slitaz-tools view tinyutils/tazx @ rev 494

Update xorg autoconfiguration tool (again)
author Antoine Bodin <gokhlayeh@mailoo.org>
date Mon Jul 05 17:51:53 2010 +0200 (2010-07-05)
parents d2c5ec45b766
children b1be14a7c9e2
line source
1 #!/bin/sh
2 #
3 # Tazx - Ncurses X configuration for SliTaz GNU/Linux using Dialog boxes.
4 # This tinyutils is part of slitaz-tools. Tazx can configure Xvesa kdrive
5 # and Xorg with several Window Manager.
6 #
7 # (c) 2010 SliTaz GNU/Linux - GNU gpl v3.
8 # Authors: Christophe Lincoln <pankso@slitaz.org>
9 # Pascal Bellard <pascal.bellard@slitaz.org>
10 #
11 : ${DIALOG=tazdialog}
13 # Default value fo Xvesa.
14 XSERVER=Xvesa
15 KEYBD=keyboard
16 MOUSE=mouse,5,/dev/input/mice
17 WM=openbox
19 # Default user for config files in Live mode.
20 USER=`cat /etc/passwd | grep 1000 | cut -d ":" -f 1`
22 ####################
23 # Tazx functions #
24 ####################
26 # Populate xorg.conf.d.
27 xorg_conf_d()
28 {
29 # Define the xorg.conf.d (can be /etc/X11/xorg.conf.d or /usr/share/X11/xorg.conf.d)
30 xorg_config=/etc/X11/xorg.conf.d
32 # Define the xorg.conf.new place.
33 xorg_template=/root/xorg.conf.new
35 # Obtain a default configuration file from Xorg.
36 Xorg -configure :1
38 # Put the differents sections in separate files in the configuration directory.
39 sed -e '/Section "ServerLayout"/,/EndSection/!d' -e "s/EndSection/EndSection\n/" $xorg_template | grep -v Core > $xorg_config/10-ServerLayout.conf
40 sed -e '/Section "Files"/,/EndSection/!d' -e "s/EndSection/EndSection\n/" $xorg_template > $xorg_config/20-Files.conf
41 sed -e '/Section "Module"/,/EndSection/!d' -e "s/EndSection/EndSection\n/" $xorg_template > $xorg_config/30-Module.conf
42 sed -e '/Section "Monitor"/,/EndSection/!d' -e "s/EndSection/EndSection\n/" $xorg_template > $xorg_config/50-Monitor.conf
43 sed -e '/Section "Device"/,/EndSection/!d' -e "s/EndSection/EndSection\n/" $xorg_template > $xorg_config/60-Device.conf
44 sed -e '/Section "Screen"/,/EndSection/!d' -e "s/EndSection/EndSection\n/" $xorg_template > $xorg_config/70-Screen.conf
46 # Remove the template.
47 rm $xorg_template
49 # Configure the keyboard with the right keymap.
50 keymap=`cat /etc/keymap.conf`
51 keyboard_config=$xorg_config/40-Keyboard.conf
52 echo 'Section "InputClass"
53 Identifier "Keyboard Defaults"
54 MatchIsKeyboard "yes"' > $keyboard_config
55 case $keymap in
56 fr_CH-latin1)
57 # Swiss FrenCH
58 echo ' Option "XkbLayout" "ch"
59 Option "XkbVariant" "fr"' >> $keyboard_config
60 ;;
61 en)
62 # Englisk UK
63 echo ' Option "XkbLayout" "en"
64 Option "XkbVariant" "en"' >> $keyboard_config
65 ;;
66 ru)
67 # Russian
68 echo ' Option "XkbLayout" "us,ru(winkeys)"
69 Option "XkbVariant" "grp:alt_shift_toggle"' >> $keyboard_config
70 ;;
71 slovene)
72 # Slovenian
73 echo ' Option "XkbLayout" "si"
74 Option "XkbOptions" "grp:alt_shift_toggle"' >> $keyboard_config
75 ;;
76 *)
77 # Use clean /etc/keymap.conf value.
78 keymap=${keymap%-latin1}
79 keymap=${keymap%-lat2}
80 keymap=${keymap%-lat6}
81 keymap=${keymap%-abnt2}
82 echo ' Option "XkbLayout" "'$keymap\" >> $keyboard_config
83 ;;
84 esac
86 echo 'Endsection' >> $keyboard_config
88 # Create a xorg.conf if needed.
89 [ ! -f /etc/X11/xorg.conf ] && echo "# You can put here you're own Xorg configurations.
90 # This configuration file is readed before all files in /etc/X11/xorg.conf.d
91 # This file will not be erased by next updates." > /etc/X11/xorg.conf
92 }
94 # Install xorg server
95 install_xorg()
96 {
97 tazpkg recharge
98 exec 3>&1
99 value=`$DIALOG --clear --colors --title " Install Xorg " \
100 --menu \
101 "The 'tazx' application helps you to select your X driver." 16 70 5 \
102 $(grep xorg-xf86-video /var/lib/tazpkg/packages.list | cut -d- -f4 | while read x; do echo $x; echo driver; done) \
103 "quit" "Quitter" \
104 2>&1 1>&3`
105 retval=$?
106 exec 3>&-
107 # Continue, exit...
108 case $retval in
109 1)
110 echo "Cancel pressed..."
111 exit 0 ;;
112 255)
113 if test -z "$value"; then
114 echo "ESC pressed..."
115 exit 0
116 fi ;;
117 esac
118 # Set selected value.
119 case $value in
120 quit)
121 echo "Quit..."
122 exit 0 ;;
123 *)
124 tazpkg get-install xorg-server
125 tazpkg get-install xorg-xf86-video-$value
126 xorg_conf_d
127 sed -i 's|/usr/bin/Xvesa|/usr/bin/Xorg|' /etc/slim.conf
128 sed -i s/"^xserver_arguments"/'\#xserver_arguments'/ /etc/slim.conf
129 XSERVER=Xorg ;;
130 esac
131 }
133 # Screen configuration dialog.
134 screen_config_dialog()
135 {
136 exec 3>&1
137 if [ -x /usr/bin/Xvesa ]; then
138 value=`$DIALOG \
139 --clear --colors \
140 --title " Configure X " \
141 --menu \
142 "The 'tazx' application helps you to configure your X session.\n\
143 Window Manager : \Z2$WM\Zn \n\
144 X server : \Z2Xvesa\Zn" 16 70 5 \
145 $(Xvesa -listmodes 2>&1 | grep ^0x | awk '{ printf "%s %s\n",$2,$3 }' | sort -nr | grep x[1-2][4-6]) \
146 "xterm" "800x600x16" \
147 "xorg" "Install or reconfigure Xorg" \
148 "text" "Disable X autostart" \
149 "quit" "Quit Tazx utility" \
150 2>&1 1>&3`
151 else
152 value=`$DIALOG \
153 --clear --colors \
154 --title " Configure X " \
155 --menu \
156 "The 'tazx' application helps you to configure your X session.\n\
157 Window Manager : \Z2$WM\Zn \n\
158 X server : \Z2Xorg\Zn" 16 70 5 \
159 "xorg" "Install or reconfigure Xorg" \
160 "text" "Disable X autostart" \
161 "quit" "Quit Tazx utility" \
162 2>&1 1>&3`
163 fi
164 retval=$?
165 exec 3>&-
166 # Continue, exit or help...
167 case $retval in
168 0)
169 continue ;;
170 1)
171 echo "Cancel pressed..."
172 exit 0 ;;
173 255)
174 if test -n "$value"; then
175 continue
176 else
177 echo "ESC pressed..."
178 exit 0
179 fi ;;
180 esac
181 # Set selected value.
182 case $value in
183 xorg)
184 install_xorg ;;
185 xterm)
186 # Only with Xvesa
187 Xvesa -ac -shadow -screen 800x600x16 -br &
188 exec xterm -cr orange -geometry 80x35+0-0 ;;
189 text)
190 sed -i s/'slim'/''/ /etc/rcS.conf
191 exit 0 ;;
192 *)
193 NEW_SCREEN=$value ;;
194 esac
195 }
197 # Slim config if root.
198 slim_config()
199 {
200 if test $(id -u) = 0; then
201 # /etc/X11/screen.conf exists for Live mode, if this file does not
202 # exist tazx is executed at boot time.
203 mkdir -p /etc/X11
204 echo "SCREEN=$NEW_SCREEN" > /etc/X11/screen.conf
205 # Get current screen size and sed config file with the new value.
206 if [ -f /etc/slim.conf ]; then
207 RES=$(grep ^xserver_arguments /etc/slim.conf | \
208 sed 's/xserver_arguments.*-screen *//' | awk '{ print $1 }')
209 #sed -i "s/\(xserver_arguments.*-screen\).*/\1 $NEW_SCREEN/" /etc/slim.conf
210 sed -i s/"-screen $RES"/"-screen $NEW_SCREEN"/ /etc/slim.conf
211 fi
212 fi
213 }
215 # Window manager specific configuration.
216 wm_config()
217 {
218 case $WM in
219 ob|openbox)
220 WM=openbox-session
221 XSEVER_OPTS="dpms +extension Composite"
222 # Check if a personal autostart script exists if OB is installed.
223 if [ -d "/var/lib/tazpkg/installed/openbox" ]; then
224 if [ ! -f "$HOME/.config/openbox/autostart.sh" ]; then
225 mkdir -p $HOME/.config/openbox
226 cp /etc/xdg/openbox/autostart.sh $HOME/.config/openbox
227 fi
228 # Script for default user (uid=1000).
229 if [ ! -f "/home/$USER/.config/openbox/autostart.sh" ]; then
230 mkdir -p /home/$USER/.config/openbox
231 cp /etc/xdg/openbox/autostart.sh /home/$USER/.config/openbox
232 fi
233 if [ ! -f "/home/$USER/.config/openbox/menu.xml" ]; then
234 mkdir -p /home/$USER/.config/openbox
235 cp /etc/xdg/openbox/menu.xml /home/$USER/.config/openbox
236 fi
237 chown -R $USER.$USER /home/$USER/.config
238 fi ;;
239 jwm)
240 WM=jwm
241 XSEVER_OPTS="dpms +extension Composite"
242 JWM_CONFIG=$HOME/.jwmrc
243 if [ -d "/var/lib/tazpkg/installed/jwm" ]; then
244 if [ ! -f "$JWM_CONFIG" ]; then
245 cp /etc/jwm/system.jwmrc $JWM_CONFIG
246 fi
247 # In Live mode default user/root JWM config does not exist and
248 # $HOME is not set, this is because tazx is executed by boot
249 # scripts.
250 if [ ! -f "/home/$USER/.jwmrc" ]; then
251 cp /etc/jwm/system.jwmrc /home/$USER/.jwmrc
252 chown $USER.$USER /home/$USER/.jwmrc
253 fi
254 if [ ! -f "/root/.jwmrc" -a `id -u` = 0 ]; then
255 cp /etc/jwm/system.jwmrc /root/.jwmrc
256 fi
257 fi ;;
258 pekwm)
259 WM=pekwm
260 XSEVER_OPTS="dpms"
261 if [ -d "/var/lib/tazpkg/installed/pekwm" ]; then
262 if [ -d "$HOME/.pekwm" ]; then
263 cp -R /etc/pekwm $HOME/.pekwm
264 fi
265 # In Live mode we want config before starting pekwm the first time.
266 if [ ! -d "/home/$USER/.pekwm" ]; then
267 cp -R /etc/pekwm /home/$USER/.pekwm
268 chown -R $USER.$USER /home/$USER/.pekwm
269 chmod +x /home/$USER/.pekwm/start
270 fi
271 if [ ! -d "/root/.pekwm" -a `id -u` = 0 ]; then
272 cp -R /etc/pekwm /root/.pekwm
273 chmod +x /root/.pekwm/start
274 fi
275 fi ;;
276 e17|enlightenment)
277 WM=enlightenment_start
278 XSEVER_OPTS="dpms -terminate" ;;
279 fluxbox)
280 WM=startfluxbox
281 XSEVER_OPTS="dpms" ;;
282 dwm|karmen)
283 WM=$WM-session
284 XSEVER_OPTS="dpms" ;;
285 awesome)
286 WM=awesome
287 XSEVER_OPTS="dpms" ;;
288 xfce|xfce4)
289 WM=xfce4-session
290 XSEVER_OPTS="dpms -terminate" ;;
291 esac
292 }
294 # Sample xinitrc for user (WM can be specified with F1 at slim login).
295 xinitrc_sample()
296 {
297 cat > $FILE << "EOF"
298 # ~/.xinitrc: Executed by slim login manager to startx X session.
299 # You can use F1 with Slim to chage your window manager or configure
300 # it permanently with your personnal applications.conf file.
301 #
302 . $HOME/.config/slitaz/applications.conf
304 case $1 in
305 e17|enlightenment*)
306 exec enlightenment_start ;;
307 openbox|openbox-session|ob)
308 exec openbox-session ;;
309 dwm|dwm-session)
310 exec dwm-session ;;
311 fluxbox|startfluxbox)
312 exec startfluxbox ;;
313 awesome)
314 exec awesome ;;
315 pekwm)
316 exec pekwm ;;
317 karmen|karmen-session)
318 exec karmen-session ;;
319 jwm)
320 lxpanel &
321 exec jwm ;;
322 xfce|xfce4|xfce4-session)
323 xfce4-session ;;
324 *)
325 exec $WINDOW_MANAGER ;;
326 esac
327 EOF
328 # Set default WM in applications.conf user file. Default WM can be
329 # configured graphicaly with 'desktopbox tazapps'
330 . $CONFIG
331 sed -i s/"WINDOW_MANAGER=.*"/"WINDOW_MANAGER=\"$WM\""/ \
332 $CONFIG
333 }
335 # ~/.xinitrc for slim login.
336 creat_xinitrc()
337 {
338 FILE=$HOME/.xinitrc
339 CONFIG=$HOME/.config/slitaz/applications.conf
340 if [ ! -f $CONFIG ]; then
341 mkdir -p $HOME/.config/slitaz
342 cp /etc/slitaz/applications.conf $CONFIG
343 fi
344 xinitrc_sample
345 # In Live mode default user needs a xinitrc, since tazx
346 # is executed only by root.
347 if [ ! -f /home/$USER/.xinitrc ]; then
348 FILE=/home/$USER/.xinitrc
349 CONFIG=/home/$USER/.config/slitaz/applications.conf
350 if [ ! -f $CONFIG ]; then
351 mkdir -p /home/$USER/.config/slitaz
352 cp /etc/slitaz/applications.conf $CONFIG
353 fi
354 xinitrc_sample
355 chown $USER.$USER $FILE
356 chown -R $USER.$USER /home/$USER/.config/slitaz
357 fi
358 }
360 # Create ~/.xsession to keep the configuration selected (used
361 # only by startx, Slim login manager uses .xinitrc).
362 creat_xsession()
363 {
364 cat > $HOME/.xsession << _EOF_
365 # ~/.xsession: Start X window session manually on your system (startx).
366 #
367 _EOF_
368 if [ -x /usr/bin/Xorg ]; then
369 echo 'Xorg &' >> $HOME/.xsession
370 else
371 cat >> $HOME/.xsession << _EOT_
372 Xvesa -ac -shadow $XSEVER_OPTS \\
373 -screen $NEW_SCREEN \\
374 -keybd $KEYBD \\
375 -mouse $MOUSE &
376 _EOT_
377 fi
378 echo '#xterm &' >> $HOME/.xsession
379 echo '#xpad &' >> $HOME/.xsession
380 # LXpanel by default with JWM.
381 if [ "$WM" = "jwm" ]; then
382 echo 'lxpanel &' >> $HOME/.xsession
383 fi
384 echo "exec $WM" >> $HOME/.xsession
385 chmod 700 $HOME/.xsession
386 }
388 ###################
389 # Tazx sequence #
390 ###################
392 case "$1" in
393 show-config)
394 . /etc/X11/screen.conf
395 echo ""
396 echo "X11 screen resolution: $SCREEN"
397 echo ""
398 echo "Slim configuration for X server:"
399 cat /etc/slim.conf | grep ^default_xserver
400 cat /etc/slim.conf | grep ^xserver_arguments
401 echo "" ;;
402 install-xorg)
403 # WM can be specified on cmdline.
404 if [ -n "$2" ]; then
405 WM=$2
406 fi
407 install_xorg
408 slim_config
409 wm_config
410 creat_xinitrc
411 creat_xsession ;;
412 config-xorg)
413 # WM can be specified on cmdline.
414 if [ -n "$2" ]; then
415 WM=$2
416 fi
417 XSERVER="Xorg"
418 wm_config
419 creat_xinitrc
420 creat_xsession
421 xorg_conf_d ;;
422 *)
423 # WM can be specified on cmdline.
424 if [ -n "$1" ]; then
425 WM=$1
426 fi
427 [ -n "$NEW_SCREEN" ] || screen_config_dialog
428 slim_config
429 wm_config
430 creat_xinitrc
431 creat_xsession ;;
432 esac
434 exit 0