slitaz-tools view tinyutils/tazx @ rev 390

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