slitaz-tools view tinyutils/tazx @ rev 534

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