slitaz-tools view tinyutils/tazx @ rev 516

tazx: incorrect tux; slitaz installer creates 1008 user
author Rohit Joshi <jozee@slitaz.org>
date Wed Nov 10 20:26:12 2010 -0500 (2010-11-10)
parents b1d5d569e454
children a5216abd91c5
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 Managers.
6 #
7 # (c) 2010 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 fo Xvesa.
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=`cat /etc/passwd | grep "/home" | cut -d ":" -f 1`
22 ####################
23 # Tazx functions #
24 ####################
26 # Populate xorg.conf.d.
27 xorg_conf_d()
28 {
29 # Define the xorg.conf.d (can be /etc/X11/xorg.conf.d or /usr/share/X11/xorg.conf.d)
30 xorg_config=/etc/X11/xorg.conf.d
32 # Define the xorg.conf.new place.
33 xorg_template=/root/xorg.conf.new
35 # Obtain a default configuration file from Xorg.
36 Xorg -configure :1
38 # Backup existing config.
39 tar -cf $xorg_config/../Previous_xorg.conf.d.tar $xorg_config/ &> /dev/null
41 # Put the differents sections in separate files in the configuration directory.
42 sed -e '/Section "ServerLayout"/,/EndSection/!d' -e "s/EndSection/EndSection\n/" $xorg_template | grep -v Core > $xorg_config/10-ServerLayout.conf
43 sed -e '/Section "Files"/,/EndSection/!d' -e "s/EndSection/EndSection\n/" $xorg_template > $xorg_config/20-Files.conf
44 sed -e '/Section "Module"/,/EndSection/!d' -e "s/EndSection/EndSection\n/" $xorg_template > $xorg_config/30-Module.conf
45 sed -e '/Section "Monitor"/,/EndSection/!d' -e "s/EndSection/EndSection\n/" $xorg_template > $xorg_config/50-Monitor.conf
46 sed -e '/Section "Device"/,/EndSection/!d' -e "s/EndSection/EndSection\n/" $xorg_template > $xorg_config/60-Device.conf
47 sed -e '/Section "Screen"/,/EndSection/!d' -e "s/EndSection/EndSection\n/" $xorg_template > $xorg_config/70-Screen.conf
49 # Remove the template.
50 rm $xorg_template
52 # Configure the keyboard with the right keymap.
53 keymap=`cat /etc/keymap.conf`
54 keyboard_config=$xorg_config/40-Keyboard.conf
55 echo 'Section "InputClass"
56 Identifier "Keyboard Defaults"
57 MatchIsKeyboard "yes"' > $keyboard_config
58 case $keymap in
59 fr_CH-latin1)
60 # Swiss FrenCH
61 echo ' Option "XkbLayout" "ch"
62 Option "XkbVariant" "fr"' >> $keyboard_config
63 ;;
64 en)
65 # Englisk UK
66 echo ' Option "XkbLayout" "en"
67 Option "XkbVariant" "en"' >> $keyboard_config
68 ;;
69 ru)
70 # Russian
71 echo ' Option "XkbLayout" "us,ru(winkeys)"
72 Option "XkbVariant" "grp:alt_shift_toggle"' >> $keyboard_config
73 ;;
74 slovene)
75 # Slovenian
76 echo ' Option "XkbLayout" "si"
77 Option "XkbOptions" "grp:alt_shift_toggle"' >> $keyboard_config
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 echo ' Option "XkbLayout" "'$keymap\" >> $keyboard_config
86 ;;
87 esac
89 echo 'Endsection' >> $keyboard_config
91 # Create a xorg.conf if needed.
92 [ ! -f /etc/X11/xorg.conf ] && echo "# You can put here your own Xorg configurations.
93 # This configuration file is read before all files in /etc/X11/xorg.conf.d
94 # This file will not be erased by any updates." > /etc/X11/xorg.conf
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_conf_d
130 sed -i 's|/usr/bin/Xvesa|/usr/bin/Xorg|' /etc/slim.conf
131 sed -i s/"^xserver_arguments"/'\#xserver_arguments'/ /etc/slim.conf
132 XSERVER=Xorg ;;
133 esac
134 }
136 # Screen configuration dialog.
137 screen_config_dialog()
138 {
139 exec 3>&1
140 if [ -x /usr/bin/Xvesa ]; then
141 value=`$DIALOG \
142 --clear --colors \
143 --title " Configure X " \
144 --menu \
145 "The 'tazx' application helps you to configure your X session.\n\
146 Window Manager : \Z2$WM\Zn \n\
147 X server : \Z2Xvesa\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 or reconfigure Xorg" \
151 "text" "Disable X autostart" \
152 "quit" "Quit Tazx utility" \
153 2>&1 1>&3`
154 else
155 value=`$DIALOG \
156 --clear --colors \
157 --title " Configure X " \
158 --menu \
159 "The 'tazx' application helps you to configure your X session.\n\
160 Window Manager : \Z2$WM\Zn \n\
161 X server : \Z2Xorg\Zn" 16 70 5 \
162 "xorg" "Install or reconfigure Xorg" \
163 "text" "Disable X autostart" \
164 "quit" "Quit Tazx utility" \
165 2>&1 1>&3`
166 fi
167 retval=$?
168 exec 3>&-
169 # Continue, exit or help...
170 case $retval in
171 0)
172 continue ;;
173 1)
174 echo "Cancel pressed..."
175 exit 0 ;;
176 255)
177 if test -n "$value"; then
178 continue
179 else
180 echo "ESC pressed..."
181 exit 0
182 fi ;;
183 esac
184 # Set selected value.
185 case $value in
186 xorg)
187 install_xorg ;;
188 xterm)
189 # Only with Xvesa.
190 Xvesa -ac -shadow -screen 800x600x16 -br &
191 exec xterm -cr orange -geometry 80x35+0-0 ;;
192 text)
193 sed -i s/'slim'/''/ /etc/rcS.conf
194 exit 0 ;;
195 *)
196 NEW_SCREEN=$value ;;
197 esac
198 }
200 # Slim config if root.
201 slim_config()
202 {
203 if test $(id -u) = 0; then
204 # /etc/X11/screen.conf exists for Live mode, if this file does not
205 # exist tazx is executed at boot time.
206 mkdir -p /etc/X11
207 echo "SCREEN=$NEW_SCREEN" > /etc/X11/screen.conf
208 # Get current screen size and sed config file with the new value.
209 if [ -f /etc/slim.conf ]; then
210 XSERV_ARGS=$(grep ^xserver_arguments /etc/slim.conf)
211 RES=$( echo $XSERV_ARGS | sed 's/xserver_arguments.*-screen *//' | awk '{print $1 }')
212 NEW_XSERV_ARGS=$(echo $XSERV_ARGS | sed s/"-screen $RES"/"-screen $NEW_SCREEN"/)
213 # Comment the old one and put the new one in the config file
214 sed -i 's/"$XSERV_ARGS"/"# $XSERV_ARGS\n$NEW_XSERV_ARGS"/' /etc/slim.conf
216 fi
217 fi
218 }
220 # Window manager specific configuration.
221 wm_config()
222 {
223 case $WM in
224 ob|openbox)
225 WM=openbox-session
226 XSEVER_OPTS="dpms +extension Composite"
227 # Check if a personal autostart script exists if OB is installed.
228 if [ -d "/var/lib/tazpkg/installed/openbox" ]; then
229 if [ ! -f "$HOME/.config/openbox/autostart.sh" ]; then
230 mkdir -p $HOME/.config/openbox
231 cp /etc/xdg/openbox/autostart.sh $HOME/.config/openbox
232 fi
233 # Script for default user (uid=1000).
234 if [ ! -f "/home/$USER/.config/openbox/autostart.sh" ]; then
235 mkdir -p /home/$USER/.config/openbox
236 cp /etc/xdg/openbox/autostart.sh /home/$USER/.config/openbox
237 fi
238 if [ ! -f "/home/$USER/.config/openbox/menu.xml" ]; then
239 mkdir -p /home/$USER/.config/openbox
240 cp /etc/xdg/openbox/menu.xml /home/$USER/.config/openbox
241 fi
242 chown -R $USER.$USER /home/$USER/.config
243 fi ;;
244 jwm)
245 WM=jwm
246 XSEVER_OPTS="dpms +extension Composite"
247 JWM_CONFIG=$HOME/.jwmrc
248 if [ -d "/var/lib/tazpkg/installed/jwm" ]; then
249 if [ ! -f "$JWM_CONFIG" ]; then
250 cp /etc/jwm/system.jwmrc $JWM_CONFIG
251 fi
252 # In Live mode default user/root JWM config does not exist and
253 # $HOME is not set, this is because tazx is executed by boot
254 # scripts.
255 if [ ! -f "/home/$USER/.jwmrc" ]; then
256 cp /etc/jwm/system.jwmrc /home/$USER/.jwmrc
257 chown $USER.$USER /home/$USER/.jwmrc
258 fi
259 if [ ! -f "/root/.jwmrc" -a `id -u` = 0 ]; then
260 cp /etc/jwm/system.jwmrc /root/.jwmrc
261 fi
262 fi ;;
263 pekwm)
264 WM=pekwm
265 XSEVER_OPTS="dpms"
266 if [ -d "/var/lib/tazpkg/installed/pekwm" ]; then
267 if [ -d "$HOME/.pekwm" ]; then
268 cp -R /etc/pekwm $HOME/.pekwm
269 fi
270 # In Live mode we want config before starting pekwm the first time.
271 if [ ! -d "/home/$USER/.pekwm" ]; then
272 cp -R /etc/pekwm /home/$USER/.pekwm
273 chown -R $USER.$USER /home/$USER/.pekwm
274 chmod +x /home/$USER/.pekwm/start
275 fi
276 if [ ! -d "/root/.pekwm" -a `id -u` = 0 ]; then
277 cp -R /etc/pekwm /root/.pekwm
278 chmod +x /root/.pekwm/start
279 fi
280 fi ;;
281 e17|enlightenment)
282 WM=enlightenment_start
283 XSEVER_OPTS="dpms -terminate" ;;
284 fluxbox)
285 WM=startfluxbox
286 XSEVER_OPTS="dpms" ;;
287 dwm|karmen)
288 WM=$WM-session
289 XSEVER_OPTS="dpms" ;;
290 awesome)
291 WM=awesome
292 XSEVER_OPTS="dpms" ;;
293 xfce|xfce4)
294 WM=xfce4-session
295 XSEVER_OPTS="dpms -terminate" ;;
296 esac
297 }
299 # Sample xinitrc for user (WM can be specified with F1 at slim login).
300 xinitrc_sample()
301 {
302 cat > $FILE << "EOF"
303 # ~/.xinitrc: Executed by slim login manager to startx X session.
304 # You can use F1 with Slim to change your window manager or configure
305 # it permanently with your personal applications.conf file.
306 #
307 . $HOME/.config/slitaz/applications.conf
309 case $1 in
310 e17|enlightenment*)
311 exec enlightenment_start ;;
312 openbox|openbox-session|ob)
313 exec openbox-session ;;
314 dwm|dwm-session)
315 exec dwm-session ;;
316 fluxbox|startfluxbox)
317 exec startfluxbox ;;
318 awesome)
319 exec awesome ;;
320 pekwm)
321 exec pekwm ;;
322 karmen|karmen-session)
323 exec karmen-session ;;
324 jwm)
325 lxpanel &
326 exec jwm ;;
327 xfce|xfce4|xfce4-session)
328 xfce4-session ;;
329 *)
330 exec $WINDOW_MANAGER ;;
331 esac
332 EOF
333 # Set default WM in applications.conf user file. Default WM can be
334 # configured graphically with 'desktopbox tazapps'
335 . $CONFIG
336 sed -i s/"WINDOW_MANAGER=.*"/"WINDOW_MANAGER=\"$WM\""/ \
337 $CONFIG
338 }
340 # ~/.xinitrc for slim login.
341 creat_xinitrc()
342 {
343 FILE=$HOME/.xinitrc
344 CONFIG=$HOME/.config/slitaz/applications.conf
345 if [ ! -f $CONFIG ]; then
346 mkdir -p $HOME/.config/slitaz
347 cp /etc/slitaz/applications.conf $CONFIG
348 fi
349 xinitrc_sample
350 # In Live mode default user needs a xinitrc, since tazx
351 # is executed only by root.
352 if [ ! -f /home/$USER/.xinitrc ]; then
353 FILE=/home/$USER/.xinitrc
354 CONFIG=/home/$USER/.config/slitaz/applications.conf
355 if [ ! -f $CONFIG ]; then
356 mkdir -p /home/$USER/.config/slitaz
357 cp /etc/slitaz/applications.conf $CONFIG
358 fi
359 xinitrc_sample
360 chown $USER.$USER $FILE
361 chown -R $USER.$USER /home/$USER/.config/slitaz
362 fi
363 }
365 # Create ~/.xsession to keep the configuration selected (used
366 # only by startx, Slim login manager uses .xinitrc).
367 creat_xsession()
368 {
369 [ -f $HOME/.xsession ] && cp -f $HOME/.xsession $HOME/.previous_xsession
370 cat > $HOME/.xsession << _EOF_
371 # ~/.xsession: Start X window session manually on your system (startx).
372 #
373 _EOF_
374 if [ -x /usr/bin/Xorg ]; then
375 echo 'Xorg &' >> $HOME/.xsession
376 else
377 cat >> $HOME/.xsession << _EOT_
378 Xvesa -ac -shadow $XSEVER_OPTS \\
379 -screen $NEW_SCREEN \\
380 -keybd $KEYBD \\
381 -mouse $MOUSE &
382 _EOT_
383 fi
384 echo '#xterm &' >> $HOME/.xsession
385 echo '#xpad &' >> $HOME/.xsession
386 # LXpanel by default with JWM.
387 if [ "$WM" = "jwm" ]; then
388 echo 'lxpanel &' >> $HOME/.xsession
389 fi
390 echo "exec $WM" >> $HOME/.xsession
391 chmod 700 $HOME/.xsession
392 }
394 ###################
395 # Tazx sequence #
396 ###################
398 case "$1" in
399 show-config)
400 . /etc/X11/screen.conf
401 echo ""
402 echo "X11 screen resolution: $SCREEN"
403 echo ""
404 echo "Slim configuration for X server:"
405 cat /etc/slim.conf | grep ^default_xserver
406 cat /etc/slim.conf | grep ^xserver_arguments
407 echo "" ;;
408 install-xorg)
409 # WM can be specified on cmdline.
410 if [ -n "$2" ]; then
411 WM=$2
412 fi
413 install_xorg
414 slim_config
415 wm_config
416 creat_xinitrc
417 creat_xsession ;;
418 config-xorg)
419 # WM can be specified on cmdline.
420 if [ -n "$2" ]; then
421 WM=$2
422 fi
423 XSERVER="Xorg"
424 wm_config
425 creat_xinitrc
426 creat_xsession
427 xorg_conf_d ;;
428 *)
429 # WM can be specified on cmdline.
430 if [ -n "$1" ]; then
431 WM=$1
432 fi
433 [ -n "$NEW_SCREEN" ] || screen_config_dialog
434 slim_config
435 wm_config
436 creat_xinitrc
437 creat_xsession ;;
438 esac
440 exit 0