Updated debian/rules
[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   DATE=$(date)
38   [ -n "$XINITRC" ] || XINITRC="$HOME/.xinitrc"
39 # }}}
40
41 # make sure we don't leave any temp files {{{
42 bailout() {
43   [ -n "$1" ] && EXIT="$1" || EXIT="1"
44   print "$bg[black]$fg[red]${bold_color}Exiting...${reset_color}">&2
45   exit "$EXIT"
46 }
47
48 trap bailout 1 2 3 15
49 # }}}
50
51 # warn if running as user root {{{
52   if [ -n "$ROOT" ] ; then
53         print "$bg[black]$fg[red]${bold_color}E: Refusing to run as root, please start \"sudo -u grml grml-x $@\" instead${reset_color}"
54         print ''
55         exit 2
56   fi
57   fstabuser=$(grep ':x:1000:' /etc/passwd)
58   fstabuser=${fstabuser%%[:]*}
59 # }}}
60
61 # usage information {{{
62 usage()
63 {
64   if [[ $1 != '' ]] ; then echo 1>&2 "\n$1" ; fi
65   print "$bg[black]$fg[red]$bold_color"
66   print 1>&2 "
67 Usage: $PROGRAMNAME
68        $PROGRAMNAME windowmanager
69
70 Usage examples:
71   $PROGRAMNAME fluxbox
72   XINITRC=~/.xinitrc $PROGRAMNAME fluxbox
73   $PROGRAMNAME -display 8 fluxbox
74
75 More information on grml-x can be found in the manual page: man grml-x
76 "
77   print "${reset_color}"
78   exit 2
79 }
80 # }}}
81
82 # runit {{{
83 function runit
84 {
85   if [ "$(readlink /etc/X11/X)" = /bin/true ] ; then
86      print "$bold_color$fg[red]Fatal: /etc/X11/X is a symlink to /bin/true."
87      print "Fix it via running 'ln -sf /usr/bin/Xorg /etc/X11/X'"
88      exit 10
89   fi
90   if [ -z "$NOSTART" ] ; then
91     print "$reset_color"
92     if [ -x /etc/init.d/xorg-common ] ; then
93       sudo /etc/init.d/xorg-common start
94     else
95       if [ -x /etc/init.d/xfree86-common ] ; then
96         sudo /etc/init.d/xfree86-common start
97       fi
98     fi
99     print ""
100     if [ -z "$DISPLAY" ] ; then
101       print "$bold_color$fg[green]Now trying to run startx.$reset_color"
102       startx $XINITRC -- $XOPTS
103       return 1
104     else
105       print "$bold_color$fg[green]Now trying to run startx on display $DISPLAY.$reset_color"
106       startx $XINITRC -- :$DISPLAY $XOPTS
107       return 1
108     fi
109   else
110     print "$bold_color$fg[blue]Not running startx as requested via option.$reset_color"
111   fi
112 }
113 # }}}
114
115 # failed {{{
116 function failed
117 {
118   print "$fg[red]"
119   if [ -z "$ROOT" ] ; then
120     if [[ $(tty) == /dev/pts/* ]] ; then
121       print "It seems you are running $PROGRAMNAME from inside GNU screen.
122 Notice that this might fail if running as user grml!
123 Please exit screen and try to run $PROGRAMNAME again."
124     fi
125   fi
126   print "Problems with the module used for X? Try to use grml-x-legacy:
127   $PROGRAMNAME-legacy -module radeon ...
128   $PROGRAMNAME-legacy -module vesa  ...
129
130 Do you want to deactivate a present synaptics touchpad? Run:
131   $PROGRAMNAME-legacy -nosynaptics ...
132
133 Your monitor is very old and/or does not support DDC-probing?
134   $PROGRAMNAME-legacy -noddc ...
135
136 Do you want to create a x configuration file but do not start X?
137   $PROGRAMNAME-legacy -nostart ...
138
139 Monitor frequency too high or too low? Just specify hsync/vsync manually:
140   $PROGRAMNAME-legacy -hsync 30-65 ...
141   $PROGRAMNAME-legacy -hsync 30-65 -vsync 50-60 ...
142
143 Want to adjust the resolution? Use the mode-switch:
144   $PROGRAMNAME-legacy -mode 1024x768 ...
145   $PROGRAMNAME-legacy -mode '1280x1024 1024x768' ...
146
147 Problems? Use vesa with resolution 1024x768:
148   $PROGRAMNAME-legacy -module vesa -mode 1024x768 ...
149
150 Still problems with X? Use the fallback option:
151   $PROGRAMNAME-legacy -fallback ...
152
153 To adjust resolution while running X execute:
154   xrandr -s '1024x768'
155
156 More information on grml-x can be found in the manual page: man grml-x
157
158 Report bugs, send wishes and feedback to the grml team:
159 http://grml.org/bugs/ - contact (at) grml.org
160 "
161 print -n "$reset_color"
162 }
163 # }}}
164
165 # parameter handling {{{
166 if [ "$#" -ne 1 ] ; then
167         usage
168 fi
169 WINDOWMANAGER="$1"
170 # }}}
171
172
173 # xinitrc {{{
174 if [ -n "$WINDOWMANAGER" ] ; then
175   if ! [ -x "$(which $WINDOWMANAGER)" ] ; then
176     print "$bg[black]$fg[red]${bold_color}Fatal: windowmanager $fg[blue]$WINDOWMANAGER$fg[red] not executable, startx will not work.${reset_color}">&2
177     bailout
178   fi
179   if [ -w "$XINITRC" ] ; then
180     sed -i "s|^[^#]*exec.*|  exec $WINDOWMANAGER|g" $XINITRC
181   else
182     echo -e "#!/bin/sh\n  exec $WINDOWMANAGER" >> $XINITRC
183   fi
184   runit || failed
185 fi
186 # }}}
187
188 ## END OF FILE #################################################################
189 # vim:foldmethod=marker expandtab ai ft=zsh sw=2