slitaz-tools view tinyutils/tazx @ rev 626

tazx: start clean-up and gettextization, fix setmixer TEXTDOMAIN
author Christophe Lincoln <pankso@slitaz.org>
date Tue Jun 14 22:52:41 2011 +0200 (2011-06-14)
parents cc4df6554e18
children b8be57e0e90b
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 # Functions
27 # Be sure we're root.
28 check_root() {
29 [ $(id -u) != 0 ] && gettext -e "\nYou must be root to configure x.\n\n" && exit 0
30 }
32 # Populate xorg.conf.d.
33 xorg_conf_d()
34 {
35 # Define the xorg.conf.d (can be /etc/X11/xorg.conf.d or /usr/share/X11/xorg.conf.d)
36 xorg_config=/etc/X11/xorg.conf.d
38 # Define the xorg.conf.new place.
39 xorg_template=/root/xorg.conf.new
41 # Obtain a default configuration file from Xorg.
42 Xorg -configure :1
44 # Backup existing config.
45 tar -cf $xorg_config/../Previous_xorg.conf.d.tar $xorg_config/ &> /dev/null
47 # Put the differents sections in separate files in the configuration directory.
48 sed -e '/Section "ServerLayout"/,/EndSection/!d' -e "s/EndSection/EndSection\n/" $xorg_template | grep -v Core > $xorg_config/10-ServerLayout.conf
49 sed -e '/Section "Files"/,/EndSection/!d' -e "s/EndSection/EndSection\n/" $xorg_template > $xorg_config/20-Files.conf
50 sed -e '/Section "Module"/,/EndSection/!d' -e "s/EndSection/EndSection\n/" $xorg_template > $xorg_config/30-Module.conf
51 sed -e '/Section "Monitor"/,/EndSection/!d' -e "s/EndSection/EndSection\n/" $xorg_template > $xorg_config/50-Monitor.conf
52 sed -e '/Section "Device"/,/EndSection/!d' -e "s/EndSection/EndSection\n/" $xorg_template > $xorg_config/60-Device.conf
53 sed -e '/Section "Screen"/,/EndSection/!d' -e "s/EndSection/EndSection\n/" $xorg_template > $xorg_config/70-Screen.conf
55 # Remove the template.
56 rm $xorg_template
58 # Configure the keyboard with the right keymap.
59 keymap=`cat /etc/keymap.conf`
60 keyboard_config=$xorg_config/40-Keyboard.conf
61 echo 'Section "InputClass"
62 Identifier "Keyboard Defaults"
63 MatchIsKeyboard "yes"' > $keyboard_config
64 case $keymap in
65 fr_CH-latin1)
66 # Swiss FrenCH
67 echo ' Option "XkbLayout" "ch"
68 Option "XkbVariant" "fr"' >> $keyboard_config ;;
69 uk)
70 # English UK
71 echo ' Option "XkbLayout" "gb"' >> $keyboard_config ;;
72 ru)
73 # Russian
74 echo ' Option "XkbLayout" "us,ru(winkeys)"
75 Option "XkbVariant" "grp:alt_shift_toggle"' >> $keyboard_config ;;
76 slovene)
77 # Slovenian
78 echo ' Option "XkbLayout" "si"
79 Option "XkbOptions" "grp:alt_shift_toggle"' >> $keyboard_config ;;
80 us-acentos)
81 echo ' Option "XkbLayout" "us"
82 Option "XkbVariant" "intl"' >> $keyboard_config ;;
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 echo ' Option "XkbLayout" "'$keymap\" >> $keyboard_config
90 ;;
91 esac
93 echo 'Endsection' >> $keyboard_config
95 # Create a xorg.conf if needed.
96 [ ! -f /etc/X11/xorg.conf ] && echo "# You can put here your own Xorg configurations.
97 # This configuration file is read before all files in /etc/X11/xorg.conf.d
98 # This file will not be erased by any updates." > /etc/X11/xorg.conf
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 "The 'tazx' application helps you to select your X driver." 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_conf_d
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 Xorg.\n\
147 Window Manager : \Z2$WM\Zn \n\
148 X server : \Z2Xorg\Zn" 16 70 5 \
149 "xorg" "Install or reconfigure Xorg" \
150 "quit" "Quit Tazx utility" \
151 2>&1 1>&3`
152 retval=$?
153 exec 3>&-
154 # Continue, exit or help...
155 case $retval in
156 0)
157 continue ;;
158 1)
159 echo "Cancel pressed..."
160 exit 0 ;;
161 255)
162 if test -n "$value"; then
163 continue
164 else
165 echo "ESC pressed..."
166 exit 0
167 fi ;;
168 esac
169 # Set selected value.
170 case $value in
171 xorg)
172 install_xorg ;;
173 *)
174 continue ;;
175 esac
176 }
178 # Window manager specific configuration.
179 wm_config()
180 {
181 case $WM in
182 ob|openbox)
183 WM=openbox-session
184 # Check if a personal autostart script exists if OB is installed.
185 if [ -d "/var/lib/tazpkg/installed/openbox" ]; then
186 if [ ! -f "$HOME/.config/openbox/autostart.sh" ]; then
187 mkdir -p $HOME/.config/openbox
188 cp /etc/xdg/openbox/autostart.sh $HOME/.config/openbox
189 fi
190 # Script for default user (uid=1000).
191 if [ ! -f "/home/$USER/.config/openbox/autostart.sh" ]; then
192 mkdir -p /home/$USER/.config/openbox
193 cp /etc/xdg/openbox/autostart.sh /home/$USER/.config/openbox
194 fi
195 if [ ! -f "/home/$USER/.config/openbox/menu.xml" ]; then
196 mkdir -p /home/$USER/.config/openbox
197 cp /etc/xdg/openbox/menu.xml /home/$USER/.config/openbox
198 fi
199 chown -R $USER.users /home/$USER/.config
200 fi ;;
201 jwm)
202 WM=jwm
203 JWM_CONFIG=$HOME/.jwmrc
204 if [ -d "/var/lib/tazpkg/installed/jwm" ]; then
205 if [ ! -f "$JWM_CONFIG" ]; then
206 cp /etc/jwm/system.jwmrc $JWM_CONFIG
207 fi
208 # In Live mode default user/root JWM config does not exist and
209 # $HOME is not set, this is because tazx is executed by boot
210 # scripts.
211 if [ ! -f "/home/$USER/.jwmrc" ]; then
212 cp /etc/jwm/system.jwmrc /home/$USER/.jwmrc
213 chown $USER.users /home/$USER/.jwmrc
214 fi
215 if [ ! -f "/root/.jwmrc" -a `id -u` = 0 ]; then
216 cp /etc/jwm/system.jwmrc /root/.jwmrc
217 fi
218 fi ;;
219 pekwm)
220 WM=pekwm
221 if [ -d "/var/lib/tazpkg/installed/pekwm" ]; then
222 if [ -d "$HOME/.pekwm" ]; then
223 cp -R /etc/pekwm $HOME/.pekwm
224 fi
225 # In Live mode we want config before starting pekwm the first time.
226 if [ ! -d "/home/$USER/.pekwm" ]; then
227 cp -R /etc/pekwm /home/$USER/.pekwm
228 chown -R $USER.users /home/$USER/.pekwm
229 chmod +x /home/$USER/.pekwm/start
230 fi
231 if [ ! -d "/root/.pekwm" -a `id -u` = 0 ]; then
232 cp -R /etc/pekwm /root/.pekwm
233 chmod +x /root/.pekwm/start
234 fi
235 fi ;;
236 e17|enlightenment)
237 WM=enlightenment_start ;;
238 fluxbox)
239 WM=startfluxbox ;;
240 dwm|karmen)
241 WM=$WM-session ;;
242 awesome)
243 WM=awesome ;;
244 xfce|xfce4)
245 WM=xfce4-session ;;
246 esac
247 }
249 # Sample xinitrc for user (WM can be specified with F1 at slim login).
250 xinitrc_sample()
251 {
252 cat > $FILE << "EOF"
253 # ~/.xinitrc: Executed by slim login manager to startx X session.
254 # You can use F1 with Slim to change your window manager or configure
255 # it permanently with your personal applications.conf file.
256 #
257 . $HOME/.config/slitaz/applications.conf
259 case $1 in
260 e17|enlightenment*)
261 exec enlightenment_start ;;
262 openbox|openbox-session|ob)
263 exec openbox-session ;;
264 dwm|dwm-session)
265 exec dwm-session ;;
266 fluxbox|startfluxbox)
267 exec startfluxbox ;;
268 awesome)
269 exec awesome ;;
270 pekwm)
271 exec pekwm ;;
272 karmen|karmen-session)
273 exec karmen-session ;;
274 jwm)
275 lxpanel &
276 exec jwm ;;
277 xfce|xfce4|xfce4-session)
278 xfce4-session ;;
279 *)
280 exec $WINDOW_MANAGER ;;
281 esac
282 EOF
283 # Set default WM in applications.conf user file. Default WM can be
284 # configured graphically with 'desktopbox tazapps'
285 . $CONFIG
286 sed -i s/"WINDOW_MANAGER=.*"/"WINDOW_MANAGER=\"$WM\""/ \
287 $CONFIG
288 }
290 # ~/.xinitrc for X login from a DM.
291 creat_xinitrc()
292 {
293 FILE=$HOME/.xinitrc
294 CONFIG=$HOME/.config/slitaz/applications.conf
295 if [ ! -f $CONFIG ]; then
296 mkdir -p $HOME/.config/slitaz
297 cp /etc/slitaz/applications.conf $CONFIG
298 fi
299 xinitrc_sample
300 # .xinitrc and config for /etc/skel so new added user will get
301 # a working X session.
302 if test $(id -u) = 0; then
303 FILE=/etc/skel/.xinitrc
304 CONFIG=/etc/skel/.config/slitaz/applications.conf
305 mkdir -p /etc/skel/.config/slitaz
306 cp -f /etc/slitaz/applications.conf $CONFIG
307 xinitrc_sample
308 fi
309 # In Live mode default user needs a xinitrc, since tazx
310 # is executed only by root.
311 CONFIG=/home/$USER/.config/slitaz/applications.conf
312 if [ ! -f $CONFIG ]; then
313 mkdir -p /home/$USER/.config/slitaz
314 cp /etc/slitaz/applications.conf $CONFIG
315 fi
316 chown -R $USER.users /home/$USER/.config/slitaz
317 if [ ! -f /home/$USER/.xinitrc ]; then
318 FILE=/home/$USER/.xinitrc
319 xinitrc_sample
320 chown $USER.users $FILE
321 fi
322 }
324 # Create ~/.xsession to keep the configuration selected (used
325 # only by startx, Slim login manager uses .xinitrc).
326 creat_xsession()
327 {
328 [ -f $HOME/.xsession ] && cp -f $HOME/.xsession $HOME/.previous_xsession
329 cat > $HOME/.xsession << _EOF_
330 # ~/.xsession: Start X window session manually on your system (startx).
331 #
332 Xorg &
333 #xterm &
334 _EOF_
335 # LXpanel by default with JWM.
336 if [ "$WM" = "jwm" ]; then
337 echo 'lxpanel &' >> $HOME/.xsession
338 fi
339 echo "exec $WM" >> $HOME/.xsession
340 chmod 700 $HOME/.xsession
341 }
344 # Commands - WM can be specified on cmdline.
346 case "$1" in
347 install-xorg)
348 check_root
349 if [ -n "$2" ]; then
350 WM=$2
351 fi
352 echo "xorg" > /etc/X11/screen.conf
353 install_xorg
354 wm_config
355 creat_xinitrc
356 creat_xsession ;;
357 config-xorg)
358 check_root
359 if [ -n "$2" ]; then
360 WM=$2
361 fi
362 echo "xorg" > /etc/X11/screen.conf
363 wm_config
364 creat_xinitrc
365 creat_xsession
366 xorg_conf_d
367 if grep -qs screen= /proc/cmdline ; then
368 MODE="$(sed 's/.*screen=\([0-9]*x[0-9]*\).*/\1/' < /proc/cmdline)"
369 sed -i "s/.*EndSubSection.*/\\t\\tModes\\t\"$MODE\"\\n&/" \
370 /etc/X11/xorg.conf.d/70-Screen.conf
371 fi ;;
372 *)
373 # User can get a new .xinitrc with tazx from cmdline.
374 if [ -n "$1" ]; then
375 WM=$1
376 fi
377 if test $(id -u) = 0; then
378 echo "xorg" > /etc/X11/screen.conf
379 screen_config_dialog
380 fi
381 wm_config
382 creat_xinitrc
383 creat_xsession ;;
384 esac
386 exit 0