slitaz-tools view tinyutils/tazx @ rev 402

installer: Add root passwd and default user setting functions
author Christophe Lincoln <pankso@slitaz.org>
date Sat Nov 07 00:03:26 2009 +0100 (2009-11-07)
parents c127ff8c4f11
children cf3f10a1e2dc
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" = "root"] && 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 xfce|xfce4)
278 WM=xfce4-session
279 XSEVER_OPTS="dpms -terminate" ;;
280 esac
281 }
283 # Sample xinitrc for user (WM can be specified with F1 at slim login).
284 xinitrc_sample()
285 {
286 cat > $FILE << "EOF"
287 # ~/.xinitrc: Executed by slim login manager to startx X session.
288 # You can use F1 with Slim to chage your window manager or configure
289 # it permanently with your personnal applications.conf file.
290 #
291 . $HOME/.config/slitaz/applications.conf
293 case $1 in
294 e17|enlightenment*)
295 exec enlightenment_start ;;
296 openbox|openbox-session|ob)
297 exec openbox-session ;;
298 dwm|dwm-session)
299 exec dwm-session ;;
300 fluxbox|startfluxbox)
301 exec startfluxbox ;;
302 awesome)
303 exec awesome ;;
304 pekwm)
305 exec pekwm ;;
306 karmen|karmen-session)
307 exec karmen-session ;;
308 jwm)
309 lxpanel &
310 exec jwm ;;
311 xfce|xfce4|xfce4-session)
312 xfce4-session ;;
313 *)
314 exec $WINDOW_MANAGER ;;
315 esac
316 EOF
317 # Set default WM in applications.conf user file. Default WM can be
318 # configured graphicaly with 'desktopbox tazapps'
319 . $CONFIG
320 sed -i s/"WINDOW_MANAGER=.*"/"WINDOW_MANAGER=\"$WM\""/ \
321 $CONFIG
322 }
324 # ~/.xinitrc for slim login.
325 creat_xinitrc()
326 {
327 FILE=$HOME/.xinitrc
328 CONFIG=$HOME/.config/slitaz/applications.conf
329 if [ ! -f $CONFIG ]; then
330 mkdir -p $HOME/.config/slitaz
331 cp /etc/slitaz/applications.conf $CONFIG
332 fi
333 xinitrc_sample
334 # In Live mode default user needs a xinitrc, since tazx
335 # is executed only by root.
336 if [ ! -f /home/$USER/.xinitrc ]; then
337 FILE=/home/$USER/.xinitrc
338 CONFIG=/home/$USER/.config/slitaz/applications.conf
339 if [ ! -f $CONFIG ]; then
340 mkdir -p /home/$USER/.config/slitaz
341 cp /etc/slitaz/applications.conf $CONFIG
342 fi
343 xinitrc_sample
344 chown $USER.$USER $FILE
345 chown -R $USER.$USER /home/$USER/.config/slitaz
346 fi
347 }
349 # Create ~/.xsession to keep the configuration selected (used
350 # only by startx, Slim login manager uses .xinitrc).
351 creat_xsession()
352 {
353 cat > $HOME/.xsession << _EOF_
354 # ~/.xsession: Start X window session manually on your system (startx).
355 #
356 _EOF_
357 if [ "$XSERVER " == "Xorg" ]; then
358 echo 'Xorg &' >> $HOME/.xsession
359 else
360 cat >> $HOME/.xsession << _EOT_
361 $XSERVER -ac -shadow $XSEVER_OPTS \\
362 -screen $NEW_SCREEN \\
363 -keybd $KEYBD \\
364 -mouse $MOUSE &
365 _EOT_
366 fi
367 echo '#xterm &' >> $HOME/.xsession
368 echo '#xpad &' >> $HOME/.xsession
369 # LXpanel by default with JWM.
370 if [ "$WM" = "jwm" ]; then
371 echo 'lxpanel &' >> $HOME/.xsession
372 fi
373 echo "exec $WM" >> $HOME/.xsession
374 chmod 700 $HOME/.xsession
375 }
377 ###################
378 # Tazx sequence #
379 ###################
381 case "$1" in
382 show-config)
383 . /etc/X11/screen.conf
384 echo ""
385 echo "X11 screen resolution: $SCREEN"
386 echo ""
387 echo "Slim configuration for X server:"
388 cat /etc/slim.conf | grep ^default_xserver
389 cat /etc/slim.conf | grep ^xserver_arguments
390 echo "" ;;
391 install-xorg)
392 # WM can be specified on cmdline.
393 if [ -n "$2" ]; then
394 WM=$2
395 fi
396 install_xorg
397 slim_config
398 wm_config
399 creat_xinitrc
400 creat_xsession ;;
401 *)
402 # WM can be specified on cmdline.
403 if [ -n "$1" ]; then
404 WM=$1
405 fi
406 [ -n "$NEW_SCREEN" ] || screen_config_dialog
407 slim_config
408 wm_config
409 creat_xinitrc
410 creat_xsession ;;
411 esac
413 exit 0