slitaz-tools view tinyutils/tazx @ rev 339

Improve and add all WM to tazx + WM config in applications.conf
author Christophe Lincoln <pankso@slitaz.org>
date Mon May 04 22:37:14 2009 +0200 (2009-05-04)
parents 8db152539be7
children ba541e2168a6
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 --help-button \
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 2)
166 $DIALOG --clear \
167 --title " Aide - Help " --textbox "$DOC" 16 70
168 exec tazx ;;
169 255)
170 if test -n "$value"; then
171 continue
172 else
173 echo "ESC pressed..."
174 exit 0
175 fi ;;
176 esac
177 # Set selected value.
178 case $value in
179 xorg)
180 install_xorg ;;
181 xterm)
182 Xvesa -ac -shadow -screen 800x600x16 -br &
183 exec xterm -cr orange -geometry 80x35+0-0 ;;
184 *)
185 NEW_SCREEN=$value ;;
186 esac
187 }
189 # Slim config if root.
190 slim_config()
191 {
192 if test $(id -u) = 0; then
193 # /etc/X11/screen.conf exists for Live mode, if this file does not
194 # exist tazx is executed at boot time.
195 mkdir -p /etc/X11
196 echo "SCREEN=$NEW_SCREEN" > /etc/X11/screen.conf
197 # Get current screen size and sed config file with the new value.
198 if [ -f /etc/slim.conf ]; then
199 RES=$(grep ^xserver_arguments /etc/slim.conf | sed 's/xserver_arguments.*-screen *//')
200 sed -i "s/\(xserver_arguments.*-screen\).*/\1 $NEW_SCREEN/" /etc/slim.conf
201 fi
202 JWM_CONFIG=/etc/jwm/system.jwmrc
203 fi
204 }
206 # Window manager specific configuration.
207 wm_config()
208 {
209 case $WM in
210 ob|openbox)
211 WM=openbox-session
212 XSEVER_OPTS="dpms +extension Composite"
213 # Check if a personal autostart script exists if OB is installed.
214 if [ -d "/var/lib/tazpkg/installed/openbox" ]; then
215 if [ ! -f "$HOME/.config/openbox/autostart.sh" ]; then
216 mkdir -p $HOME/.config/openbox
217 cp /etc/xdg/openbox/autostart.sh $HOME/.config/openbox
218 fi
219 # Script for default user (uid=1000).
220 if [ ! -f "/home/$USER/.config/openbox/autostart.sh" ]; then
221 mkdir -p /home/$USER/.config/openbox
222 cp /etc/xdg/openbox/autostart.sh /home/$USER/.config/openbox
223 fi
224 if [ ! -f "/home/$USER/.config/openbox/menu.xml" ]; then
225 mkdir -p /home/$USER/.config/openbox
226 cp /etc/xdg/openbox/menu.xml /home/$USER/.config/openbox
227 fi
228 chown -R $USER.$USER /home/$USER/.config
229 fi ;;
230 jwm)
231 WM=jwm
232 XSEVER_OPTS="dpms +extension Composite"
233 JWM_CONFIG=$HOME/.jwmrc
234 if [ -d "/var/lib/tazpkg/installed/jwm" ]; then
235 if [ ! -f "$JWM_CONFIG" ]; then
236 cp /etc/jwm/system.jwmrc $JWM_CONFIG
237 fi
238 # In Live mode default user/root JWM config does not exist and
239 # $HOME is not set, this is because tazx is executed by boot
240 # scripts.
241 if [ ! -f "/home/$USER/.jwmrc" ]; then
242 cp /etc/jwm/system.jwmrc /home/$USER/.jwmrc
243 chown $USER.$USER /home/$USER/.jwmrc
244 fi
245 if [ ! -f "/root/.jwmrc" -a `id -u` = 0 ]; then
246 cp /etc/jwm/system.jwmrc /root/.jwmrc
247 fi
248 fi ;;
249 pekwm)
250 WM=pekwm
251 XSEVER_OPTS="dpms"
252 if [ -d "/var/lib/tazpkg/installed/pekwm" ]; then
253 if [ -d "$HOME/.pekwm" ]; then
254 cp -R /etc/pekwm $HOME/.pekwm
255 fi
256 # In Live mode we want config before starting pekwm the first time.
257 if [ ! -d "/home/$USER/.pekwm" ]; then
258 cp -R /etc/pekwm /home/$USER/.pekwm
259 chown -R $USER.$USER /home/$USER/.pekwm
260 chmod +x /home/$USER/.pekwm/start
261 fi
262 if [ ! -d "/root/.pekwm" -a `id -u` = 0 ]; then
263 cp -R /etc/pekwm /root/.pekwm
264 chmod +x /root/.pekwm/start
265 fi
266 fi ;;
267 e17|enlightenment)
268 WM=enlightenment_start
269 XSEVER_OPTS="dpms -terminate" ;;
270 fluxbox)
271 WM=startfluxbox
272 XSEVER_OPTS="dpms" ;;
273 dwm|karmen)
274 WM=$WM-session
275 XSEVER_OPTS="dpms" ;;
276 awesome)
277 WM=awesome
278 XSEVER_OPTS="dpms" ;;
279 esac
280 }
282 # Sample xinitrc for user (WM can be specified with F1 at slim login).
283 xinitrc_sample()
284 {
285 cat > $FILE << "EOF"
286 # ~/.xinitrc: Executed by slim login manager to startx X session.
287 # You can use F1 with Slim to chage your window manager or configure
288 # it permanently with your personnal applications.conf file.
289 #
290 . $HOME/.config/slitaz/applications.conf
292 case $1 in
293 e17|enlightenment*)
294 exec enlightenment_start ;;
295 openbox|openbox-session|ob)
296 exec openbox-session ;;
297 dwm|dwm-session)
298 exec dwm-session ;;
299 fluxbox|startfluxbox)
300 exec startfluxbox ;;
301 awesome)
302 exec awesome ;;
303 pekwm)
304 exec pekwm ;;
305 karmen|karmen-session)
306 exec karmen-session ;;
307 jwm)
308 lxpanel &
309 exec jwm ;;
310 *)
311 exec $WINDOW_MANAGER ;;
312 esac
313 EOF
314 # Set default WM in applications.conf user file. Default WM can be
315 # configured graphicaly with 'desktopbox tazapps'
316 . $CONFIG
317 sed -i s/"WINDOW_MANAGER=.*"/"WINDOW_MANAGER=\"$WM\""/ \
318 $CONFIG
319 }
321 # ~/.xinitrc for slim login.
322 creat_xinitrc()
323 {
324 FILE=$HOME/.xinitrc
325 CONFIG=$HOME/.config/slitaz/applications.conf
326 if [ ! -f $CONFIG ]; then
327 mkdir -p $HOME/.config/slitaz
328 cp /etc/slitaz/applications.conf $CONFIG
329 fi
330 xinitrc_sample
331 # In Live mode default user needs a xinitrc, since tazx
332 # is executed only by root.
333 if [ ! -f /home/$USER/.xinitrc ]; then
334 FILE=/home/$USER/.xinitrc
335 CONFIG=/home/$USER/.config/slitaz/applications.conf
336 if [ ! -f $CONFIG ]; then
337 mkdir -p /home/$USER/.config/slitaz
338 cp /etc/slitaz/applications.conf $CONFIG
339 fi
340 xinitrc_sample
341 chown $USER.$USER $FILE
342 chown -R $USER.$USER /home/$USER/.config/slitaz
343 fi
344 }
346 # Create ~/.xsession to keep the configuration selected (used
347 # only by startx, Slim login manager uses .xinitrc).
348 creat_xsession()
349 {
350 cat > $HOME/.xsession << _EOF_
351 # ~/.xsession: Start X window session manually on your system (startx).
352 #
353 _EOF_
354 if [ "$XSERVER " == "Xorg" ]; then
355 echo 'Xorg &' >> $HOME/.xsession
356 else
357 echo "$XSERVER -ac -shadow $XSEVER_OPTS -screen $NEW_SCREEN -mouse $MOUSE &" \
358 >> $HOME/.xsession
359 fi
360 echo '#xterm &' >> $HOME/.xsession
361 echo '#xpad &' >> $HOME/.xsession
362 # LXpanel by default with JWM.
363 if [ "$WM" = "jwm" ]; then
364 echo 'lxpanel &' >> $HOME/.xsession
365 fi
366 echo "exec $WM" >> $HOME/.xsession
367 chmod 700 $HOME/.xsession
368 }
370 ###################
371 # Tazx sequence #
372 ###################
374 [ -n "$NEW_SCREEN" ] || screen_config_dialog
375 slim_config
376 wm_config
377 creat_xinitrc
378 creat_xsession
380 exit 0