slitaz-tools view tinyutils/tazx @ rev 628

tazx: code clean-up and more gettextization
author Christophe Lincoln <pankso@slitaz.org>
date Tue Jun 14 23:36:15 2011 +0200 (2011-06-14)
parents 585b0b30e445
children 093a5116dfff
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 Xorg with
5 # several Window Managers. The GTK interface to configure X is in tazbox.
6 #
7 # (c) 2011 SliTaz GNU/Linux - GNU gpl v3.
8 # Authors: Christophe Lincoln <pankso@slitaz.org>
9 # Pascal Bellard <pascal.bellard@slitaz.org>
10 #
11 : ${DIALOG=dialog}
13 # Default value.
14 WM=openbox
16 # Default user for config files in Live mode, id is 1000 since it is
17 # created by /etc/init.d/bootopts.sh.
18 USER=$(cat /etc/passwd | grep 1000 | cut -d ":" -f 1)
20 # Internationalization
21 . /usr/bin/gettext.sh
22 TEXTDOMAIN='slitaz-tools'
23 export TEXTDOMAIN
25 #
26 # Functions
27 #
29 # Be sure we're root.
30 check_root() {
31 if [ $(id -u) != 0 ]; then
32 gettext "You must be root to configure X server."
33 echo "" && exit 0
34 fi
35 }
37 # Populate xorg.conf.d.
38 xorg_conf_d()
39 {
40 # Define the xorg.conf.d (can be /etc/X11/xorg.conf.d or /usr/share/X11/xorg.conf.d)
41 xorg_config=/etc/X11/xorg.conf.d
43 # Define the xorg.conf.new place.
44 xorg_template=/root/xorg.conf.new
46 # Obtain a default configuration file from Xorg.
47 Xorg -configure :1
49 # Backup existing config.
50 tar -cf $xorg_config/../Previous_xorg.conf.d.tar $xorg_config/ &> /dev/null
52 # Put the differents sections in separate files in the config directory.
53 sed -e '/Section "ServerLayout"/,/EndSection/!d' \
54 -e "s/EndSection/EndSection\n/" $xorg_template | \
55 grep -v Core > $xorg_config/10-ServerLayout.conf
56 sed -e '/Section "Files"/,/EndSection/!d' \
57 -e "s/EndSection/EndSection\n/" $xorg_template > \
58 $xorg_config/20-Files.conf
59 sed -e '/Section "Module"/,/EndSection/!d' \
60 -e "s/EndSection/EndSection\n/" $xorg_template > \
61 $xorg_config/30-Module.conf
62 sed -e '/Section "Monitor"/,/EndSection/!d' \
63 -e "s/EndSection/EndSection\n/" $xorg_template > \
64 $xorg_config/50-Monitor.conf
65 sed -e '/Section "Device"/,/EndSection/!d' \
66 -e "s/EndSection/EndSection\n/" $xorg_template > \
67 $xorg_config/60-Device.conf
68 sed -e '/Section "Screen"/,/EndSection/!d' \
69 -e "s/EndSection/EndSection\n/" $xorg_template > \
70 $xorg_config/70-Screen.conf
72 # Remove the template.
73 rm $xorg_template
75 # Configure the keyboard with the right keymap.
76 keymap=`cat /etc/keymap.conf`
77 keyboard_config=$xorg_config/40-Keyboard.conf
78 echo 'Section "InputClass"
79 Identifier "Keyboard Defaults"
80 MatchIsKeyboard "yes"' > $keyboard_config
81 case $keymap in
82 fr_CH-latin1)
83 # Swiss FrenCH
84 echo ' Option "XkbLayout" "ch"
85 Option "XkbVariant" "fr"' >> $keyboard_config ;;
86 uk)
87 # English UK
88 echo ' Option "XkbLayout" "gb"' >> $keyboard_config ;;
89 ru)
90 # Russian
91 echo ' Option "XkbLayout" "us,ru(winkeys)"
92 Option "XkbVariant" "grp:alt_shift_toggle"' >> $keyboard_config ;;
93 slovene)
94 # Slovenian
95 echo ' Option "XkbLayout" "si"
96 Option "XkbOptions" "grp:alt_shift_toggle"' >> $keyboard_config ;;
97 us-acentos)
98 echo ' Option "XkbLayout" "us"
99 Option "XkbVariant" "intl"' >> $keyboard_config ;;
100 *)
101 # Use clean /etc/keymap.conf value.
102 keymap=${keymap%-latin1}
103 keymap=${keymap%-lat2}
104 keymap=${keymap%-lat6}
105 keymap=${keymap%-abnt2}
106 echo ' Option "XkbLayout" "'$keymap\" >> $keyboard_config ;;
107 esac
109 echo 'Endsection' >> $keyboard_config
111 # Create a xorg.conf if needed.
112 if [ ! -f /etc/X11/xorg.conf ]; then
113 cat > /etc/X11/xorg.conf << EOT
114 # You can put here your own Xorg configurations. This config file is read
115 # before all files in /etc/X11/xorg.conf.d and will NOT be erased by any
116 updates.
117 EOT
118 fi
119 }
121 # Install xorg server.
122 install_xorg()
123 {
124 [ -f "/var/lib/tazpkg/packages.list" ] || tazpkg recharge
125 exec 3>&1
126 value=`$DIALOG --clear --colors --title " Install Xorg " \
127 --menu \
128 "The 'tazx' application helps you to select your X driver." 16 70 5 \
129 $(fgrep xorg-xf86-video /var/lib/tazpkg/packages.list | cut -d- -f4 | while read x; do echo $x; echo driver; done) \
130 "quit" "Quitter" \
131 2>&1 1>&3`
132 retval=$?
133 exec 3>&-
135 # Continue or exit.
136 case $retval in
137 0) continue ;;
138 1|255) exit 0 ;;
139 esac
141 # Set selected value.
142 case $value in
143 quit) exit 0 ;;
144 *)
145 installed=/var/lib/tazpkg/installed/
146 [ -d "$installed/xorg-server" ] || tazpkg get-install xorg-server
147 [ -d "$installed/xorg-xf86-video-$value" ] || \
148 tazpkg get-install xorg-xf86-video-$value
149 xorg_conf_d ;;
150 esac
151 }
153 # Screen configuration dialog. TODO: menus items to enable/disable X on boot
154 # and sed /etc/rcS.conf to remove slim from RUN_DAEMONS.
155 config_dialog()
156 {
157 exec 3>&1
158 value=`$DIALOG \
159 --clear --colors \
160 --title " Configure X " \
161 --menu "\
162 $(gettext "Tazx dialog helps you to configure your Xorg.")\n\
163 $(gettext "Window Manager:") \Z2$WM\Zn \
164 $(gettext "X server:") \Z2Xorg\Zn" 16 70 5 \
165 "xorg" "$(gettext "Install or reconfigure Xorg")" \
166 "xfbdev" "$(gettext "Install TinyX server Xfbdev")" \
167 "quit" "$(gettext "Quit Tazx utility")" \
168 2>&1 1>&3`
169 retval=$?
170 exec 3>&-
172 # Continue or exit.
173 case $retval in
174 0) continue ;;
175 1|255) exit 0 ;;
176 esac
178 # Set selected value.
179 case $value in
180 xorg)
181 install_xorg ;;
182 xfbdev)
183 # FIXME: Much to do here, for now just install Xfbdev.
184 tazpkg get-install xorg-server-xfbdev ;;
185 *) exit 0 ;;
186 esac
187 }
189 # Window manager specific configuration.
190 wm_config()
191 {
192 case $WM in
193 ob|openbox)
194 WM=openbox-session
195 # Check if a personal autostart script exists if OB is installed.
196 if [ -d "/var/lib/tazpkg/installed/openbox" ]; then
197 if [ ! -f "$HOME/.config/openbox/autostart.sh" ]; then
198 mkdir -p $HOME/.config/openbox
199 cp /etc/xdg/openbox/autostart.sh $HOME/.config/openbox
200 fi
201 # Script for default user (uid=1000).
202 if [ ! -f "/home/$USER/.config/openbox/autostart.sh" ]; then
203 mkdir -p /home/$USER/.config/openbox
204 cp /etc/xdg/openbox/autostart.sh /home/$USER/.config/openbox
205 fi
206 if [ ! -f "/home/$USER/.config/openbox/menu.xml" ]; then
207 mkdir -p /home/$USER/.config/openbox
208 cp /etc/xdg/openbox/menu.xml /home/$USER/.config/openbox
209 fi
210 chown -R $USER.users /home/$USER/.config
211 fi ;;
212 jwm)
213 WM=jwm
214 JWM_CONFIG=$HOME/.jwmrc
215 if [ -d "/var/lib/tazpkg/installed/jwm" ]; then
216 if [ ! -f "$JWM_CONFIG" ]; then
217 cp /etc/jwm/system.jwmrc $JWM_CONFIG
218 fi
219 # In Live mode default user/root JWM config does not exist and
220 # $HOME is not set, this is because tazx is executed by boot
221 # scripts.
222 if [ ! -f "/home/$USER/.jwmrc" ]; then
223 cp /etc/jwm/system.jwmrc /home/$USER/.jwmrc
224 chown $USER.users /home/$USER/.jwmrc
225 fi
226 if [ ! -f "/root/.jwmrc" -a `id -u` = 0 ]; then
227 cp /etc/jwm/system.jwmrc /root/.jwmrc
228 fi
229 fi ;;
230 pekwm)
231 WM=pekwm
232 if [ -d "/var/lib/tazpkg/installed/pekwm" ]; then
233 if [ -d "$HOME/.pekwm" ]; then
234 cp -R /etc/pekwm $HOME/.pekwm
235 fi
236 # In Live mode we want config before starting pekwm the first time.
237 if [ ! -d "/home/$USER/.pekwm" ]; then
238 cp -R /etc/pekwm /home/$USER/.pekwm
239 chown -R $USER.users /home/$USER/.pekwm
240 chmod +x /home/$USER/.pekwm/start
241 fi
242 if [ ! -d "/root/.pekwm" -a `id -u` = 0 ]; then
243 cp -R /etc/pekwm /root/.pekwm
244 chmod +x /root/.pekwm/start
245 fi
246 fi ;;
247 e17|enlightenment)
248 WM=enlightenment_start ;;
249 fluxbox)
250 WM=startfluxbox ;;
251 dwm|karmen)
252 WM=$WM-session ;;
253 awesome)
254 WM=awesome ;;
255 xfce|xfce4)
256 WM=xfce4-session ;;
257 esac
258 }
260 # Sample xinitrc for user (WM can be specified with F1 at slim login).
261 xinitrc_sample()
262 {
263 cat > $FILE << "EOF"
264 # ~/.xinitrc: Executed by slim login manager to startx X session.
265 # You can use F1 with Slim to change your window manager or configure
266 # it permanently with your personal applications.conf file.
267 #
268 . $HOME/.config/slitaz/applications.conf
270 case $1 in
271 e17|enlightenment*)
272 exec enlightenment_start ;;
273 openbox|openbox-session|ob)
274 exec openbox-session ;;
275 dwm|dwm-session)
276 exec dwm-session ;;
277 fluxbox|startfluxbox)
278 exec startfluxbox ;;
279 awesome)
280 exec awesome ;;
281 pekwm)
282 exec pekwm ;;
283 karmen|karmen-session)
284 exec karmen-session ;;
285 jwm)
286 lxpanel &
287 exec jwm ;;
288 xfce|xfce4|xfce4-session)
289 xfce4-session ;;
290 *)
291 exec $WINDOW_MANAGER ;;
292 esac
293 EOF
294 # Set default WM in applications.conf user file. Default WM can be
295 # configured graphically with 'desktopbox tazapps'
296 . $CONFIG
297 sed -i s/"WINDOW_MANAGER=.*"/"WINDOW_MANAGER=\"$WM\""/ \
298 $CONFIG
299 }
301 # ~/.xinitrc for X login from a DM.
302 creat_xinitrc()
303 {
304 FILE=$HOME/.xinitrc
305 CONFIG=$HOME/.config/slitaz/applications.conf
306 if [ ! -f $CONFIG ]; then
307 mkdir -p $HOME/.config/slitaz
308 cp /etc/slitaz/applications.conf $CONFIG
309 fi
310 xinitrc_sample
311 # .xinitrc and config for /etc/skel so new added user will get
312 # a working X session.
313 if test $(id -u) = 0; then
314 FILE=/etc/skel/.xinitrc
315 CONFIG=/etc/skel/.config/slitaz/applications.conf
316 mkdir -p /etc/skel/.config/slitaz
317 cp -f /etc/slitaz/applications.conf $CONFIG
318 xinitrc_sample
319 fi
320 # In Live mode default user needs a xinitrc, since tazx
321 # is executed only by root.
322 CONFIG=/home/$USER/.config/slitaz/applications.conf
323 if [ ! -f $CONFIG ]; then
324 mkdir -p /home/$USER/.config/slitaz
325 cp /etc/slitaz/applications.conf $CONFIG
326 fi
327 chown -R $USER.users /home/$USER/.config/slitaz
328 if [ ! -f /home/$USER/.xinitrc ]; then
329 FILE=/home/$USER/.xinitrc
330 xinitrc_sample
331 chown $USER.users $FILE
332 fi
333 }
335 # Create ~/.xsession to keep the configuration selected (used
336 # only by startx, Slim login manager uses .xinitrc).
337 creat_xsession()
338 {
339 [ -f $HOME/.xsession ] && cp -f $HOME/.xsession $HOME/.previous_xsession
340 cat > $HOME/.xsession << _EOF_
341 # ~/.xsession: Start X window session manually on your system (startx).
342 #
343 Xorg &
344 #xterm &
345 _EOF_
346 # LXpanel by default with JWM.
347 if [ "$WM" = "jwm" ]; then
348 echo 'lxpanel &' >> $HOME/.xsession
349 fi
350 echo "exec $WM" >> $HOME/.xsession
351 chmod 700 $HOME/.xsession
352 }
355 # Commands - WM can be specified on cmdline.
357 case "$1" in
358 install-xorg)
359 check_root
360 if [ -n "$2" ]; then
361 WM=$2
362 fi
363 echo "xorg" > /etc/X11/screen.conf
364 install_xorg
365 wm_config
366 creat_xinitrc
367 creat_xsession ;;
368 config-xorg)
369 check_root
370 if [ -n "$2" ]; then
371 WM=$2
372 fi
373 echo "xorg" > /etc/X11/screen.conf
374 wm_config
375 creat_xinitrc
376 creat_xsession
377 xorg_conf_d
378 if grep -qs screen= /proc/cmdline ; then
379 MODE="$(sed 's/.*screen=\([0-9]*x[0-9]*\).*/\1/' < /proc/cmdline)"
380 sed -i "s/.*EndSubSection.*/\\t\\tModes\\t\"$MODE\"\\n&/" \
381 /etc/X11/xorg.conf.d/70-Screen.conf
382 fi ;;
383 *)
384 # User can get a new .xinitrc with tazx from cmdline.
385 if [ -n "$1" ]; then
386 WM=$1
387 fi
388 if test $(id -u) = 0; then
389 echo "xorg" > /etc/X11/screen.conf
390 config_dialog
391 fi
392 wm_config
393 creat_xinitrc
394 creat_xsession ;;
395 esac
397 exit 0