slitaz-tools view tinyutils/tazx @ rev 431
Auto-install non-free firmware (to avoid wifi confusion for users)
author | Rohit Joshi <jozee@slitaz.org> |
---|---|
date | Mon Feb 22 13:05:37 2010 +0000 (2010-02-22) |
parents | 0eb4f6b032fa |
children | 627b4051b6e6 |
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) 2009 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.
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 value=`$DIALOG \
163 --clear --colors \
164 --title " Configure X " \
165 --menu \
166 "The 'tazx' application helps you to configure your X session.\n\
167 Window Manager : \Z2$WM\Zn" 16 70 5 \
168 $(Xvesa -listmodes 2>&1 | grep ^0x | awk '{ printf "%s %s\n",$2,$3 }' | sort -nr | grep x[1-2][4-6]) \
169 "xterm" "800x600x16" \
170 "xorg" "Install Xorg" \
171 "text" "Disable X autostart" \
172 "quit" "Quitter" \
173 2>&1 1>&3`
174 retval=$?
175 exec 3>&-
176 # Continue, exit or help...
177 case $retval in
178 0)
179 continue ;;
180 1)
181 echo "Cancel pressed..."
182 exit 0 ;;
183 255)
184 if test -n "$value"; then
185 continue
186 else
187 echo "ESC pressed..."
188 exit 0
189 fi ;;
190 esac
191 # Set selected value.
192 case $value in
193 xorg)
194 install_xorg ;;
195 xterm)
196 Xvesa -ac -shadow -screen 800x600x16 -br &
197 exec xterm -cr orange -geometry 80x35+0-0 ;;
198 text)
199 sed -i s/'slim'/''/ /etc/rcS.conf
200 exit 0 ;;
201 *)
202 NEW_SCREEN=$value ;;
203 esac
204 }
206 # Slim config if root.
207 slim_config()
208 {
209 if test $(id -u) = 0; then
210 # /etc/X11/screen.conf exists for Live mode, if this file does not
211 # exist tazx is executed at boot time.
212 mkdir -p /etc/X11
213 echo "SCREEN=$NEW_SCREEN" > /etc/X11/screen.conf
214 # Get current screen size and sed config file with the new value.
215 if [ -f /etc/slim.conf ]; then
216 RES=$(grep ^xserver_arguments /etc/slim.conf | \
217 sed 's/xserver_arguments.*-screen *//' | awk '{ print $1 }')
218 #sed -i "s/\(xserver_arguments.*-screen\).*/\1 $NEW_SCREEN/" /etc/slim.conf
219 sed -i s/"-screen $RES"/"-screen $NEW_SCREEN"/ /etc/slim.conf
220 fi
221 fi
222 }
224 # Window manager specific configuration.
225 wm_config()
226 {
227 case $WM in
228 ob|openbox)
229 WM=openbox-session
230 XSEVER_OPTS="dpms +extension Composite"
231 # Check if a personal autostart script exists if OB is installed.
232 if [ -d "/var/lib/tazpkg/installed/openbox" ]; then
233 if [ ! -f "$HOME/.config/openbox/autostart.sh" ]; then
234 mkdir -p $HOME/.config/openbox
235 cp /etc/xdg/openbox/autostart.sh $HOME/.config/openbox
236 fi
237 # Script for default user (uid=1000).
238 if [ ! -f "/home/$USER/.config/openbox/autostart.sh" ]; then
239 mkdir -p /home/$USER/.config/openbox
240 cp /etc/xdg/openbox/autostart.sh /home/$USER/.config/openbox
241 fi
242 if [ ! -f "/home/$USER/.config/openbox/menu.xml" ]; then
243 mkdir -p /home/$USER/.config/openbox
244 cp /etc/xdg/openbox/menu.xml /home/$USER/.config/openbox
245 fi
246 chown -R $USER.$USER /home/$USER/.config
247 fi ;;
248 jwm)
249 WM=jwm
250 XSEVER_OPTS="dpms +extension Composite"
251 JWM_CONFIG=$HOME/.jwmrc
252 if [ -d "/var/lib/tazpkg/installed/jwm" ]; then
253 if [ ! -f "$JWM_CONFIG" ]; then
254 cp /etc/jwm/system.jwmrc $JWM_CONFIG
255 fi
256 # In Live mode default user/root JWM config does not exist and
257 # $HOME is not set, this is because tazx is executed by boot
258 # scripts.
259 if [ ! -f "/home/$USER/.jwmrc" ]; then
260 cp /etc/jwm/system.jwmrc /home/$USER/.jwmrc
261 chown $USER.$USER /home/$USER/.jwmrc
262 fi
263 if [ ! -f "/root/.jwmrc" -a `id -u` = 0 ]; then
264 cp /etc/jwm/system.jwmrc /root/.jwmrc
265 fi
266 fi ;;
267 pekwm)
268 WM=pekwm
269 XSEVER_OPTS="dpms"
270 if [ -d "/var/lib/tazpkg/installed/pekwm" ]; then
271 if [ -d "$HOME/.pekwm" ]; then
272 cp -R /etc/pekwm $HOME/.pekwm
273 fi
274 # In Live mode we want config before starting pekwm the first time.
275 if [ ! -d "/home/$USER/.pekwm" ]; then
276 cp -R /etc/pekwm /home/$USER/.pekwm
277 chown -R $USER.$USER /home/$USER/.pekwm
278 chmod +x /home/$USER/.pekwm/start
279 fi
280 if [ ! -d "/root/.pekwm" -a `id -u` = 0 ]; then
281 cp -R /etc/pekwm /root/.pekwm
282 chmod +x /root/.pekwm/start
283 fi
284 fi ;;
285 e17|enlightenment)
286 WM=enlightenment_start
287 XSEVER_OPTS="dpms -terminate" ;;
288 fluxbox)
289 WM=startfluxbox
290 XSEVER_OPTS="dpms" ;;
291 dwm|karmen)
292 WM=$WM-session
293 XSEVER_OPTS="dpms" ;;
294 awesome)
295 WM=awesome
296 XSEVER_OPTS="dpms" ;;
297 xfce|xfce4)
298 WM=xfce4-session
299 XSEVER_OPTS="dpms -terminate" ;;
300 esac
301 }
303 # Sample xinitrc for user (WM can be specified with F1 at slim login).
304 xinitrc_sample()
305 {
306 cat > $FILE << "EOF"
307 # ~/.xinitrc: Executed by slim login manager to startx X session.
308 # You can use F1 with Slim to chage your window manager or configure
309 # it permanently with your personnal applications.conf file.
310 #
311 . $HOME/.config/slitaz/applications.conf
313 case $1 in
314 e17|enlightenment*)
315 exec enlightenment_start ;;
316 openbox|openbox-session|ob)
317 exec openbox-session ;;
318 dwm|dwm-session)
319 exec dwm-session ;;
320 fluxbox|startfluxbox)
321 exec startfluxbox ;;
322 awesome)
323 exec awesome ;;
324 pekwm)
325 exec pekwm ;;
326 karmen|karmen-session)
327 exec karmen-session ;;
328 jwm)
329 lxpanel &
330 exec jwm ;;
331 xfce|xfce4|xfce4-session)
332 xfce4-session ;;
333 *)
334 exec $WINDOW_MANAGER ;;
335 esac
336 EOF
337 # Set default WM in applications.conf user file. Default WM can be
338 # configured graphicaly with 'desktopbox tazapps'
339 . $CONFIG
340 sed -i s/"WINDOW_MANAGER=.*"/"WINDOW_MANAGER=\"$WM\""/ \
341 $CONFIG
342 }
344 # ~/.xinitrc for slim login.
345 creat_xinitrc()
346 {
347 FILE=$HOME/.xinitrc
348 CONFIG=$HOME/.config/slitaz/applications.conf
349 if [ ! -f $CONFIG ]; then
350 mkdir -p $HOME/.config/slitaz
351 cp /etc/slitaz/applications.conf $CONFIG
352 fi
353 xinitrc_sample
354 # In Live mode default user needs a xinitrc, since tazx
355 # is executed only by root.
356 if [ ! -f /home/$USER/.xinitrc ]; then
357 FILE=/home/$USER/.xinitrc
358 CONFIG=/home/$USER/.config/slitaz/applications.conf
359 if [ ! -f $CONFIG ]; then
360 mkdir -p /home/$USER/.config/slitaz
361 cp /etc/slitaz/applications.conf $CONFIG
362 fi
363 xinitrc_sample
364 chown $USER.$USER $FILE
365 chown -R $USER.$USER /home/$USER/.config/slitaz
366 fi
367 }
369 # Create ~/.xsession to keep the configuration selected (used
370 # only by startx, Slim login manager uses .xinitrc).
371 creat_xsession()
372 {
373 cat > $HOME/.xsession << _EOF_
374 # ~/.xsession: Start X window session manually on your system (startx).
375 #
376 _EOF_
377 if [ "$XSERVER " == "Xorg" ]; then
378 echo 'Xorg &' >> $HOME/.xsession
379 else
380 cat >> $HOME/.xsession << _EOT_
381 $XSERVER -ac -shadow $XSEVER_OPTS \\
382 -screen $NEW_SCREEN \\
383 -keybd $KEYBD \\
384 -mouse $MOUSE &
385 _EOT_
386 fi
387 echo '#xterm &' >> $HOME/.xsession
388 echo '#xpad &' >> $HOME/.xsession
389 # LXpanel by default with JWM.
390 if [ "$WM" = "jwm" ]; then
391 echo 'lxpanel &' >> $HOME/.xsession
392 fi
393 echo "exec $WM" >> $HOME/.xsession
394 chmod 700 $HOME/.xsession
395 }
397 ###################
398 # Tazx sequence #
399 ###################
401 case "$1" in
402 show-config)
403 . /etc/X11/screen.conf
404 echo ""
405 echo "X11 screen resolution: $SCREEN"
406 echo ""
407 echo "Slim configuration for X server:"
408 cat /etc/slim.conf | grep ^default_xserver
409 cat /etc/slim.conf | grep ^xserver_arguments
410 echo "" ;;
411 install-xorg)
412 # WM can be specified on cmdline.
413 if [ -n "$2" ]; then
414 WM=$2
415 fi
416 install_xorg
417 slim_config
418 wm_config
419 creat_xinitrc
420 creat_xsession ;;
421 config-xorg)
422 # WM can be specified on cmdline.
423 if [ -n "$2" ]; then
424 WM=$2
425 fi
426 XSERVER="Xorg"
427 wm_config
428 creat_xinitrc
429 creat_xsession
430 patch_xorg_kbd ;;
431 *)
432 # WM can be specified on cmdline.
433 if [ -n "$1" ]; then
434 WM=$1
435 fi
436 [ -n "$NEW_SCREEN" ] || screen_config_dialog
437 slim_config
438 wm_config
439 creat_xinitrc
440 creat_xsession ;;
441 esac
443 exit 0