slitaz-tools view tinyutils/tazx @ rev 577

tazx: fix for us-acentos
author Christophe Lincoln <pankso@slitaz.org>
date Fri Apr 29 16:21:53 2011 +0200 (2011-04-29)
parents 2b8a6ff728b5
children bac3728828c5
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.
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=tazdialog}
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 ####################
21 # Tazx functions #
22 ####################
24 # Populate xorg.conf.d.
25 xorg_conf_d()
26 {
27 # Define the xorg.conf.d (can be /etc/X11/xorg.conf.d or /usr/share/X11/xorg.conf.d)
28 xorg_config=/etc/X11/xorg.conf.d
30 # Define the xorg.conf.new place.
31 xorg_template=/root/xorg.conf.new
33 # Obtain a default configuration file from Xorg.
34 Xorg -configure :1
36 # Backup existing config.
37 tar -cf $xorg_config/../Previous_xorg.conf.d.tar $xorg_config/ &> /dev/null
39 # Put the differents sections in separate files in the configuration directory.
40 sed -e '/Section "ServerLayout"/,/EndSection/!d' -e "s/EndSection/EndSection\n/" $xorg_template | grep -v Core > $xorg_config/10-ServerLayout.conf
41 sed -e '/Section "Files"/,/EndSection/!d' -e "s/EndSection/EndSection\n/" $xorg_template > $xorg_config/20-Files.conf
42 sed -e '/Section "Module"/,/EndSection/!d' -e "s/EndSection/EndSection\n/" $xorg_template > $xorg_config/30-Module.conf
43 sed -e '/Section "Monitor"/,/EndSection/!d' -e "s/EndSection/EndSection\n/" $xorg_template > $xorg_config/50-Monitor.conf
44 sed -e '/Section "Device"/,/EndSection/!d' -e "s/EndSection/EndSection\n/" $xorg_template > $xorg_config/60-Device.conf
45 sed -e '/Section "Screen"/,/EndSection/!d' -e "s/EndSection/EndSection\n/" $xorg_template > $xorg_config/70-Screen.conf
47 # Remove the template.
48 rm $xorg_template
50 # Configure the keyboard with the right keymap.
51 keymap=`cat /etc/keymap.conf`
52 keyboard_config=$xorg_config/40-Keyboard.conf
53 echo 'Section "InputClass"
54 Identifier "Keyboard Defaults"
55 MatchIsKeyboard "yes"' > $keyboard_config
56 case $keymap in
57 fr_CH-latin1)
58 # Swiss FrenCH
59 echo ' Option "XkbLayout" "ch"
60 Option "XkbVariant" "fr"' >> $keyboard_config ;;
61 en)
62 # Englisk UK
63 echo ' Option "XkbLayout" "en"
64 Option "XkbVariant" "en"' >> $keyboard_config ;;
65 ru)
66 # Russian
67 echo ' Option "XkbLayout" "us,ru(winkeys)"
68 Option "XkbVariant" "grp:alt_shift_toggle"' >> $keyboard_config ;;
69 slovene)
70 # Slovenian
71 echo ' Option "XkbLayout" "si"
72 Option "XkbOptions" "grp:alt_shift_toggle"' >> $keyboard_config ;;
73 us-acentos)
74 echo ' Option "XkbLayout" "us"
75 Option "XkbVariant" "intl"' >> $keyboard_config ;;
76 *)
77 # Use clean /etc/keymap.conf value.
78 keymap=${keymap%-latin1}
79 keymap=${keymap%-lat2}
80 keymap=${keymap%-lat6}
81 keymap=${keymap%-abnt2}
82 echo ' Option "XkbLayout" "'$keymap\" >> $keyboard_config
83 ;;
84 esac
86 echo 'Endsection' >> $keyboard_config
88 # Create a xorg.conf if needed.
89 [ ! -f /etc/X11/xorg.conf ] && echo "# You can put here your own Xorg configurations.
90 # This configuration file is read before all files in /etc/X11/xorg.conf.d
91 # This file will not be erased by any updates." > /etc/X11/xorg.conf
92 }
94 # Install xorg server.
95 install_xorg()
96 {
97 tazpkg recharge
98 exec 3>&1
99 value=`$DIALOG --clear --colors --title " Install Xorg " \
100 --menu \
101 "The 'tazx' application helps you to select your X driver." 16 70 5 \
102 $(grep xorg-xf86-video /var/lib/tazpkg/packages.list | cut -d- -f4 | while read x; do echo $x; echo driver; done) \
103 "quit" "Quitter" \
104 2>&1 1>&3`
105 retval=$?
106 exec 3>&-
107 # Continue, exit...
108 case $retval in
109 1)
110 echo "Cancel pressed..."
111 exit 0 ;;
112 255)
113 if test -z "$value"; then
114 echo "ESC pressed..."
115 exit 0
116 fi ;;
117 esac
118 # Set selected value.
119 case $value in
120 quit)
121 echo "Quit..."
122 exit 0 ;;
123 *)
124 tazpkg get-install xorg-server
125 tazpkg get-install xorg-xf86-video-$value
126 xorg_conf_d
127 sed -i 's|/usr/bin/Xvesa|/usr/bin/Xorg|' /etc/slim.conf
128 sed -i s/"^xserver_arguments"/'\#xserver_arguments'/ /etc/slim.conf
129 XSERVER=Xorg ;;
130 esac
131 }
133 # Screen configuration dialog.
134 screen_config_dialog()
135 {
136 exec 3>&1
137 value=`$DIALOG \
138 --clear --colors \
139 --title " Configure X " \
140 --menu \
141 "The 'tazx' application helps you to configure your X session.\n\
142 Window Manager : \Z2$WM\Zn \n\
143 X server : \Z2Xorg\Zn" 16 70 5 \
144 "xorg" "Install or reconfigure Xorg" \
145 "text" "Disable X autostart" \
146 "quit" "Quit Tazx utility" \
147 2>&1 1>&3`
148 retval=$?
149 exec 3>&-
150 # Continue, exit or help...
151 case $retval in
152 0)
153 continue ;;
154 1)
155 echo "Cancel pressed..."
156 exit 0 ;;
157 255)
158 if test -n "$value"; then
159 continue
160 else
161 echo "ESC pressed..."
162 exit 0
163 fi ;;
164 esac
165 # Set selected value.
166 case $value in
167 xorg)
168 install_xorg ;;
169 text)
170 sed -i s/'slim'/''/ /etc/rcS.conf
171 exit 0 ;;
172 *)
173 continue ;;
174 esac
175 }
177 # Window manager specific configuration.
178 wm_config()
179 {
180 case $WM in
181 ob|openbox)
182 WM=openbox-session
183 # Check if a personal autostart script exists if OB is installed.
184 if [ -d "/var/lib/tazpkg/installed/openbox" ]; then
185 if [ ! -f "$HOME/.config/openbox/autostart.sh" ]; then
186 mkdir -p $HOME/.config/openbox
187 cp /etc/xdg/openbox/autostart.sh $HOME/.config/openbox
188 fi
189 # Script for default user (uid=1000).
190 if [ ! -f "/home/$USER/.config/openbox/autostart.sh" ]; then
191 mkdir -p /home/$USER/.config/openbox
192 cp /etc/xdg/openbox/autostart.sh /home/$USER/.config/openbox
193 fi
194 if [ ! -f "/home/$USER/.config/openbox/menu.xml" ]; then
195 mkdir -p /home/$USER/.config/openbox
196 cp /etc/xdg/openbox/menu.xml /home/$USER/.config/openbox
197 fi
198 chown -R $USER.users /home/$USER/.config
199 fi ;;
200 jwm)
201 WM=jwm
202 JWM_CONFIG=$HOME/.jwmrc
203 if [ -d "/var/lib/tazpkg/installed/jwm" ]; then
204 if [ ! -f "$JWM_CONFIG" ]; then
205 cp /etc/jwm/system.jwmrc $JWM_CONFIG
206 fi
207 # In Live mode default user/root JWM config does not exist and
208 # $HOME is not set, this is because tazx is executed by boot
209 # scripts.
210 if [ ! -f "/home/$USER/.jwmrc" ]; then
211 cp /etc/jwm/system.jwmrc /home/$USER/.jwmrc
212 chown $USER.users /home/$USER/.jwmrc
213 fi
214 if [ ! -f "/root/.jwmrc" -a `id -u` = 0 ]; then
215 cp /etc/jwm/system.jwmrc /root/.jwmrc
216 fi
217 fi ;;
218 pekwm)
219 WM=pekwm
220 if [ -d "/var/lib/tazpkg/installed/pekwm" ]; then
221 if [ -d "$HOME/.pekwm" ]; then
222 cp -R /etc/pekwm $HOME/.pekwm
223 fi
224 # In Live mode we want config before starting pekwm the first time.
225 if [ ! -d "/home/$USER/.pekwm" ]; then
226 cp -R /etc/pekwm /home/$USER/.pekwm
227 chown -R $USER.users /home/$USER/.pekwm
228 chmod +x /home/$USER/.pekwm/start
229 fi
230 if [ ! -d "/root/.pekwm" -a `id -u` = 0 ]; then
231 cp -R /etc/pekwm /root/.pekwm
232 chmod +x /root/.pekwm/start
233 fi
234 fi ;;
235 e17|enlightenment)
236 WM=enlightenment_start ;;
237 fluxbox)
238 WM=startfluxbox ;;
239 dwm|karmen)
240 WM=$WM-session ;;
241 awesome)
242 WM=awesome ;;
243 xfce|xfce4)
244 WM=xfce4-session ;;
245 esac
246 }
248 # Sample xinitrc for user (WM can be specified with F1 at slim login).
249 xinitrc_sample()
250 {
251 cat > $FILE << "EOF"
252 # ~/.xinitrc: Executed by slim login manager to startx X session.
253 # You can use F1 with Slim to change your window manager or configure
254 # it permanently with your personal applications.conf file.
255 #
256 . $HOME/.config/slitaz/applications.conf
258 case $1 in
259 e17|enlightenment*)
260 exec enlightenment_start ;;
261 openbox|openbox-session|ob)
262 exec openbox-session ;;
263 dwm|dwm-session)
264 exec dwm-session ;;
265 fluxbox|startfluxbox)
266 exec startfluxbox ;;
267 awesome)
268 exec awesome ;;
269 pekwm)
270 exec pekwm ;;
271 karmen|karmen-session)
272 exec karmen-session ;;
273 jwm)
274 lxpanel &
275 exec jwm ;;
276 xfce|xfce4|xfce4-session)
277 xfce4-session ;;
278 *)
279 exec $WINDOW_MANAGER ;;
280 esac
281 EOF
282 # Set default WM in applications.conf user file. Default WM can be
283 # configured graphically with 'desktopbox tazapps'
284 . $CONFIG
285 sed -i s/"WINDOW_MANAGER=.*"/"WINDOW_MANAGER=\"$WM\""/ \
286 $CONFIG
287 }
289 # ~/.xinitrc for X login from a DM.
290 creat_xinitrc()
291 {
292 FILE=$HOME/.xinitrc
293 CONFIG=$HOME/.config/slitaz/applications.conf
294 if [ ! -f $CONFIG ]; then
295 mkdir -p $HOME/.config/slitaz
296 cp /etc/slitaz/applications.conf $CONFIG
297 fi
298 xinitrc_sample
299 # .xinitrc and config for /etc/skel so new added user will get
300 # a working X session.
301 if test $(id -u) = 0; then
302 FILE=/etc/skel/.xinitrc
303 CONFIG=/etc/skel/.config/slitaz/applications.conf
304 mkdir -p /etc/skel/.config/slitaz
305 cp -f /etc/slitaz/applications.conf $CONFIG
306 xinitrc_sample
307 fi
308 # In Live mode default user needs a xinitrc, since tazx
309 # is executed only by root.
310 CONFIG=/home/$USER/.config/slitaz/applications.conf
311 if [ ! -f $CONFIG ]; then
312 mkdir -p /home/$USER/.config/slitaz
313 cp /etc/slitaz/applications.conf $CONFIG
314 fi
315 chown -R $USER.users /home/$USER/.config/slitaz
316 if [ ! -f /home/$USER/.xinitrc ]; then
317 FILE=/home/$USER/.xinitrc
318 xinitrc_sample
319 chown $USER.users $FILE
320 fi
321 }
323 # Create ~/.xsession to keep the configuration selected (used
324 # only by startx, Slim login manager uses .xinitrc).
325 creat_xsession()
326 {
327 [ -f $HOME/.xsession ] && cp -f $HOME/.xsession $HOME/.previous_xsession
328 cat > $HOME/.xsession << _EOF_
329 # ~/.xsession: Start X window session manually on your system (startx).
330 #
331 Xorg &
332 #xterm &
333 _EOF_
334 # LXpanel by default with JWM.
335 if [ "$WM" = "jwm" ]; then
336 echo 'lxpanel &' >> $HOME/.xsession
337 fi
338 echo "exec $WM" >> $HOME/.xsession
339 chmod 700 $HOME/.xsession
340 }
342 ###################
343 # Tazx sequence #
344 ###################
346 case "$1" in
347 install-xorg)
348 # WM can be specified on cmdline.
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 # WM can be specified on cmdline.
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 # WM can be specified on cmdline.
374 if [ -n "$1" ]; then
375 WM=$1
376 fi
377 # User can get a new .xinitrc with tazx from cmdline.
378 if test $(id -u) = 0; then
379 echo "xorg" > /etc/X11/screen.conf
380 screen_config_dialog
381 fi
382 wm_config
383 creat_xinitrc
384 creat_xsession ;;
385 esac
387 exit 0