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