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