Initial support for Xinemera; Support activating composite extension
[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="Section \"InputDevice\"
378         Identifier  \"Serial Mouse\"
379         Driver      \"mouse\"
380         Option      \"Device\" \"/dev/ttyS0\"
381         Option      \"Protocol\" \"Microsoft\"
382         Option      \"Emulate3Buttons\" \"true\"
383         Option      \"Emulate3Timeout\" \"70\"
384         Option      \"SendCoreEvents\"  \"true\"
385 EndSection
386 "
387    else
388      SERMOUSE='# No serial mouse detected.'
389      SERMOUSEDETAIL=''
390    fi
391
392    # ImExPS/2 Logitech Explorer Mouse
393    # "PS2++ Logitech MX Mouse"
394    if [ -n "$USE_PS2" ] ; then
395       PS2='yes'
396       PS2MOUSE='InputDevice    "PS/2 Mouse"    "CorePointer"'
397       PS2MOUSEDETAIL="Section \"InputDevice\"
398         Identifier  \"PS/2 Mouse\"
399         Driver      \"mouse\"
400         Option      \"Device\" \"/dev/input/mice\"
401         # Option      \"Device\" \"/dev/psaux\"
402         Option      \"Protocol\" \"PS/2\"
403         Option      \"Emulate3Buttons\" \"true\"
404         Option      \"Emulate3Timeout\" \"70\"
405         Option      \"SendCoreEvents\"  \"true\"
406 EndSection
407 "
408      else
409       PS2MOUSE='# InputDevice    "PS/2 Mouse"    "CorePointer"'
410       PS2MOUSEDETAIL=''
411      fi
412
413      EVDEV_MOUSE="# Section \"InputDevice\"
414 #         Identifier      \"Generic Mouse\"
415 #         Driver          \"evdev\"
416 #         Option          \"Device\"                \"/dev/input/mice\"
417 #         Option          \"Protocol\"              \"auto\"
418 #         Option          \"ZAxisMapping\"          \"4 5\"
419 #         Option          \"Buttons\"               \"5\"
420 #         Option          \"SendCoreEvents\"        \"true\"
421 # EndSection
422 "
423
424    MOUSE="        $USBMOUSE
425         $PS2MOUSE
426         $SYNMOUSE
427         $SERMOUSE"
428 }
429 # }}}
430
431 # commandline parsing {{{
432 parse_options()
433 {
434    zparseopts -K -- module:=o_module help=o_help noddc=o_noddc nosync=o_nosync \
435                     vsync:=o_vsync hsync:=o_hsync mode:=o_mode force=o_force display:=o_display   \
436                     nostart=o_nostart nodpms=o_nodpms nosynaptics=o_nosynaptics nousb=o_nousb \
437                     nops2=o_nops2 genmouse=o_genmouse novref=o_novref nohsync=o_nohsync \
438                     fallback=o_fallback usb=o_usb ps2=o_ps2 composite=o_composite \
439                     xinerama=o_xinerama
440
441    if [[ $# == 0 || "$o_help" != "" || "$1" == '-h' || "$1" == '--help' ]]; then
442       usage
443    fi
444
445    if [[ "$o_force" != "" ]]; then
446       FORCE='yes'
447    fi
448
449    if [[ "$o_fallback" != "" ]]; then
450       FALLBACK="yes"
451       if [ -r /etc/X11/xorg.conf.example ] ; then
452          sudo cp /etc/X11/xorg.conf.example $XCONFIG
453          print "$bold_color$fg[blue]Copying /etc/X11/xorg.conf.example to $XCONFIG as requested via fallback option."
454       else
455          echo 'Error: /etc/X11/xorg.conf.example not readable, exiting.'
456          exit 1
457       fi
458    fi
459
460    if [[ "$o_nodpms" != "" ]]; then
461       DPMS='Option       "DPMS"      "false"'
462    else
463       DPMS='Option       "DPMS"      "true"'
464    fi
465
466    if [[ "$o_noddc" != "" ]]; then
467       NODDC="yes"
468    fi
469
470    if [[ "$o_vsync" != "" ]]; then
471       FORCE="yes"
472    fi
473
474    if [[ "$o_hsync" != "" ]]; then
475       FORCE="yes"
476    fi
477
478    if [[ "$o_nousb" != "" ]]; then
479       echo 'Warning: option -nousb is deprecated.'>&2
480    fi
481
482    if [[ "$o_usb" != "" ]]; then
483       USE_USB='yes'
484    fi
485
486    if [[ "$o_nops2" != "" ]]; then
487       echo 'Warning: optino -nops2 is deprecatedË™'>&2
488    fi
489
490    if [[ "$o_ps2" != "" ]]; then
491       USE_PS2='yes'
492    fi
493
494    if [[ "$o_genmouse" != "" ]]; then
495       GENERICMOUSE='yes'
496    fi
497
498    if [[ "$o_nosynaptics" != "" ]]; then
499       SYNAPTICS='no'
500    else
501       SYNAPTICS='yes'
502    fi
503
504    if [[ "$o_nostart" != "" ]]; then
505       NOSTART="yes"
506    fi
507
508    DISPLAY=$o_display[2]
509
510    eval WINDOWMANAGER=\${$#}
511
512    if [[ "$XKEYBOARD" == de ]] ; then
513       KEYBOARD="$KEYBOARD
514 #         Option      \"XkbVariant\" \"nodeadkeys\""
515    fi
516
517    if [ -n "$FORCE" -o ! -r "$XCONFIG" -a -z "$FALLBACK" ] ; then
518      print -n "$bold_color$fg[blue]Gathering hardware information...$fg[red]"
519
520      sync # get hsync/vsync
521
522      if [ -z "$o_hsync" ] ; then
523        o_hsync=(-hsync "$hsyncval")
524        HSYNC=$o_hsync[2]
525        HORIZSYNC="        HorizSync    $HSYNC"
526      else
527        o_hsync=(-hsync "$o_hsync[2]")
528        HSYNC=$o_hsync[2]
529        HORIZSYNC="        HorizSync    $HSYNC"
530      fi
531
532      if [ -z "$o_vsync" ] ; then
533        o_vsync=(-vsync "$vsyncval")
534        VSYNC=$o_vsync[2]
535        VERTISYNC="        VertRefresh  $VSYNC"
536      else
537        o_vsync=(-vsync "$o_vsync[2]")
538        VSYNC=$o_vsync[2]
539        VERTISYNC="        VertRefresh  $VSYNC"
540      fi
541
542      if [[ "$o_nosync" != "" ]]; then
543         HORIZSYNC="#       HorizSync   28.0 - 96.0  # deactivated via -nosync option of grml-x"
544         VERTISYNC="#       VertRefresh 50.0 - 60.0  # deactivated via -nosync option of grml-x"
545      fi
546
547      if [[ "$o_nohsync" != "" ]]; then
548         HORIZSYNC="#       HorizSync   28.0 - 96.0  # deactivated via -nohsync option of grml-x"
549      fi
550
551      if [[ "$o_novref" != "" ]]; then
552         VERTISYNC="#       VertRefresh 50.0 - 60.0  # deactivated via -novref option of grml-x"
553      fi
554
555      if [[ "$o_xinerama" != "" ]]; then
556         XINERAMA=1
557      fi
558
559      if [[ "$o_composite" != "" ]]; then
560         COMPOSITE="Section \"Extensions\"
561     Option \"Composite\" \"Enable\"
562 EndSection"
563      else
564         COMPOSITE="#Section \"Extensions\"
565 #    Option \"Composite\" \"Enable\"
566 #EndSection"
567      fi
568
569      # write hwinfo stuff
570      writehwinfo
571
572      # monitor stuff
573      MONITOR=$(awk '/monitor.1:/{print $3}' $HWINFO_TMP)
574      [[ $MONITOR != 'ddc' ]] && NODDC=yes
575
576      # module handling
577      MODULE=$o_module[2]
578      if [ -z "$MODULE" ] ; then
579        MODULE="$(getBootParam xmodule 2>/dev/null)"
580        if [ -z "$MODULE" ] ; then
581          MODULE=$(grep 'XFree86 v4 Server Module:' "${HWINFO_TMP}" | head -1 | awk '{print $5}')
582          if [ -z "$MODULE" ] ; then
583            MODULE='vesa'
584          fi
585          # hwinfo >=13.28 reports driver 'intel' instead of i810
586          if [[ "$MODULE" == 'intel' ]] ; then
587             [ -r /usr/lib/xorg/modules/drivers/intel_drv.so ] || MODULE='i810'
588          fi
589        fi
590      else
591        FORCE="yes"
592      fi
593
594      mouse    # get mouse settings
595      VGA=$(lspci | grep VGA | sed 's/.*compatible controller: //' | head -1)
596
597      MODE=$o_mode[2]
598      if [ -z $MODE ] ; then
599        B_MODE="$(getBootParam xmode 2>/dev/null)"
600        if [ -n "$B_MODE" ] ; then
601          MODES="Modes \"$B_MODE\""
602          FORCE="yes"
603        fi
604        if [ -z "$MODES" ] ; then
605           mode # get available modes
606        fi
607      else
608        MODES="Modes \"$MODE\""
609        FORCE="yes"
610      fi
611
612      print "$fg[green]done$reset_color"
613      print "$bg[black]$fg[white]$bold_color"
614      print "$fg[green]Specified windowmanager is $fg[yellow]$WINDOWMANAGER"
615      print "$fg[green]Video is $fg[yellow]$VGA$fg[green] using $bg[black]$fg[yellow]${XSERVER}$fg[cyan](${MODULE})$fg[green] Server"
616      [[ -z $HSYNC ]] && [[ -z $VSYNC ]] && print "$fg[green]Monitor is $fg[yellow]$MONITOR"
617      [[ -z $HSYNC ]] && [[ -n $VSYNC ]] && print "$fg[green]Monitor is $fg[yellow]$MONITOR$fg[green], VSYNC: $fg[yellow]$VSYNC"
618      [[ -z $VSYNC ]] && [[ -n $HSYNC ]] && print "$fg[green]Monitor is $fg[yellow]$MONITOR$fg[green], HSYNC: $fg[yellow]$HSYNC"
619      [[ -n $VSYNC ]] && [[ -n $HSYNC ]] && print "$fg[green]Monitor is $fg[yellow]$MONITOR$fg[green], HSYNC: $fg[yellow]$HSYNC $fg[green]VSYNC: $fg[yellow]$VSYNC"
620      [[ -n $modes ]] && print "$fg[green]Using default X.org modes."
621      [[ -z $modes ]] && print "$fg[green]Using Mode: $fg[yellow]$MODE"
622      print "${reset_color}"
623    fi
624 }
625 parse_options $*
626 # }}}
627
628 # check for requirements {{{
629 requirements()
630 {
631 if ! [ -x $(which hwinfo) ] ; then
632   print "$bg[black]$fg[red]${bold_color}Error: hwinfo not found in path.${reset_color}
633 Note:  run 'apt-get install hwinfo' on systems running debian.
634 Exiting.${reset_color}"
635   exit -1
636 fi
637
638 if ! [[ -d /sys ]] ; then
639   print "$bg[black]$fg[red]${bold_color}Error: mounted /sys required (for hwinfo).${reset_color}
640 You may want to add the following line to your /etc/fstab:
641
642   sysfs /sys sysfs defaults 0 0
643
644 or just run 'mount /sys'. Exiting.${reset_color}"
645   exit -1
646 fi
647 }
648 requirements
649 # }}}
650
651 # xconfig {{{
652 xconfig() {
653 cat << EOX
654 ################################################################################
655 # Filename:      $XCONFIG
656 # Purpose:       config file for xserver - generated by grml-x
657 # Bug-Reports:   see http://grml.org/bugs/
658 # Latest change: ${DATE}
659 # See also:
660 #   /usr/share/doc/xserver-xorg/   and
661 #   http://wiki.x.org/wiki/Home    and
662 #   http://ftp.x.org/pub/X11R7.0/doc/html/index.html for information on Xorg
663 # Refer to the xorg.conf man page and to
664 # http://ftp.x.org/pub/X11R7.0/doc/html/xorg.conf.5.html
665 # for details about the format of this file.
666 #
667 # If you would like this file to be automatically reconfigured by debian,
668 # run the following command:
669 #   sudo dpkg-reconfigure -phigh xserver-xorg
670 ################################################################################
671
672 Section "ServerLayout"
673         Identifier     "XServer Configured"
674         Screen      0  "Screen0" 0 0
675         # InputDevice    "Keyboard0"     "CoreKeyboard"
676         # InputDevice    "Generic Mouse" "CorePointer"
677 $MOUSE
678 EndSection
679
680 Section "ServerFlags"
681         Option "AllowMouseOpenFail"  "true"  # allows the server to start up even if the mouse does not work
682         Option "DontVTSwitch"        "false" # allow switching between virtual terminal
683         # Option "DontZap"             "true"  # disable <Crtl><Alt><BS> (server abort)
684         # Option "DontZoom"            "true"  # disable <Crtl><Alt><KP_+>/<KP_-> (resolution switching)
685 EndSection
686
687 Section "Files"
688         # More information:  http://ftp.x.org/pub/X11R7.0/doc/html/fonts.html
689 $XFONTS
690         # FontPath     "/usr/share/fonts/ttf/western"
691         # FontPath     "/usr/share/fonts/ttf/decoratives"
692         FontPath     "/usr/share/fonts/truetype/ttf-bitstream-vera"
693         FontPath     "/usr/share/fonts/latex-ttf-fonts"
694         FontPath     "/var/lib/defoma/x-ttcidfont-conf.d/dirs/TrueType"
695 EndSection
696
697 # Modules - see /usr/X11R6/lib/modules/fonts and /usr/X11R6/lib/modules/extensions
698 Section "Module"
699         Load  "dbe"       # double buffer extension
700         Load  "dri"       # direct rendering
701         Load  "glx"       # 3D layer / GLX extension
702         Load  "type1"     # type1 font module
703         Load  "freetype"  # freetype fonts rendering
704         Load  "extmod"    # some commonly used server extensions (e.g. shape extension)
705         Load  "record"    # recording extension
706         Load  "evdev"     # generic input handling driver on Linux
707         # Load  "vbe"       # Vesa BIOS Extension
708         # Load  "i2c"       # I2C bus
709         # Load  "int10"     # initialize graphics cards via int10 call to the BIOS
710         # Load  "v4l"       # Video for Linux
711         ## Deprecated/unneeded modules with Xorg >=7.0:
712         # Load  "speedo"    # font module (does not exist anymore)
713         # Load  "ddc"       # ddc probing of monitor (automatically loaded)
714         # Load  "GLcore"    # render OpenGL in software (automatically loaded)
715         # Load  "bitmap"    # bitmap fonts (automatically loaded)
716 # Valid entries - see /usr/lib/xorg/modules/[extensions/]
717 # afb bitmap cfb cfb16 cfb24 cfb32 cw damage dbe ddc dri drm extmod fb
718 # fbdevhw freetype GLcore glx i2c int10 int10 layer mfb pcidata rac ramdac
719 # record scanpci shadow shadowfb type1 vbe vgahw xaa xf1bpp xf24_32bpp xf4bpp
720 # xf8_16bpp xf8_32bpp xtrap
721 EndSection
722
723 # If you'd like to switch the positions of your capslock and control keys, use:
724 # Option "XkbOptions" "ctrl:swapcaps"
725 # Or if you just want both to be control, use:
726 # Option "XkbOptions" "ctrl:nocaps"
727 # More information: http://ftp.x.org/pub/X11R7.0/doc/html/XKB-Config.html
728 # Section "InputDevice"
729 #         Identifier  "Keyboard0"
730 #         Option      "CoreKeyboard"
731 #         $KEYBOARD
732 #         # Option      "XkbOptions" "ctrl:swapcaps,grp:alt_shift_toggle,grp_led:scroll,compose:menu"
733 # EndSection
734
735 # More information: http://ftp.x.org/pub/X11R7.0/doc/html/mouse.html
736 $USBMOUSEDETAIL
737 $PS2MOUSEDETAIL
738 $SERMOUSEDETAIL
739 $SYNMOUSEDETAIL
740 $EVDEV_MOUSE
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