Remove some blank lines in generated xorg.conf; update manpage
[grml-x.git] / grml-x
1 #!/bin/zsh
2 # Filename:      grml-x
3 # Purpose:       wrapper for startx on grml [providing new xconfiguration tool]
4 # Authors:       grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
5 # Bug-Reports:   see http://grml.org/bugs/
6 # License:       This file is licensed under the GPL v2.
7 # Latest change: Don Jul 12 01:20:47 CEST 2007 [mika]
8 ################################################################################
9
10 # debugging {{{
11 # usage: DEBUG=1 grml-x ..... 2>/tmp/grml-x-debug.log
12   if [[ $DEBUG -gt 0 ]]; then
13       setopt xtrace
14   fi
15 # }}}
16
17 # functions and color {{{
18   # use colors only if not booted with nocolor bootoption
19   if ! grep -q nocolor /proc/cmdline ; then
20      autoload colors ; colors
21      [ -r /etc/grml_colors ] && . /etc/grml_colors
22   fi
23
24   # some functions like getBootParam
25   if [ -r /etc/grml/script-functions -a -r /etc/grml/sh-lib ] ; then
26      source /etc/grml/script-functions
27      source /etc/grml/sh-lib
28   else
29     echo 'Error: sourcing function files failed. Exiting.'
30     exit 1
31   fi
32
33   check4root &>/dev/null && ROOT='1' || ROOT=''
34 # }}}
35
36 # set variables  {{{
37   PROGRAMNAME=${0##*/}
38   HWINFO='/usr/sbin/hwinfo'
39   DATE=$(date)
40   [ -n "$XINITRC" ] || XINITRC="$HOME/.xinitrc"
41
42   # temporary files
43   HWINFO_TMP="/tmp/hwinfo.$$"
44   MONITORINFO="/tmp/monitorinfo.$$"
45   MOUSEINFO="/tmp/mouse.$$"
46
47   if [ -r /etc/sysconfig/keyboard ] ; then
48     source /etc/sysconfig/keyboard
49   else
50     XKEYBOARD='us'
51   fi
52
53   XSERVER="Xorg"
54   XCONFIG='/etc/X11/xorg.conf'
55   KEYBOARD="# Driver      \"kbd\"
56 #         Option      \"XkbRules\"   \"xfree86\"
57 #         Option      \"XkbRules\"   \"xorg\"
58 #         Option      \"XkbModel\"   \"pc105\"
59 #         Option      \"XkbLayout\"  \"${XKEYBOARD},us\"
60 #         Option      \"XkbVariant\" \"nodeadkeys\""
61
62   # check for font path
63   if [ -d /usr/share/fonts/X11 ] ; then
64      XFONTS="        FontPath     \"/usr/share/fonts/X11/misc\"
65         FontPath     \"/usr/share/fonts/X11/100dpi/:unscaled\"
66         FontPath     \"/usr/share/fonts/X11/75dpi/:unscaled\"
67         FontPath     \"/usr/share/fonts/X11/Type1\"
68         FontPath     \"/usr/share/fonts/X11/100dpi\"
69         FontPath     \"/usr/share/fonts/X11/75dpi\""
70   fi
71   # /usr/X11R6/lib/X11/fonts exists nearly everywhere, assume
72   # /usr/X11R6/lib/X11/fonts as valid font path only if fonts.dir
73   # exists for "misc"
74   if [ -r /usr/X11R6/lib/X11/fonts/misc/fonts.dir ] ; then
75       XFONTS="$XFONTS
76         FontPath     \"/usr/X11R6/lib/X11/fonts/Type1\"
77         FontPath     \"/usr/X11R6/lib/X11/fonts/misc:unscaled\"
78         FontPath     \"/usr/X11R6/lib/X11/fonts/misc\"
79         FontPath     \"/usr/X11R6/lib/X11/fonts/75dpi:unscaled\"
80         FontPath     \"/usr/X11R6/lib/X11/fonts/75dpi\"
81         FontPath     \"/usr/X11R6/lib/X11/fonts/100dpi:unscaled\"
82         FontPath     \"/usr/X11R6/lib/X11/fonts/100dpi\""
83   fi
84 # }}}
85
86 # make sure we don't leave any temp files {{{
87 bailout() {
88   rm -f "$HWINFO_TMP" "$MONITORINFO" "$MOUSEINFO"
89   [ -n "$1" ] && EXIT="$1" || EXIT="1"
90   print "$bg[black]$fg[red]${bold_color}Exiting...${reset_color}">&2
91   exit "$EXIT"
92 }
93
94 trap bailout 1 2 3 15
95 # }}}
96
97 # warn if running as user root {{{
98   if [ -n "$ROOT" ] ; then
99      if [ -r /etc/grml_cd ] ; then
100         print "$bg[black]$fg[red]${bold_color}Warning: Please do not run grml-x as user root.${reset_color}"
101         print "$bg[black]$fg[red]${bold_color}Running grml-x as user root is *not* supported!${reset_color}"
102         print "$bg[black]$fg[red]${bold_color}Switch to user grml or run su - grml -c 'grml-x ...' instead.${reset_color}"
103         print ''
104      else
105         print "$bg[black]$fg[red]${bold_color}Warning: Please do not run X.org as user root!${reset_color}"
106         print "$bg[black]$fg[red]${bold_color}As soon as you have a working $XCONFIG please use startx instead of grml-x.${reset_color}"
107         print ''
108      fi
109   fi
110   fstabuser=$(grep ':x:1000:' /etc/passwd)
111   fstabuser=${fstabuser%%[:]*}
112 # }}}
113
114 # usage information {{{
115 usage()
116 {
117   if [[ $1 != '' ]] ; then echo 1>&2 "\n$1" ; fi
118   print "$bg[black]$fg[red]$bold_color"
119   print 1>&2 "
120 Usage: $PROGRAMNAME
121        $PROGRAMNAME [-options] windowmanager
122
123 Examples:
124   $PROGRAMNAME wmii
125   $PROGRAMNAME pekwm
126   $PROGRAMNAME fluxbox
127   $PROGRAMNAME -force -nostart fluxbox
128   $PROGRAMNAME -nosynaptics fluxbox
129   $PROGRAMNAME -nosync fluxbox
130   $PROGRAMNAME -noddc wmii
131   $PROGRAMNAME -module radeon -mode 1024x768 -vsync 60 wmi
132   XINITRC=~/.xinitrc $PROGRAMNAME ion
133   $PROGRAMNAME -display 8 wmii
134
135 More information on grml-x can be found in the manual page: man grml-x
136
137 Report bugs, send wishes and feedback to the grml team:
138 http://grml.org/bugs/ - contact (at) grml.org
139 "
140   print "${reset_color}"
141   exit 2
142 }
143 # }}}
144
145 # writehwinfo {{{
146 writehwinfo()
147 {
148    if [ -n "$ROOT" ] ; then
149      su - $fstabuser -c "$HWINFO > $HWINFO_TMP"
150    else
151      $HWINFO > $HWINFO_TMP
152    fi
153 }
154 # }}}
155
156 # monitor {{{
157 monitor()
158 {
159   sudo $HWINFO --monitor > $MONITORINFO
160 }
161 # }}}
162
163 # mode {{{
164 mode()
165 {
166    [ -r "$MONITORINFO" ] || monitor # get monitor settings
167    modes=$(perl -e 'while (<STDIN>) {if (/  Resolution:/) { s/.*\s+(\d+x\d+).*/$1/; print} }' < $MONITORINFO |
168 sort -nur | perl -ne 's/\s+/ /; s/(\d+x\d+)/"$1"/; print')
169
170    if [ -n "$XINERAMA" ] ; then
171
172       print "$fg[green]
173
174 Option for $fg[yellow]Xinerama$fg[green] found, please use xrandr inside X.org for your further configuration!
175 Trying to identify monitors now..."
176
177       # Currently we only know that it works with current intel driver,
178       # so inform user about that:
179       if [[ "$MODULE" != "intel" ]] ; then
180               print "$fg[red]
181
182 Warning: using a non-intel driver - trying Xinerama setup anyway.
183 If it worked please contact grml developers providing information
184 about your setup so we can adjust grml-x according!
185
186       -> http://grml.org/contact/
187
188 Sleeping for 10 seconds now... Will continue then...
189 Just press Ctrl-C to cancel operation.
190 "
191 #             sleep 10 # FIXME
192       fi
193
194       # make sure we have information from 2 monitors:
195       # - first one from 'hwinfo --monitor'      => $MONITORINFO
196       # - second one from 'hwinfo --framebuffer' => $FRAMEBUFFER
197       FRAMEBUFFER=$(hwinfo --framebuffer | grep 'Mode 0x.* bits' | head -1)
198       if [ -z "$FRAMEBUFFER" ] ; then
199          print "$fg[red]
200 Fatal: could not identify two monitors - no chance to
201        set up multihead using Xinerama - sorry. :-(
202
203 Please run grml-x without the -xinerama option and contact
204 grml developers if you have any further useful information.
205        => http://grml.org/bugs/
206 "
207          bailout 10
208       fi
209
210       # check whether we can read the $MONITORINFO file
211       if ! [ -r "$MONITORINFO" ] ; then
212          print "$fg[red]
213 Fatal: could not identify monitor - no chance to
214        set up multihead using Xinerama - sorry. :-(
215 "
216          bailout 11
217       else
218          # now calculate Virtual size for use with Xinerama
219          HORIZ_RES1="$(grep 'Max. Resolution:' $MONITORINFO | sed 's/    Max\. Resolution: \(.*\)x\(.*\)/\1/')"
220          VERIZ_RES1="$(grep 'Max. Resolution:' $MONITORINFO | sed 's/    Max\. Resolution: \(.*\)x\(.*\)/\2/')"
221
222          HORIZ_RES2="$(echo $FRAMEBUFFER | sed 's/  Mode 0x.*: \(.*\)x.*/\1/')"
223          VERIZ_RES2="$(echo $FRAMEBUFFER | sed 's/  Mode 0x.*x\(.*\) (.*/\1/')"
224
225          if [ -n "$HORIZ_RES1" -a -n "$VERIZ_RES1" -a -n "$HORIZ_RES2" ] ; then
226             if [ $(echo $VERIZ_RES1 - $VERIZ_RES2 | bc -l) -eq 0 ] ; then
227             VERIZ_RESULT="$VERIZ_RES1"
228             elif [ "$VERIZ_RES1" -gt "$VERIZ_RES2" ] ; then
229                VERIZ_RESULT="$VERIZ_RES1"
230             else
231                VERIZ_RESULT="$VERIZ_RES2"
232             fi
233
234             HORIZ_RESULT=$(echo $HORIZ_RES1 + $HORIZ_RES2 | bc -l)
235
236             # important: keep newline for appropriate placing below $MODES!
237             if [ -n "$HORIZ_RESULT" ] ; then
238                VIRTUAL="
239                 Virtual $HORIZ_RESULT $VERIZ_RES1"
240             fi
241          fi
242        fi
243    fi
244
245    if [[ -n $NODDC ]] ; then
246      MODES="Modes \"1024x768\" \"800x600\" \"640x480\"  \"1600x1200\" \"1280x1024\" \"1280x960\"$VIRTUAL"
247    elif [[ "$modes" == "\"1024x768\" " || -z $modes ]] ; then
248      MODES="# Modes \"1024x768\" \"800x600\" \"640x480\"  \"1600x1200\" \"1280x1024\" \"1280x960\"$VIRTUAL"
249    else
250      MODES="# Modes $modes$VIRTUAL"
251    fi
252 }
253 # }}}
254
255 # sync - get hsync/vsync settings {{{
256 sync()
257 {
258    [ -r "$MONITORINFO" ] || monitor # get monitor settings
259    vsyncval=$(awk '/Vert. Sync Range:/{print $4}' $MONITORINFO | sed 's/-/.0 - / ; s/$/.0/' | head -1)
260    hsyncval=$(awk '/Hor. Sync Range:/{print $4}'  $MONITORINFO | sed 's/-/.0 - / ; s/$/.0/' | head -1)
261    if [ -z $vsyncval ] ; then
262      vsyncval='50.0 - 60.0'
263    fi
264    if [ -z $hsyncval ] ; then
265      hsyncval='28.0 - 96.0'
266    fi
267 }
268 # }}}
269
270 # mouse {{{
271 mouse()
272 {
273    sudo $HWINFO --mouse > $MOUSEINFO
274
275    # SynPS/2 Synaptics TouchPad
276    if grep -q 'Device:.*Synaptics' "$MOUSEINFO" ; then
277     if [[ "$SYNAPTICS" == "yes" ]] ; then # check for '-nosynaptics'-option
278      MOUSEDRIVER='synaptics'
279      SYNMOUSE='InputDevice    "Synaptics"  "AlwaysCore"'
280      SYNMOUSEDETAIL="
281 Section \"InputDevice\"
282   Driver        \"synaptics\"
283   Identifier    \"Synaptics\"
284   Option        \"Device\"        \"/dev/psaux\"
285   Option        \"Protocol\"      \"auto-dev\"
286   Option        \"LeftEdge\"      \"1700\"
287   Option        \"RightEdge\"     \"5300\"
288   Option        \"TopEdge\"       \"1700\"
289   Option        \"BottomEdge\"    \"4200\"
290   Option        \"FingerLow\"     \"25\"
291   Option        \"FingerHigh\"    \"30\"
292   Option        \"ZAxisMapping\"   \"4 5\"
293   Option        \"MaxTapTime\"    \"180\"
294   Option        \"MaxTapMove\"    \"220\"
295   Option        \"VertScrollDelta\" \"100\"
296   Option        \"MinSpeed\"      \"0.06\"
297   Option        \"MaxSpeed\"      \"0.12\"
298   Option        \"AccelFactor\" \"0.0010\"
299 #  Option       \"SHMConfig\"     \"on\"
300 #  Option       \"Repeater\"      \"/dev/ps2mouse\"
301 EndSection
302 "
303     else
304      MOUSEDRIVER='mouse'
305      SYNMOUSEDETAIL=""
306      SYNMOUSE='# No synaptics touchpad detected.'
307     fi
308    else
309
310     # AlpsPS/2 ALPS TouchPad (with Synapticsdriver)
311     if grep -q 'Device:.*ALPS' "$MOUSEINFO" ; then
312      if [[ "$SYNAPTICS" == "yes" ]] ; then # check for '-nosynaptics'-option
313       MOUSEDRIVER='synaptics'
314       SYNMOUSE='InputDevice    "Synaptics"  "AlwaysCore"'
315       SYNMOUSEDETAIL="
316 Section \"InputDevice\"
317   Driver        \"synaptics\"
318   Identifier    \"Synaptics\"
319   Option        \"Device\"        \"/dev/psaux\"
320   Option        \"Protocol\"      \"auto-dev\"
321   Option        \"LeftEdge\"      \"120\"
322   Option        \"RightEdge\"     \"850\"
323   Option        \"TopEdge\"       \"120\"
324   Option        \"BottomEdge\"    \"650\"
325   Option        \"FingerLow\"     \"14\"
326   Option        \"FingerHigh\"    \"15\"
327   Option        \"ZAxisMapping\"   \"4 5\"
328   Option        \"MaxTapTime\"    \"180\"
329   Option        \"MaxTapMove\"    \"50\"
330   Option        \"MaxDoubleTapTime\"    \"100\"
331   Option        \"VertScrollDelta\" \"20\"
332   Option        \"HorizScrollDelta\" \"20\"
333   Option        \"MinSpeed\"      \"0.3\"
334   Option        \"MaxSpeed\"      \"2.00\"
335   Option        \"AccelFactor\" \"0.030\"
336   Option        \"UpDownScrolling\" \"1\"
337   Option        \"EmulateMiddleButtonTime\" \"75\"
338   Option        \"CircularScrolling\" \"1\"
339   Option        \"CircScrollDelta\" \"0.1\"
340   Option        \"CircScrollTrigger\" \"8\"
341 #  Option       \"SHMConfig\"     \"on\"
342 #  Option       \"Repeater\"      \"/dev/ps2mouse\"
343 EndSection
344 "
345      else
346       MOUSEDRIVER='mouse'
347       SYNMOUSEDETAIL=""
348       SYNMOUSE='# No alps touchpad detected.'
349      fi
350     else
351       SYNMOUSE='# No synaptics/alps touchpad present.'
352     fi
353    fi
354
355    # USB-PS/2 Optical Mouse
356    if [ -n "$USE_USB" ] ; then
357      USBMOUSE='InputDevice    "USB Mouse"     "CorePointer"'
358      USBMOUSEDETAIL="
359 Section \"InputDevice\"
360         Identifier      \"USB Mouse\"
361         Driver          \"mouse\"
362         Option          \"Device\"                \"/dev/input/mice\"
363         Option          \"Protocol\"              \"auto\"
364         Option          \"ZAxisMapping\"          \"4 5\"
365         Option          \"Buttons\"               \"5\"
366         Option          \"SendCoreEvents\"        \"true\"
367 EndSection
368 "
369    else
370      USBMOUSE='# InputDevice    "USB Mouse"     "CorePointer"'
371      USBMOUSEDETAIL=''
372    fi
373
374    if grep -q 'Device:.*Serial' "$MOUSEINFO" ; then
375      SERIAL='yes'
376      SERMOUSE='InputDevice    "Serial Mouse"     "CorePointer"'
377      SERMOUSEDETAIL="
378 Section \"InputDevice\"
379         Identifier  \"Serial Mouse\"
380         Driver      \"mouse\"
381         Option      \"Device\" \"/dev/ttyS0\"
382         Option      \"Protocol\" \"Microsoft\"
383         Option      \"Emulate3Buttons\" \"true\"
384         Option      \"Emulate3Timeout\" \"70\"
385         Option      \"SendCoreEvents\"  \"true\"
386 EndSection
387 "
388    else
389      SERMOUSE='# No serial mouse detected.'
390      SERMOUSEDETAIL=''
391    fi
392
393    # ImExPS/2 Logitech Explorer Mouse
394    # "PS2++ Logitech MX Mouse"
395    if [ -n "$USE_PS2" ] ; then
396       PS2='yes'
397       PS2MOUSE='InputDevice    "PS/2 Mouse"    "CorePointer"'
398       PS2MOUSEDETAIL="
399 Section \"InputDevice\"
400         Identifier  \"PS/2 Mouse\"
401         Driver      \"mouse\"
402         Option      \"Device\" \"/dev/input/mice\"
403         # Option      \"Device\" \"/dev/psaux\"
404         Option      \"Protocol\" \"PS/2\"
405         Option      \"Emulate3Buttons\" \"true\"
406         Option      \"Emulate3Timeout\" \"70\"
407         Option      \"SendCoreEvents\"  \"true\"
408 EndSection
409 "
410      else
411       PS2MOUSE='# InputDevice    "PS/2 Mouse"    "CorePointer"'
412       PS2MOUSEDETAIL=''
413      fi
414
415      EVDEV_MOUSE="
416 # Section \"InputDevice\"
417 #         Identifier      \"Generic Mouse\"
418 #         Driver          \"evdev\"
419 #         Option          \"Device\"                \"/dev/input/mice\"
420 #         Option          \"Protocol\"              \"auto\"
421 #         Option          \"ZAxisMapping\"          \"4 5\"
422 #         Option          \"Buttons\"               \"5\"
423 #         Option          \"SendCoreEvents\"        \"true\"
424 # EndSection
425 "
426
427    MOUSE="        $USBMOUSE
428         $PS2MOUSE
429         $SYNMOUSE
430         $SERMOUSE"
431 }
432 # }}}
433
434 # commandline parsing {{{
435 parse_options()
436 {
437    zparseopts -K -- module:=o_module help=o_help noddc=o_noddc nosync=o_nosync \
438                     vsync:=o_vsync hsync:=o_hsync mode:=o_mode force=o_force display:=o_display   \
439                     nostart=o_nostart nodpms=o_nodpms nosynaptics=o_nosynaptics nousb=o_nousb \
440                     nops2=o_nops2 genmouse=o_genmouse novref=o_novref nohsync=o_nohsync \
441                     fallback=o_fallback usb=o_usb ps2=o_ps2 composite=o_composite \
442                     xinerama=o_xinerama
443
444    if [[ $# == 0 || "$o_help" != "" || "$1" == '-h' || "$1" == '--help' ]]; then
445       usage
446    fi
447
448    if [[ "$o_force" != "" ]]; then
449       FORCE='yes'
450    fi
451
452    if [[ "$o_fallback" != "" ]]; then
453       FALLBACK="yes"
454       if [ -r /etc/X11/xorg.conf.example ] ; then
455          sudo cp /etc/X11/xorg.conf.example $XCONFIG
456          print "$bold_color$fg[blue]Copying /etc/X11/xorg.conf.example to $XCONFIG as requested via fallback option."
457       else
458          echo 'Error: /etc/X11/xorg.conf.example not readable, exiting.'
459          exit 1
460       fi
461    fi
462
463    if [[ "$o_nodpms" != "" ]]; then
464       DPMS='Option       "DPMS"      "false"'
465    else
466       DPMS='Option       "DPMS"      "true"'
467    fi
468
469    if [[ "$o_noddc" != "" ]]; then
470       NODDC="yes"
471    fi
472
473    if [[ "$o_vsync" != "" ]]; then
474       FORCE="yes"
475    fi
476
477    if [[ "$o_hsync" != "" ]]; then
478       FORCE="yes"
479    fi
480
481    if [[ "$o_nousb" != "" ]]; then
482       echo 'Warning: option -nousb is deprecated.'>&2
483    fi
484
485    if [[ "$o_usb" != "" ]]; then
486       USE_USB='yes'
487    fi
488
489    if [[ "$o_nops2" != "" ]]; then
490       echo 'Warning: optino -nops2 is deprecatedË™'>&2
491    fi
492
493    if [[ "$o_ps2" != "" ]]; then
494       USE_PS2='yes'
495    fi
496
497    if [[ "$o_genmouse" != "" ]]; then
498       GENERICMOUSE='yes'
499    fi
500
501    if [[ "$o_nosynaptics" != "" ]]; then
502       SYNAPTICS='no'
503    else
504       SYNAPTICS='yes'
505    fi
506
507    if [[ "$o_nostart" != "" ]]; then
508       NOSTART="yes"
509    fi
510
511    DISPLAY=$o_display[2]
512
513    eval WINDOWMANAGER=\${$#}
514
515    if [[ "$XKEYBOARD" == de ]] ; then
516       KEYBOARD="$KEYBOARD
517 #         Option      \"XkbVariant\" \"nodeadkeys\""
518    fi
519
520    if [ -n "$FORCE" -o ! -r "$XCONFIG" -a -z "$FALLBACK" ] ; then
521      print -n "$bold_color$fg[blue]Gathering hardware information...$fg[red]"
522
523      sync # get hsync/vsync
524
525      if [ -z "$o_hsync" ] ; then
526        o_hsync=(-hsync "$hsyncval")
527        HSYNC=$o_hsync[2]
528        HORIZSYNC="        HorizSync    $HSYNC"
529      else
530        o_hsync=(-hsync "$o_hsync[2]")
531        HSYNC=$o_hsync[2]
532        HORIZSYNC="        HorizSync    $HSYNC"
533      fi
534
535      if [ -z "$o_vsync" ] ; then
536        o_vsync=(-vsync "$vsyncval")
537        VSYNC=$o_vsync[2]
538        VERTISYNC="        VertRefresh  $VSYNC"
539      else
540        o_vsync=(-vsync "$o_vsync[2]")
541        VSYNC=$o_vsync[2]
542        VERTISYNC="        VertRefresh  $VSYNC"
543      fi
544
545      if [[ "$o_nosync" != "" ]]; then
546         HORIZSYNC="#       HorizSync   28.0 - 96.0  # deactivated via -nosync option of grml-x"
547         VERTISYNC="#       VertRefresh 50.0 - 60.0  # deactivated via -nosync option of grml-x"
548      fi
549
550      if [[ "$o_nohsync" != "" ]]; then
551         HORIZSYNC="#       HorizSync   28.0 - 96.0  # deactivated via -nohsync option of grml-x"
552      fi
553
554      if [[ "$o_novref" != "" ]]; then
555         VERTISYNC="#       VertRefresh 50.0 - 60.0  # deactivated via -novref option of grml-x"
556      fi
557
558      if [[ "$o_xinerama" != "" ]]; then
559         XINERAMA=1
560      fi
561
562      if [[ "$o_composite" != "" ]]; then
563         COMPOSITE="Section \"Extensions\"
564     Option \"Composite\" \"Enable\"
565 EndSection"
566      else
567         COMPOSITE="#Section \"Extensions\"
568 #    Option \"Composite\" \"Enable\"
569 #EndSection"
570      fi
571
572      # write hwinfo stuff
573      writehwinfo
574
575      # monitor stuff
576      MONITOR=$(awk '/monitor.1:/{print $3}' $HWINFO_TMP)
577      [[ $MONITOR != 'ddc' ]] && NODDC=yes
578
579      # module handling
580      MODULE=$o_module[2]
581      if [ -z "$MODULE" ] ; then
582        MODULE="$(getBootParam xmodule 2>/dev/null)"
583        if [ -z "$MODULE" ] ; then
584          MODULE=$(grep 'XFree86 v4 Server Module:' "${HWINFO_TMP}" | head -1 | awk '{print $5}')
585          if [ -z "$MODULE" ] ; then
586            MODULE='vesa'
587          fi
588          # hwinfo >=13.28 reports driver 'intel' instead of i810
589          if [[ "$MODULE" == 'intel' ]] ; then
590             [ -r /usr/lib/xorg/modules/drivers/intel_drv.so ] || MODULE='i810'
591          fi
592        fi
593      else
594        FORCE="yes"
595      fi
596
597      mouse    # get mouse settings
598      VGA=$(lspci | grep VGA | sed 's/.*compatible controller: //' | head -1)
599
600      MODE=$o_mode[2]
601      if [ -z $MODE ] ; then
602        B_MODE="$(getBootParam xmode 2>/dev/null)"
603        if [ -n "$B_MODE" ] ; then
604          MODES="Modes \"$B_MODE\""
605          FORCE="yes"
606        fi
607        if [ -z "$MODES" ] ; then
608           mode # get available modes
609        fi
610      else
611        MODES="Modes \"$MODE\""
612        FORCE="yes"
613      fi
614
615      print "$fg[green]done$reset_color"
616      print "$bg[black]$fg[white]$bold_color"
617      print "$fg[green]Specified windowmanager is $fg[yellow]$WINDOWMANAGER"
618      print "$fg[green]Video is $fg[yellow]$VGA$fg[green] using $bg[black]$fg[yellow]${XSERVER}$fg[cyan](${MODULE})$fg[green] Server"
619      [[ -z $HSYNC ]] && [[ -z $VSYNC ]] && print "$fg[green]Monitor is $fg[yellow]$MONITOR"
620      [[ -z $HSYNC ]] && [[ -n $VSYNC ]] && print "$fg[green]Monitor is $fg[yellow]$MONITOR$fg[green], VSYNC: $fg[yellow]$VSYNC"
621      [[ -z $VSYNC ]] && [[ -n $HSYNC ]] && print "$fg[green]Monitor is $fg[yellow]$MONITOR$fg[green], HSYNC: $fg[yellow]$HSYNC"
622      [[ -n $VSYNC ]] && [[ -n $HSYNC ]] && print "$fg[green]Monitor is $fg[yellow]$MONITOR$fg[green], HSYNC: $fg[yellow]$HSYNC $fg[green]VSYNC: $fg[yellow]$VSYNC"
623      [[ -n $modes ]] && print "$fg[green]Using default X.org modes."
624      [[ -z $modes ]] && print "$fg[green]Using Mode: $fg[yellow]$MODE"
625      print "${reset_color}"
626    fi
627 }
628 parse_options $*
629 # }}}
630
631 # check for requirements {{{
632 requirements()
633 {
634 if ! [ -x $(which hwinfo) ] ; then
635   print "$bg[black]$fg[red]${bold_color}Error: hwinfo not found in path.${reset_color}
636 Note:  run 'apt-get install hwinfo' on systems running debian.
637 Exiting.${reset_color}"
638   exit -1
639 fi
640
641 if ! [[ -d /sys ]] ; then
642   print "$bg[black]$fg[red]${bold_color}Error: mounted /sys required (for hwinfo).${reset_color}
643 You may want to add the following line to your /etc/fstab:
644
645   sysfs /sys sysfs defaults 0 0
646
647 or just run 'mount /sys'. Exiting.${reset_color}"
648   exit -1
649 fi
650 }
651 requirements
652 # }}}
653
654 # xconfig {{{
655 xconfig() {
656 cat << EOX
657 ################################################################################
658 # Filename:      $XCONFIG
659 # Purpose:       config file for xserver - generated by grml-x
660 # Bug-Reports:   see http://grml.org/bugs/
661 # Latest change: ${DATE}
662 # See also:
663 #   /usr/share/doc/xserver-xorg/   and
664 #   http://wiki.x.org/wiki/Home    and
665 #   http://ftp.x.org/pub/X11R7.0/doc/html/index.html for information on Xorg
666 # Refer to the xorg.conf man page and to
667 # http://ftp.x.org/pub/X11R7.0/doc/html/xorg.conf.5.html
668 # for details about the format of this file.
669 #
670 # If you would like this file to be automatically reconfigured by debian,
671 # run the following command:
672 #   sudo dpkg-reconfigure -phigh xserver-xorg
673 ################################################################################
674
675 Section "ServerLayout"
676         Identifier     "XServer Configured"
677         Screen      0  "Screen0" 0 0
678         # InputDevice    "Keyboard0"     "CoreKeyboard"
679         # InputDevice    "Generic Mouse" "CorePointer"
680 $MOUSE
681 EndSection
682
683 Section "ServerFlags"
684         Option "AllowMouseOpenFail"  "true"  # allows the server to start up even if the mouse does not work
685         Option "DontVTSwitch"        "false" # allow switching between virtual terminal
686         # Option "DontZap"             "true"  # disable <Crtl><Alt><BS> (server abort)
687         # Option "DontZoom"            "true"  # disable <Crtl><Alt><KP_+>/<KP_-> (resolution switching)
688 EndSection
689
690 Section "Files"
691         # More information:  http://ftp.x.org/pub/X11R7.0/doc/html/fonts.html
692 $XFONTS
693         # FontPath     "/usr/share/fonts/ttf/western"
694         # FontPath     "/usr/share/fonts/ttf/decoratives"
695         FontPath     "/usr/share/fonts/truetype/ttf-bitstream-vera"
696         FontPath     "/usr/share/fonts/latex-ttf-fonts"
697         FontPath     "/var/lib/defoma/x-ttcidfont-conf.d/dirs/TrueType"
698 EndSection
699
700 # Modules - see /usr/X11R6/lib/modules/fonts and /usr/X11R6/lib/modules/extensions
701 Section "Module"
702         Load  "dbe"       # double buffer extension
703         Load  "dri"       # direct rendering
704         Load  "glx"       # 3D layer / GLX extension
705         Load  "type1"     # type1 font module
706         Load  "freetype"  # freetype fonts rendering
707         Load  "extmod"    # some commonly used server extensions (e.g. shape extension)
708         Load  "record"    # recording extension
709         Load  "evdev"     # generic input handling driver on Linux
710         # Load  "vbe"       # Vesa BIOS Extension
711         # Load  "i2c"       # I2C bus
712         # Load  "int10"     # initialize graphics cards via int10 call to the BIOS
713         # Load  "v4l"       # Video for Linux
714         ## Deprecated/unneeded modules with Xorg >=7.0:
715         # Load  "speedo"    # font module (does not exist anymore)
716         # Load  "ddc"       # ddc probing of monitor (automatically loaded)
717         # Load  "GLcore"    # render OpenGL in software (automatically loaded)
718         # Load  "bitmap"    # bitmap fonts (automatically loaded)
719 # Valid entries - see /usr/lib/xorg/modules/[extensions/]
720 # afb bitmap cfb cfb16 cfb24 cfb32 cw damage dbe ddc dri drm extmod fb
721 # fbdevhw freetype GLcore glx i2c int10 int10 layer mfb pcidata rac ramdac
722 # record scanpci shadow shadowfb type1 vbe vgahw xaa xf1bpp xf24_32bpp xf4bpp
723 # xf8_16bpp xf8_32bpp xtrap
724 EndSection
725
726 # If you'd like to switch the positions of your capslock and control keys, use:
727 # Option "XkbOptions" "ctrl:swapcaps"
728 # Or if you just want both to be control, use:
729 # Option "XkbOptions" "ctrl:nocaps"
730 # More information: http://ftp.x.org/pub/X11R7.0/doc/html/XKB-Config.html
731 # Section "InputDevice"
732 #         Identifier  "Keyboard0"
733 #         Option      "CoreKeyboard"
734 #         $KEYBOARD
735 #         # Option      "XkbOptions" "ctrl:swapcaps,grp:alt_shift_toggle,grp_led:scroll,compose:menu"
736 # EndSection
737
738 # More information: http://ftp.x.org/pub/X11R7.0/doc/html/mouse.html
739 ${USBMOUSEDETAIL}${PS2MOUSEDETAIL}${SERMOUSEDETAIL}${SYNMOUSEDETAIL}${EVDEV_MOUSE}
740
741 Section "Monitor"
742         Identifier   "Monitor0"
743 #       ModelName    "Old Monitor (no DDC)"
744         $DPMS
745 #       HorizSync    28.0 - 78.0 # Warning: This may fry very old Monitors
746 #       HorizSync    28.0 - 96.0 # Warning: This may fry old Monitors
747 $HORIZSYNC
748 #       VertRefresh  50.0 - 76.0 # Very conservative. May flicker.
749 #       VertRefresh  50.0 - 60.0 # Extreme conservative. Will flicker. TFT default.
750 $VERTISYNC
751 # Need more information?
752 #  http://xtiming.sourceforge.net/cgi-bin/xtiming.pl
753 #  http://en.tldp.org/HOWTO/XFree86-Video-Timings-HOWTO/
754 EndSection
755
756 Section "Device"
757         ### Available Driver options are:
758         ## sw_cursor is needed for some ati and radeon cards
759         # Option     "sw_cursor"
760         # Option     "hw_cursor"
761         # Option     "NoAccel"
762         # Option     "ShowCache"
763         # Option     "ShadowFB"
764         # Option     "UseFBDev"
765         # Option     "Rotate"
766         ## xorg + nvidia:
767         # Option "RenderAccel" "true"
768         # Option "AllowGLXWithComposite" "true"
769         Identifier  "Card0"
770         # The following line is auto-generated by grml-x
771         Driver      "$MODULE"
772         VendorName  "All"
773         BoardName   "All"
774         ## Workaround for drivers (for example radeon) which might send output to wrong device:
775         # Option "MonitorLayout" "LVDS, AUTO"
776         # Option "MonitorLayout" "LVDS, CRT"
777         # Option "MonitorLayout" "NONE, STV"
778         # Option "MonitorLayout" "LVDS"
779         ## Specify BusID:
780         # BusID       "PCI:1:0:0"
781 EndSection
782
783 Section "Screen"
784         Identifier "Screen0"
785         Device     "Card0"
786         Monitor    "Monitor0"
787         DefaultColorDepth 16
788         SubSection "Display"
789                 Depth     1
790                 $MODES
791         EndSubSection
792         SubSection "Display"
793                 Depth     4
794                 $MODES
795         EndSubSection
796         SubSection "Display"
797                 Depth     8
798                 $MODES
799         EndSubSection
800         SubSection "Display"
801                 Depth     15
802                 $MODES
803         EndSubSection
804         SubSection "Display"
805                 Depth     16
806                 $MODES
807         EndSubSection
808         SubSection "Display"
809                 Depth     24
810                 $MODES
811         EndSubSection
812         SubSection "Display"
813                 Depth     32
814                 $MODES
815         EndSubSection
816 EndSection
817
818 # Make sure you have the relevant Debian packages on your system
819 # to be able to use DRI (libgl1-mesa-dri for example)
820 Section "DRI"
821         Mode 0666
822 EndSection
823
824 $COMPOSITE
825
826 ## END OF FILE #################################################################
827 EOX
828 }
829 # }}}
830
831 # writeit {{{
832 writeit() {
833     XCONFTMP="/tmp/xconfig.$$"
834     xconfig > $XCONFTMP
835     # we do not want to have two CorePointers, deactivate one therefore
836     if grep -Eq '^[[:space:]]+InputDevice[ ]+"USB Mouse"[ ]+"CorePointer"' $XCONFTMP ; then
837        if grep -Eq '^[[:space:]]+InputDevice[ ]+"PS/2 Mouse"[ ]+"CorePointer"' $XCONFTMP ; then
838           sed -i 's|InputDevice.*PS/2.*CorePointer|# & # deactivated to avoid two CorePointers|' $XCONFTMP
839        fi
840     fi
841     [ -f $XCONFIG ] && sudo mv -f $XCONFIG $XCONFIG.old
842     sudo mv $XCONFTMP $XCONFIG
843     sudo chown root.root $XCONFIG
844     sudo chmod 644 $XCONFIG
845 }
846 # }}}
847
848 # writeconfig {{{
849 function writeconfig
850 {
851   if [[ ! -f $XCONFIG ]] ; then
852     print -n "$bold_color$fg[blue]Creating $XCONFIG: $fg[red]"
853     writeit && print "$fg[green]done$reset_color"
854   else
855     if [ -z "$FORCE" -a -z "$FALLBACK" ] ; then
856        print "$bold_color$fg[blue]Notice: $XCONFIG exists already.
857 Use the force-option (-force) to force creation.
858 $fg[red]"
859     fi
860   fi
861   if [[ -n "$FORCE" ]] ; then
862     print "$bold_color$fg[blue]Force-switch or manual option(s) detected:"
863     print -n "\-> Moving eventual existing $XCONFIG to ${XCONFIG}.old: $fg[red]"
864     writeit && print "$fg[green]done$reset_color"
865   fi
866 }
867 # }}}
868
869 # runit {{{
870 function runit
871 {
872   writeconfig
873   if [ -z "$NOSTART" ] ; then
874     print "$reset_color"
875     if [ -x /etc/init.d/xorg-common ] ; then
876       sudo /etc/init.d/xorg-common start
877     else
878       if [ -x /etc/init.d/xfree86-common ] ; then
879         sudo /etc/init.d/xfree86-common start
880       fi
881     fi
882     print ""
883     if [ -z "$DISPLAY" ] ; then
884       print "$bold_color$fg[green]Now trying to run startx.$reset_color"
885       startx $XINITRC -- $XOPTS
886     else
887       print "$bold_color$fg[green]Now trying to run startx on display $DISPLAY.$reset_color"
888       startx $XINITRC -- :$DISPLAY $XOPTS
889     fi
890   else
891     print "$bold_color$fg[blue]Not running startx as requested via option.$reset_color"
892   fi
893   return 1
894 }
895 # }}}
896
897 # failed {{{
898 function failed
899 {
900   print "$fg[red]"
901   if [ -z "$ROOT" ] ; then
902     if [[ $(tty) == /dev/pts/* ]] ; then
903       print "It seems you are running $PROGRAMNAME from inside GNU screen.
904 Notice that this might fail if running as user grml!
905 Please exit screen and try to run $PROGRAMNAME again."
906     fi
907   fi
908   print "Run the following commands for getting information on your hardware:
909   hwinfo --gfxcard
910   discover -v --data-path=xfree86/server/device/driver display
911   xdebconfigurator -c -d -i -x
912   get-edid | parse-edid
913
914 Do you want to go the debian way of life? Run:
915   apt-get install x-window-system-core read-edid mdetect hwinfo xdebconfigurator
916   dpkg-reconfigure x-window-system-core (or xserver-xorg depending on your system)
917
918 Problems with the module used for X? Try to load another one or
919 fall back to module vesa:
920   $PROGRAMNAME -module radeon ...
921   $PROGRAMNAME -module vesa  ...
922
923 Do you want to deactivate a present synaptics touchpad? Run:
924   $PROGRAMNAME -nosynaptics ...
925
926 Your monitor is very old and/or does not support DDC-probing?
927   $PROGRAMNAME -noddc ...
928
929 Do you want to create a x configuration file but do not start X?
930   $PROGRAMNAME -nostart ...
931
932 Monitor frequency too high or too low? Just specify hsync/vsync manually:
933   $PROGRAMNAME -hsync 30-65 ...
934   $PROGRAMNAME -hsync 30-65 -vsync 50-60 ...
935
936 Want to adjust the resolution? Use the mode-switch:
937   $PROGRAMNAME -mode 1024x768 ...
938   $PROGRAMNAME -mode '1280x1024 1024x768' ...
939
940 Problems? Use vesa with resolution 1024x768:
941   $PROGRAMNAME -module vesa -mode 1024x768 ...
942
943 Still problems with X? Use the fallback option:
944   $PROGRAMNAME -fallback ...
945
946 To adjust resolution while running X execute:
947   xrandr -s '1024x768'
948
949 More information on grml-x can be found in the manual page: man grml-x
950
951 Report bugs, send wishes and feedback to the grml team:
952 http://grml.org/bugs/ - contact (at) grml.org
953 "
954 print -n "$reset_color"
955 }
956 # }}}
957
958 # cleanup {{{
959 cleanup()
960 {
961   rm -f $HWINFO_TMP
962   rm -f $MONITORINFO
963   rm -f $MOUSEINFO
964   rm -f $XCONFTMP
965 }
966 cleanup
967 # }}}
968
969 # xinitrc {{{
970   if ! [ -x "$(which $WINDOWMANAGER)" ] ; then
971      print "$bg[black]$fg[red]${bold_color}Fatal: windowmanager $fg[blue]$WINDOWMANAGER$fg[red] not executable, startx won' work.${reset_color}">&2
972      bailout
973   fi
974   if [ -w "$XINITRC" ] ; then
975     sed -i "s|^[^#]*exec.*|  exec $WINDOWMANAGER|g" $XINITRC
976     runit || failed
977   else
978     echo -e "#!/bin/sh\n  exec $WINDOWMANAGER" >> $XINITRC
979     runit || failed
980   fi
981 # }}}
982
983 ## END OF FILE #################################################################
984 # vim:foldmethod=marker expandtab ai ft=zsh