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