slitaz-tools view tinyutils/tazx @ rev 260

tazx: Fix and improve xorg keymap patch
author Christophe Lincoln <pankso@slitaz.org>
date Mon Jul 21 00:12:50 2008 +0200 (2008-07-21)
parents db0e82bebc70
children 810c4042b710
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.
5 #
6 # (c) 20080609 SliTaz GNU/Linux - GNU gpl v3.
7 # Authors: Christophe Lincoln <pankso@slitaz.org>
8 # Pascal Bellard <pascal.bellard@slitaz.org>
9 #
10 : ${DIALOG=tazdialog}
12 # Variables.
13 #
14 XSERVER=Xvesa
15 DOC=/usr/share/doc/slitaz-tools/tazx.txt
16 MOUSE=/dev/input/mice,5
17 # WM can be specified on cmdline.
18 if [ -n "$1" ]; then
19 WM=$1
20 else
21 WM=openbox
22 fi
23 # Default user for config files
24 USER=`cat /etc/passwd | grep 1000 | cut -d ":" -f 1`
26 ####################
27 # Tazx functions #
28 ####################
30 # Patch xorg.conf to set keymap layout.
31 patch_xorg_kbd()
32 {
33 KEYMAP=`cat /etc/keymap.conf`
34 case $KEYMAP in
35 fr_CH-latin1)
36 # Swiss FrenCH
37 patch -p0 <<EOF
38 --- /etc/X11/xorg.conf
39 +++ /etc/X11/xorg.conf
40 @@ -30,2 +30,3 @@
41 Driver "kbd"
42 + Option "XkbLayout" "ch"
43 + Option "XkbVariant" "fr"
44 EndSection
45 EOF
46 ;;
47 en)
48 # Englisk UK
49 patch -p0 <<EOF
50 --- /etc/X11/xorg.conf
51 +++ /etc/X11/xorg.conf
52 @@ -30,2 +30,3 @@
53 Driver "kbd"
54 + Option "XkbLayout" "en"
55 + Option "XkbVariant" "en"
56 EndSection
57 EOF
58 ;;
59 ru)
60 # Russian
61 patch -p0 <<EOF
62 --- /etc/X11/xorg.conf
63 +++ /etc/X11/xorg.conf
64 @@ -30,2 +30,3 @@
65 Driver "kbd"
66 + Option "XkbLayout" "us,ru(winkeys)"
67 + Option "XkbVariant" "grp:alt_shift_toggle"
68 EndSection
69 EOF
70 ;;
71 *)
72 # Use clean /etc/keymap.conf value.
73 KEYMAP=${KEYMAP%-latin1}
74 KEYMAP=${KEYMAP%-lat2}
75 KEYMAP=${KEYMAP%-lat6}
76 KEYMAP=${KEYMAP%-abnt2}
77 patch -p0 <<EOF
78 --- /etc/X11/xorg.conf
79 +++ /etc/X11/xorg.conf
80 @@ -30,2 +30,3 @@
81 Driver "kbd"
82 + Option "XkbLayout" "$KEYMAP"
83 EndSection
84 EOF
85 ;;
86 esac
87 }
89 # Install xorg server
90 install_xorg()
91 {
92 tazpkg recharge
93 exec 3>&1
94 value=`$DIALOG --clear --colors --title " Install Xorg " \
95 --menu \
96 "L'application 'tazx' permet de configurer le driver X." 16 70 5 \
97 $(grep xorg-xf86-video /var/lib/tazpkg/packages.list | cut -d- -f4 | while read x; do echo $x; echo driver; done) \
98 "quit" "Quitter" \
99 2>&1 1>&3`
100 retval=$?
101 exec 3>&-
102 # Continue, exit...
103 case $retval in
104 1)
105 echo "Cancel pressed..."
106 exit 0 ;;
107 255)
108 if test -z "$value"; then
109 echo "ESC pressed..."
110 exit 0
111 fi ;;
112 esac
113 # Set selected value.
114 case $value in
115 quit)
116 echo "Quit..."
117 exit 0 ;;
118 *)
119 tazpkg get-install xorg-server
120 tazpkg get-install xorg-xf86-video-$value
121 Xorg -configure :1
122 mv /root/xorg.conf.new /etc/X11/xorg.conf
123 patch_xorg_kbd
124 sed -i 's|/usr/bin/Xvesa|/usr/bin/Xorg|' /etc/slim.conf
125 sed -i s/"^xserver_arguments"/'\#xserver_arguments'/ /etc/slim.conf
126 XSERVER=Xorg;;
127 esac
128 }
130 # Screen configuration dialog.
131 screen_config_dialog()
132 {
133 exec 3>&1
134 value=`$DIALOG --help-button \
135 --clear --colors \
136 --title " Configure X " \
137 --menu \
138 "L'application 'tazx' permet de configurer une session X.\n\
139 Gestionnaire de fenêtres : \Z2$WM\Zn" 16 70 5 \
140 $(Xvesa -listmodes 2>&1 | grep ^0x | awk '{ printf "%s %s\n",$2,$3 }' | sort -nr | grep x[1-2][4-6]) \
141 "xterm" "800x600x16" \
142 "xorg" "Installer Xorg" \
143 "quit" "Quitter" \
144 2>&1 1>&3`
145 retval=$?
146 exec 3>&-
147 # Continue, exit or help...
148 case $retval in
149 0)
150 continue ;;
151 1)
152 echo "Cancel pressed..."
153 exit 0 ;;
154 2)
155 $DIALOG --clear \
156 --title " Aide - Help " --textbox "$DOC" 16 70
157 exec tazx ;;
158 255)
159 if test -n "$value"; then
160 continue
161 else
162 echo "ESC pressed..."
163 exit 0
164 fi ;;
165 esac
166 # Set selected value.
167 case $value in
168 xorg)
169 install_xorg;;
170 xterm)
171 Xvesa -ac -shadow -screen 800x600x16 -br &
172 exec xterm -cr orange -geometry 80x35+0-0 ;;
173 *)
174 NEW_SCREEN=$value ;;
175 esac
176 }
178 # Slim config if root.
179 slim_config()
180 {
181 if test $(id -u) = 0; then
182 # /etc/X11/screen.conf exist for Live mode, if this file dos not
183 # exist tazx is executed at boot time.
184 mkdir -p /etc/X11
185 echo "SCREEN=$NEW_SCREEN" > /etc/X11/screen.conf
186 # Get current screen size and sed config file with the new value.
187 if [ -f /etc/slim.conf ]; then
188 RES=$(grep ^xserver_arguments /etc/slim.conf | sed 's/xserver_arguments.*-screen *//')
189 sed -i "s/\(xserver_arguments.*-screen\).*/\1 $NEW_SCREEN/" /etc/slim.conf
190 fi
191 JWM_CONFIG=/etc/jwm/system.jwmrc
192 fi
193 }
195 # e17 start with enlightenment_start.
196 e17_stuff()
197 {
198 if [ "$WM" == "e17" ]; then
199 WM=enlightenment_start
200 XSEVER_OPTS="dpms -terminate"
201 fi
202 }
204 # Openbox with openbox-session.
205 openbox_stuff()
206 {
207 if [ "$WM" == "openbox" -o "$WM" == "ob" ]; then
208 WM=openbox-session
209 XSEVER_OPTS="dpms +extension Composite"
210 fi
211 # Check if a personal autostart script exists if OB is installed.
212 if [ -d "/var/lib/tazpkg/installed/openbox" ]; then
213 if [ ! -f "$HOME/.config/openbox/autostart.sh" ]; then
214 mkdir -p $HOME/.config/openbox
215 cp /etc/xdg/openbox/autostart.sh $HOME/.config/openbox
216 fi
217 # Script for default user (uid=1000).
218 if [ ! -f "/home/$USER/.config/openbox/autostart.sh" ]; then
219 mkdir -p /home/$USER/.config/openbox
220 cp /etc/xdg/openbox/autostart.sh /home/$USER/.config/openbox
221 fi
222 if [ ! -f "/home/$USER/.config/openbox/menu.xml" ]; then
223 mkdir -p /home/$USER/.config/openbox
224 cp /etc/xdg/openbox/menu.xml /home/$USER/.config/openbox
225 fi
226 chown -R $USER.$USER /home/$USER/.config
227 fi
228 }
230 # Sample xinitrc for user (WM can be specified with F1 at slim login).
231 xinitrc_sample()
232 {
233 cat > $FILE << "EOF"
234 # ~/.xinitrc: Executed by slim login manager to startx X session.
235 # You can use F1 with Slim or 'tazx' to configure permanantly
236 # your default WM: tazx e17
237 #
238 WM=openbox-session
240 case $1 in
241 e17|enlightenment_start)
242 exec enlightenment_start
243 ;;
244 openbox|openbox-session|ob)
245 exec openbox-session
246 ;;
247 jwm)
248 lxpanel &
249 exec jwm
250 ;;
251 *)
252 exec $WM
253 ;;
254 esac
255 EOF
256 # Set default WM.
257 RES=`grep ^WM=[e-o] $FILE`
258 sed -i s/"$RES"/"WM=$WM"/ $FILE
259 }
261 # ~/.xinitrc for slim login.
262 creat_xinitrc()
263 {
264 FILE=$HOME/.xinitrc
265 xinitrc_sample
267 # In Live mode default user needs a xinitrc, since tazx
268 # is executed only by root.
269 if [ ! -f /home/$USER/.xinitrc ]; then
270 FILE=/home/$USER/.xinitrc
271 xinitrc_sample
272 chown $USER.$USER $FILE
273 fi
274 }
276 # Copy a JWM system config if any present in user home.
277 jwm_config()
278 {
279 if [ -d "/var/lib/tazpkg/installed/jwm" ]; then
280 JWM_CONFIG=$HOME/.jwmrc
281 if [ ! -f "$JWM_CONFIG" ]; then
282 cp /etc/jwm/system.jwmrc $JWM_CONFIG
283 fi
284 # In Live mode default user/root JWM config dose not exist and
285 # $HOME is ot set, this is because tazx is executed by boot
286 # scripts.
287 if [ ! -f "/home/$USER/.jwmrc" ]; then
288 JWM_CONFIG=/home/$USER/.jwmrc
289 cp /etc/jwm/system.jwmrc $JWM_CONFIG
290 chown $USER.$USER $JWM_CONFIG
291 fi
292 if [ ! -f "/root/.jwmrc" -a `id -u` = 0 ]; then
293 JWM_CONFIG=/root/.jwmrc
294 cp /etc/jwm/system.jwmrc $JWM_CONFIG
295 fi
296 fi
297 }
299 # Create ~/.xsession to keep the configuration selected (used
300 # only by startx, Slim login manager uses .xinitrc).
301 creat_xsession()
302 {
303 cat > $HOME/.xsession << _EOF_
304 # ~/.xsession: Start X window session manually on your system (startx).
305 #
306 _EOF_
307 if [ "$XSERVER " == "Xorg" ]; then
308 echo 'Xorg &' >> $HOME/.xsession
309 else
310 echo "$XSERVER -ac -shadow $XSEVER_OPTS -screen $NEW_SCREEN -mouse $MOUSE &" \
311 >> $HOME/.xsession
312 fi
313 echo '#xterm &' >> $HOME/.xsession
314 echo '#xpad &' >> $HOME/.xsession
315 # LXpanel by default with JWM.
316 if [ "$WM" = "jwm" ]; then
317 echo 'lxpanel &' >> $HOME/.xsession
318 fi
319 echo "exec $WM" >> $HOME/.xsession
320 chmod 700 $HOME/.xsession
321 }
323 ###################
324 # Tazx sequence #
325 ###################
327 [ -n "$NEW_SCREEN" ] || screen_config_dialog
328 slim_config
329 e17_stuff
330 openbox_stuff
331 creat_xinitrc
332 jwm_config
333 creat_xsession
335 exit 0