slitaz-tools view tinyutils/tazx @ rev 312

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