slitaz-tools view tinyutils/tazx @ rev 349

Added tag 3.1 for changeset f03d03012bdd
author Christophe Lincoln <pankso@slitaz.org>
date Tue May 05 01:56:14 2009 +0200 (2009-05-05)
parents 777b680060ec
children 8fa52d6b8af5
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.
5 #
6 # (c) 20080609 SliTaz GNU/Linux - GNU gpl v3.
7 # Authors: Christophe Lincoln <pankso@slitaz.org>
8 # Pascal Bellard <pascal.bellard@slitaz.org>
9 #
10 : ${DIALOG=tazdialog}
12 # Variables.
13 XSERVER=Xvesa
14 DOC=/usr/share/doc/slitaz-tools/tazx.txt
15 MOUSE=/dev/input/mice,5
16 # WM can be specified on cmdline.
17 if [ -n "$1" ]; then
18 WM=$1
19 else
20 WM=openbox
21 fi
22 # Default user for config files in Live mode.
23 USER=`cat /etc/passwd | grep 1000 | cut -d ":" -f 1`
25 ####################
26 # Tazx functions #
27 ####################
29 # Patch xorg.conf to set keymap layout.
30 patch_xorg_kbd()
31 {
32 KEYMAP=`cat /etc/keymap.conf`
33 case $KEYMAP in
34 fr_CH-latin1)
35 # Swiss FrenCH
36 patch -p0 <<EOF
37 --- /etc/X11/xorg.conf
38 +++ /etc/X11/xorg.conf
39 @@ -30,2 +30,3 @@
40 Driver "kbd"
41 + Option "XkbLayout" "ch"
42 + Option "XkbVariant" "fr"
43 EndSection
44 EOF
45 ;;
46 en)
47 # Englisk UK
48 patch -p0 <<EOF
49 --- /etc/X11/xorg.conf
50 +++ /etc/X11/xorg.conf
51 @@ -30,2 +30,3 @@
52 Driver "kbd"
53 + Option "XkbLayout" "en"
54 + Option "XkbVariant" "en"
55 EndSection
56 EOF
57 ;;
58 ru)
59 # Russian
60 patch -p0 <<EOF
61 --- /etc/X11/xorg.conf
62 +++ /etc/X11/xorg.conf
63 @@ -30,2 +30,3 @@
64 Driver "kbd"
65 + Option "XkbLayout" "us,ru(winkeys)"
66 + Option "XkbVariant" "grp:alt_shift_toggle"
67 EndSection
68 EOF
69 ;;
70 slovene)
71 # Slovenian
72 patch -p0 <<EOF
73 --- /etc/X11/xorg.conf
74 +++ /etc/X11/xorg.conf
75 @@ -30,2 +30,3 @@
76 Driver "kbd"
77 + Option "XkbLayout" "si"
78 + Option "XkbOptions" "grp:alt_shift_toggle"
79 EndSection
80 EOF
81 ;;
82 *)
83 # Use clean /etc/keymap.conf value.
84 KEYMAP=${KEYMAP%-latin1}
85 KEYMAP=${KEYMAP%-lat2}
86 KEYMAP=${KEYMAP%-lat6}
87 KEYMAP=${KEYMAP%-abnt2}
88 patch -p0 <<EOF
89 --- /etc/X11/xorg.conf
90 +++ /etc/X11/xorg.conf
91 @@ -30,2 +30,3 @@
92 Driver "kbd"
93 + Option "XkbLayout" "$KEYMAP"
94 EndSection
95 EOF
96 ;;
97 esac
98 }
100 # Install xorg server
101 install_xorg()
102 {
103 tazpkg recharge
104 exec 3>&1
105 value=`$DIALOG --clear --colors --title " Install Xorg " \
106 --menu \
107 "The 'tazx' application helps you to select your X driver." 16 70 5 \
108 $(grep xorg-xf86-video /var/lib/tazpkg/packages.list | cut -d- -f4 | while read x; do echo $x; echo driver; done) \
109 "quit" "Quitter" \
110 2>&1 1>&3`
111 retval=$?
112 exec 3>&-
113 # Continue, exit...
114 case $retval in
115 1)
116 echo "Cancel pressed..."
117 exit 0 ;;
118 255)
119 if test -z "$value"; then
120 echo "ESC pressed..."
121 exit 0
122 fi ;;
123 esac
124 # Set selected value.
125 case $value in
126 quit)
127 echo "Quit..."
128 exit 0 ;;
129 *)
130 tazpkg get-install xorg-server
131 tazpkg get-install xorg-xf86-video-$value
132 Xorg -configure :1
133 mv /root/xorg.conf.new /etc/X11/xorg.conf
134 patch_xorg_kbd
135 sed -i 's|/usr/bin/Xvesa|/usr/bin/Xorg|' /etc/slim.conf
136 sed -i s/"^xserver_arguments"/'\#xserver_arguments'/ /etc/slim.conf
137 XSERVER=Xorg;;
138 esac
139 }
141 # Screen configuration dialog.
142 screen_config_dialog()
143 {
144 exec 3>&1
145 value=`$DIALOG \
146 --clear --colors \
147 --title " Configure X " \
148 --menu \
149 "The 'tazx' application helps you to configure your X session.\n\
150 Window Manager : \Z2$WM\Zn" 16 70 5 \
151 $(Xvesa -listmodes 2>&1 | grep ^0x | awk '{ printf "%s %s\n",$2,$3 }' | sort -nr | grep x[1-2][4-6]) \
152 "xterm" "800x600x16" \
153 "xorg" "Installer Xorg" \
154 "quit" "Quitter" \
155 2>&1 1>&3`
156 retval=$?
157 exec 3>&-
158 # Continue, exit or help...
159 case $retval in
160 0)
161 continue ;;
162 1)
163 echo "Cancel pressed..."
164 exit 0 ;;
165 255)
166 if test -n "$value"; then
167 continue
168 else
169 echo "ESC pressed..."
170 exit 0
171 fi ;;
172 esac
173 # Set selected value.
174 case $value in
175 xorg)
176 install_xorg ;;
177 xterm)
178 Xvesa -ac -shadow -screen 800x600x16 -br &
179 exec xterm -cr orange -geometry 80x35+0-0 ;;
180 *)
181 NEW_SCREEN=$value ;;
182 esac
183 }
185 # Slim config if root.
186 slim_config()
187 {
188 if test $(id -u) = 0; then
189 # /etc/X11/screen.conf exists for Live mode, if this file does not
190 # exist tazx is executed at boot time.
191 mkdir -p /etc/X11
192 echo "SCREEN=$NEW_SCREEN" > /etc/X11/screen.conf
193 # Get current screen size and sed config file with the new value.
194 if [ -f /etc/slim.conf ]; then
195 RES=$(grep ^xserver_arguments /etc/slim.conf | sed 's/xserver_arguments.*-screen *//')
196 sed -i "s/\(xserver_arguments.*-screen\).*/\1 $NEW_SCREEN/" /etc/slim.conf
197 fi
198 JWM_CONFIG=/etc/jwm/system.jwmrc
199 fi
200 }
202 # Window manager specific configuration.
203 wm_config()
204 {
205 case $WM in
206 ob|openbox)
207 WM=openbox-session
208 XSEVER_OPTS="dpms +extension Composite"
209 # Check if a personal autostart script exists if OB is installed.
210 if [ -d "/var/lib/tazpkg/installed/openbox" ]; then
211 if [ ! -f "$HOME/.config/openbox/autostart.sh" ]; then
212 mkdir -p $HOME/.config/openbox
213 cp /etc/xdg/openbox/autostart.sh $HOME/.config/openbox
214 fi
215 # Script for default user (uid=1000).
216 if [ ! -f "/home/$USER/.config/openbox/autostart.sh" ]; then
217 mkdir -p /home/$USER/.config/openbox
218 cp /etc/xdg/openbox/autostart.sh /home/$USER/.config/openbox
219 fi
220 if [ ! -f "/home/$USER/.config/openbox/menu.xml" ]; then
221 mkdir -p /home/$USER/.config/openbox
222 cp /etc/xdg/openbox/menu.xml /home/$USER/.config/openbox
223 fi
224 chown -R $USER.$USER /home/$USER/.config
225 fi ;;
226 jwm)
227 WM=jwm
228 XSEVER_OPTS="dpms +extension Composite"
229 JWM_CONFIG=$HOME/.jwmrc
230 if [ -d "/var/lib/tazpkg/installed/jwm" ]; then
231 if [ ! -f "$JWM_CONFIG" ]; then
232 cp /etc/jwm/system.jwmrc $JWM_CONFIG
233 fi
234 # In Live mode default user/root JWM config does not exist and
235 # $HOME is not set, this is because tazx is executed by boot
236 # scripts.
237 if [ ! -f "/home/$USER/.jwmrc" ]; then
238 cp /etc/jwm/system.jwmrc /home/$USER/.jwmrc
239 chown $USER.$USER /home/$USER/.jwmrc
240 fi
241 if [ ! -f "/root/.jwmrc" -a `id -u` = 0 ]; then
242 cp /etc/jwm/system.jwmrc /root/.jwmrc
243 fi
244 fi ;;
245 pekwm)
246 WM=pekwm
247 XSEVER_OPTS="dpms"
248 if [ -d "/var/lib/tazpkg/installed/pekwm" ]; then
249 if [ -d "$HOME/.pekwm" ]; then
250 cp -R /etc/pekwm $HOME/.pekwm
251 fi
252 # In Live mode we want config before starting pekwm the first time.
253 if [ ! -d "/home/$USER/.pekwm" ]; then
254 cp -R /etc/pekwm /home/$USER/.pekwm
255 chown -R $USER.$USER /home/$USER/.pekwm
256 chmod +x /home/$USER/.pekwm/start
257 fi
258 if [ ! -d "/root/.pekwm" -a `id -u` = 0 ]; then
259 cp -R /etc/pekwm /root/.pekwm
260 chmod +x /root/.pekwm/start
261 fi
262 fi ;;
263 e17|enlightenment)
264 WM=enlightenment_start
265 XSEVER_OPTS="dpms -terminate" ;;
266 fluxbox)
267 WM=startfluxbox
268 XSEVER_OPTS="dpms" ;;
269 dwm|karmen)
270 WM=$WM-session
271 XSEVER_OPTS="dpms" ;;
272 awesome)
273 WM=awesome
274 XSEVER_OPTS="dpms" ;;
275 esac
276 }
278 # Sample xinitrc for user (WM can be specified with F1 at slim login).
279 xinitrc_sample()
280 {
281 cat > $FILE << "EOF"
282 # ~/.xinitrc: Executed by slim login manager to startx X session.
283 # You can use F1 with Slim to chage your window manager or configure
284 # it permanently with your personnal applications.conf file.
285 #
286 . $HOME/.config/slitaz/applications.conf
288 case $1 in
289 e17|enlightenment*)
290 exec enlightenment_start ;;
291 openbox|openbox-session|ob)
292 exec openbox-session ;;
293 dwm|dwm-session)
294 exec dwm-session ;;
295 fluxbox|startfluxbox)
296 exec startfluxbox ;;
297 awesome)
298 exec awesome ;;
299 pekwm)
300 exec pekwm ;;
301 karmen|karmen-session)
302 exec karmen-session ;;
303 jwm)
304 lxpanel &
305 exec jwm ;;
306 *)
307 exec $WINDOW_MANAGER ;;
308 esac
309 EOF
310 # Set default WM in applications.conf user file. Default WM can be
311 # configured graphicaly with 'desktopbox tazapps'
312 . $CONFIG
313 sed -i s/"WINDOW_MANAGER=.*"/"WINDOW_MANAGER=\"$WM\""/ \
314 $CONFIG
315 }
317 # ~/.xinitrc for slim login.
318 creat_xinitrc()
319 {
320 FILE=$HOME/.xinitrc
321 CONFIG=$HOME/.config/slitaz/applications.conf
322 if [ ! -f $CONFIG ]; then
323 mkdir -p $HOME/.config/slitaz
324 cp /etc/slitaz/applications.conf $CONFIG
325 fi
326 xinitrc_sample
327 # In Live mode default user needs a xinitrc, since tazx
328 # is executed only by root.
329 if [ ! -f /home/$USER/.xinitrc ]; then
330 FILE=/home/$USER/.xinitrc
331 CONFIG=/home/$USER/.config/slitaz/applications.conf
332 if [ ! -f $CONFIG ]; then
333 mkdir -p /home/$USER/.config/slitaz
334 cp /etc/slitaz/applications.conf $CONFIG
335 fi
336 xinitrc_sample
337 chown $USER.$USER $FILE
338 chown -R $USER.$USER /home/$USER/.config/slitaz
339 fi
340 }
342 # Create ~/.xsession to keep the configuration selected (used
343 # only by startx, Slim login manager uses .xinitrc).
344 creat_xsession()
345 {
346 cat > $HOME/.xsession << _EOF_
347 # ~/.xsession: Start X window session manually on your system (startx).
348 #
349 _EOF_
350 if [ "$XSERVER " == "Xorg" ]; then
351 echo 'Xorg &' >> $HOME/.xsession
352 else
353 echo "$XSERVER -ac -shadow $XSEVER_OPTS -screen $NEW_SCREEN -mouse $MOUSE &" \
354 >> $HOME/.xsession
355 fi
356 echo '#xterm &' >> $HOME/.xsession
357 echo '#xpad &' >> $HOME/.xsession
358 # LXpanel by default with JWM.
359 if [ "$WM" = "jwm" ]; then
360 echo 'lxpanel &' >> $HOME/.xsession
361 fi
362 echo "exec $WM" >> $HOME/.xsession
363 chmod 700 $HOME/.xsession
364 }
366 ###################
367 # Tazx sequence #
368 ###################
370 [ -n "$NEW_SCREEN" ] || screen_config_dialog
371 slim_config
372 wm_config
373 creat_xinitrc
374 creat_xsession
376 exit 0