slitaz-tools view tinyutils/tazx @ rev 597

tazx: fix English Uk keyboard
author Christophe Lincoln <pankso@slitaz.org>
date Tue May 17 00:22:35 2011 +0200 (2011-05-17)
parents bac3728828c5
children 41d4c6ddf3c8
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 uk)
62 # Englisk UK
63 echo ' Option "XkbLayout" "gb"' >> $keyboard_config ;;
64 ru)
65 # Russian
66 echo ' Option "XkbLayout" "us,ru(winkeys)"
67 Option "XkbVariant" "grp:alt_shift_toggle"' >> $keyboard_config ;;
68 slovene)
69 # Slovenian
70 echo ' Option "XkbLayout" "si"
71 Option "XkbOptions" "grp:alt_shift_toggle"' >> $keyboard_config ;;
72 us-acentos)
73 echo ' Option "XkbLayout" "us"
74 Option "XkbVariant" "intl"' >> $keyboard_config ;;
75 *)
76 # Use clean /etc/keymap.conf value.
77 keymap=${keymap%-latin1}
78 keymap=${keymap%-lat2}
79 keymap=${keymap%-lat6}
80 keymap=${keymap%-abnt2}
81 echo ' Option "XkbLayout" "'$keymap\" >> $keyboard_config
82 ;;
83 esac
85 echo 'Endsection' >> $keyboard_config
87 # Create a xorg.conf if needed.
88 [ ! -f /etc/X11/xorg.conf ] && echo "# You can put here your own Xorg configurations.
89 # This configuration file is read before all files in /etc/X11/xorg.conf.d
90 # This file will not be erased by any updates." > /etc/X11/xorg.conf
91 }
93 # Install xorg server.
94 install_xorg()
95 {
96 tazpkg recharge
97 exec 3>&1
98 value=`$DIALOG --clear --colors --title " Install Xorg " \
99 --menu \
100 "The 'tazx' application helps you to select your X driver." 16 70 5 \
101 $(grep xorg-xf86-video /var/lib/tazpkg/packages.list | cut -d- -f4 | while read x; do echo $x; echo driver; done) \
102 "quit" "Quitter" \
103 2>&1 1>&3`
104 retval=$?
105 exec 3>&-
106 # Continue, exit...
107 case $retval in
108 1)
109 echo "Cancel pressed..."
110 exit 0 ;;
111 255)
112 if test -z "$value"; then
113 echo "ESC pressed..."
114 exit 0
115 fi ;;
116 esac
117 # Set selected value.
118 case $value in
119 quit)
120 echo "Quit..."
121 exit 0 ;;
122 *)
123 tazpkg get-install xorg-server
124 tazpkg get-install xorg-xf86-video-$value
125 xorg_conf_d
126 XSERVER=Xorg ;;
127 esac
128 }
130 # Screen configuration dialog.
131 screen_config_dialog()
132 {
133 exec 3>&1
134 value=`$DIALOG \
135 --clear --colors \
136 --title " Configure X " \
137 --menu \
138 "The 'tazx' application helps you to configure your Xorg.\n\
139 Window Manager : \Z2$WM\Zn \n\
140 X server : \Z2Xorg\Zn" 16 70 5 \
141 "xorg" "Install or reconfigure Xorg" \
142 "quit" "Quit Tazx utility" \
143 2>&1 1>&3`
144 retval=$?
145 exec 3>&-
146 # Continue, exit or help...
147 case $retval in
148 0)
149 continue ;;
150 1)
151 echo "Cancel pressed..."
152 exit 0 ;;
153 255)
154 if test -n "$value"; then
155 continue
156 else
157 echo "ESC pressed..."
158 exit 0
159 fi ;;
160 esac
161 # Set selected value.
162 case $value in
163 xorg)
164 install_xorg ;;
165 *)
166 continue ;;
167 esac
168 }
170 # Window manager specific configuration.
171 wm_config()
172 {
173 case $WM in
174 ob|openbox)
175 WM=openbox-session
176 # Check if a personal autostart script exists if OB is installed.
177 if [ -d "/var/lib/tazpkg/installed/openbox" ]; then
178 if [ ! -f "$HOME/.config/openbox/autostart.sh" ]; then
179 mkdir -p $HOME/.config/openbox
180 cp /etc/xdg/openbox/autostart.sh $HOME/.config/openbox
181 fi
182 # Script for default user (uid=1000).
183 if [ ! -f "/home/$USER/.config/openbox/autostart.sh" ]; then
184 mkdir -p /home/$USER/.config/openbox
185 cp /etc/xdg/openbox/autostart.sh /home/$USER/.config/openbox
186 fi
187 if [ ! -f "/home/$USER/.config/openbox/menu.xml" ]; then
188 mkdir -p /home/$USER/.config/openbox
189 cp /etc/xdg/openbox/menu.xml /home/$USER/.config/openbox
190 fi
191 chown -R $USER.users /home/$USER/.config
192 fi ;;
193 jwm)
194 WM=jwm
195 JWM_CONFIG=$HOME/.jwmrc
196 if [ -d "/var/lib/tazpkg/installed/jwm" ]; then
197 if [ ! -f "$JWM_CONFIG" ]; then
198 cp /etc/jwm/system.jwmrc $JWM_CONFIG
199 fi
200 # In Live mode default user/root JWM config does not exist and
201 # $HOME is not set, this is because tazx is executed by boot
202 # scripts.
203 if [ ! -f "/home/$USER/.jwmrc" ]; then
204 cp /etc/jwm/system.jwmrc /home/$USER/.jwmrc
205 chown $USER.users /home/$USER/.jwmrc
206 fi
207 if [ ! -f "/root/.jwmrc" -a `id -u` = 0 ]; then
208 cp /etc/jwm/system.jwmrc /root/.jwmrc
209 fi
210 fi ;;
211 pekwm)
212 WM=pekwm
213 if [ -d "/var/lib/tazpkg/installed/pekwm" ]; then
214 if [ -d "$HOME/.pekwm" ]; then
215 cp -R /etc/pekwm $HOME/.pekwm
216 fi
217 # In Live mode we want config before starting pekwm the first time.
218 if [ ! -d "/home/$USER/.pekwm" ]; then
219 cp -R /etc/pekwm /home/$USER/.pekwm
220 chown -R $USER.users /home/$USER/.pekwm
221 chmod +x /home/$USER/.pekwm/start
222 fi
223 if [ ! -d "/root/.pekwm" -a `id -u` = 0 ]; then
224 cp -R /etc/pekwm /root/.pekwm
225 chmod +x /root/.pekwm/start
226 fi
227 fi ;;
228 e17|enlightenment)
229 WM=enlightenment_start ;;
230 fluxbox)
231 WM=startfluxbox ;;
232 dwm|karmen)
233 WM=$WM-session ;;
234 awesome)
235 WM=awesome ;;
236 xfce|xfce4)
237 WM=xfce4-session ;;
238 esac
239 }
241 # Sample xinitrc for user (WM can be specified with F1 at slim login).
242 xinitrc_sample()
243 {
244 cat > $FILE << "EOF"
245 # ~/.xinitrc: Executed by slim login manager to startx X session.
246 # You can use F1 with Slim to change your window manager or configure
247 # it permanently with your personal applications.conf file.
248 #
249 . $HOME/.config/slitaz/applications.conf
251 case $1 in
252 e17|enlightenment*)
253 exec enlightenment_start ;;
254 openbox|openbox-session|ob)
255 exec openbox-session ;;
256 dwm|dwm-session)
257 exec dwm-session ;;
258 fluxbox|startfluxbox)
259 exec startfluxbox ;;
260 awesome)
261 exec awesome ;;
262 pekwm)
263 exec pekwm ;;
264 karmen|karmen-session)
265 exec karmen-session ;;
266 jwm)
267 lxpanel &
268 exec jwm ;;
269 xfce|xfce4|xfce4-session)
270 xfce4-session ;;
271 *)
272 exec $WINDOW_MANAGER ;;
273 esac
274 EOF
275 # Set default WM in applications.conf user file. Default WM can be
276 # configured graphically with 'desktopbox tazapps'
277 . $CONFIG
278 sed -i s/"WINDOW_MANAGER=.*"/"WINDOW_MANAGER=\"$WM\""/ \
279 $CONFIG
280 }
282 # ~/.xinitrc for X login from a DM.
283 creat_xinitrc()
284 {
285 FILE=$HOME/.xinitrc
286 CONFIG=$HOME/.config/slitaz/applications.conf
287 if [ ! -f $CONFIG ]; then
288 mkdir -p $HOME/.config/slitaz
289 cp /etc/slitaz/applications.conf $CONFIG
290 fi
291 xinitrc_sample
292 # .xinitrc and config for /etc/skel so new added user will get
293 # a working X session.
294 if test $(id -u) = 0; then
295 FILE=/etc/skel/.xinitrc
296 CONFIG=/etc/skel/.config/slitaz/applications.conf
297 mkdir -p /etc/skel/.config/slitaz
298 cp -f /etc/slitaz/applications.conf $CONFIG
299 xinitrc_sample
300 fi
301 # In Live mode default user needs a xinitrc, since tazx
302 # is executed only by root.
303 CONFIG=/home/$USER/.config/slitaz/applications.conf
304 if [ ! -f $CONFIG ]; then
305 mkdir -p /home/$USER/.config/slitaz
306 cp /etc/slitaz/applications.conf $CONFIG
307 fi
308 chown -R $USER.users /home/$USER/.config/slitaz
309 if [ ! -f /home/$USER/.xinitrc ]; then
310 FILE=/home/$USER/.xinitrc
311 xinitrc_sample
312 chown $USER.users $FILE
313 fi
314 }
316 # Create ~/.xsession to keep the configuration selected (used
317 # only by startx, Slim login manager uses .xinitrc).
318 creat_xsession()
319 {
320 [ -f $HOME/.xsession ] && cp -f $HOME/.xsession $HOME/.previous_xsession
321 cat > $HOME/.xsession << _EOF_
322 # ~/.xsession: Start X window session manually on your system (startx).
323 #
324 Xorg &
325 #xterm &
326 _EOF_
327 # LXpanel by default with JWM.
328 if [ "$WM" = "jwm" ]; then
329 echo 'lxpanel &' >> $HOME/.xsession
330 fi
331 echo "exec $WM" >> $HOME/.xsession
332 chmod 700 $HOME/.xsession
333 }
335 ###################
336 # Tazx sequence #
337 ###################
339 case "$1" in
340 install-xorg)
341 # WM can be specified on cmdline.
342 if [ -n "$2" ]; then
343 WM=$2
344 fi
345 echo "xorg" > /etc/X11/screen.conf
346 install_xorg
347 wm_config
348 creat_xinitrc
349 creat_xsession ;;
350 config-xorg)
351 # WM can be specified on cmdline.
352 if [ -n "$2" ]; then
353 WM=$2
354 fi
355 echo "xorg" > /etc/X11/screen.conf
356 wm_config
357 creat_xinitrc
358 creat_xsession
359 xorg_conf_d
360 if grep -qs screen= /proc/cmdline ; then
361 MODE="$(sed 's/.*screen=\([0-9]*x[0-9]*\).*/\1/' < /proc/cmdline)"
362 sed -i "s/.*EndSubSection.*/\\t\\tModes\\t\"$MODE\"\\n&/" \
363 /etc/X11/xorg.conf.d/70-Screen.conf
364 fi ;;
365 *)
366 # WM can be specified on cmdline.
367 if [ -n "$1" ]; then
368 WM=$1
369 fi
370 # User can get a new .xinitrc with tazx from cmdline.
371 if test $(id -u) = 0; then
372 echo "xorg" > /etc/X11/screen.conf
373 screen_config_dialog
374 fi
375 wm_config
376 creat_xinitrc
377 creat_xsession ;;
378 esac
380 exit 0