slitaz-tools view tinyutils/tazx @ rev 362

Add: sshbox
author Eric Joseph-Alexandre <erjo@slitaz.org>
date Thu Jun 18 10:07:49 2009 +0200 (2009-06-18)
parents 4487d4096fbf
children cf5de149f626
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 Xvesa kdrive
5 # and Xorg with several Window Manager.
6 #
7 # (c) 2009 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 XSERVER=Xvesa
15 KEYBD=keyboard
16 MOUSE=mouse,5,/dev/input/mice
17 WM=openbox
19 # Default user for config files in Live mode.
20 [ -z $USER ] && USER=`cat /etc/passwd | grep 1000 | cut -d ":" -f 1`
22 ####################
23 # Tazx functions #
24 ####################
26 # Patch xorg.conf to set keymap layout.
27 patch_xorg_kbd()
28 {
29 KEYMAP=`cat /etc/keymap.conf`
30 case $KEYMAP in
31 fr_CH-latin1)
32 # Swiss FrenCH
33 patch -p0 <<EOF
34 --- /etc/X11/xorg.conf
35 +++ /etc/X11/xorg.conf
36 @@ -30,2 +30,3 @@
37 Driver "kbd"
38 + Option "XkbLayout" "ch"
39 + Option "XkbVariant" "fr"
40 EndSection
41 EOF
42 ;;
43 en)
44 # Englisk UK
45 patch -p0 <<EOF
46 --- /etc/X11/xorg.conf
47 +++ /etc/X11/xorg.conf
48 @@ -30,2 +30,3 @@
49 Driver "kbd"
50 + Option "XkbLayout" "en"
51 + Option "XkbVariant" "en"
52 EndSection
53 EOF
54 ;;
55 ru)
56 # Russian
57 patch -p0 <<EOF
58 --- /etc/X11/xorg.conf
59 +++ /etc/X11/xorg.conf
60 @@ -30,2 +30,3 @@
61 Driver "kbd"
62 + Option "XkbLayout" "us,ru(winkeys)"
63 + Option "XkbVariant" "grp:alt_shift_toggle"
64 EndSection
65 EOF
66 ;;
67 slovene)
68 # Slovenian
69 patch -p0 <<EOF
70 --- /etc/X11/xorg.conf
71 +++ /etc/X11/xorg.conf
72 @@ -30,2 +30,3 @@
73 Driver "kbd"
74 + Option "XkbLayout" "si"
75 + Option "XkbOptions" "grp:alt_shift_toggle"
76 EndSection
77 EOF
78 ;;
79 *)
80 # Use clean /etc/keymap.conf value.
81 KEYMAP=${KEYMAP%-latin1}
82 KEYMAP=${KEYMAP%-lat2}
83 KEYMAP=${KEYMAP%-lat6}
84 KEYMAP=${KEYMAP%-abnt2}
85 patch -p0 <<EOF
86 --- /etc/X11/xorg.conf
87 +++ /etc/X11/xorg.conf
88 @@ -30,2 +30,3 @@
89 Driver "kbd"
90 + Option "XkbLayout" "$KEYMAP"
91 EndSection
92 EOF
93 ;;
94 esac
95 }
97 # Install xorg server
98 install_xorg()
99 {
100 tazpkg recharge
101 exec 3>&1
102 value=`$DIALOG --clear --colors --title " Install Xorg " \
103 --menu \
104 "The 'tazx' application helps you to select your X driver." 16 70 5 \
105 $(grep xorg-xf86-video /var/lib/tazpkg/packages.list | cut -d- -f4 | while read x; do echo $x; echo driver; done) \
106 "quit" "Quitter" \
107 2>&1 1>&3`
108 retval=$?
109 exec 3>&-
110 # Continue, exit...
111 case $retval in
112 1)
113 echo "Cancel pressed..."
114 exit 0 ;;
115 255)
116 if test -z "$value"; then
117 echo "ESC pressed..."
118 exit 0
119 fi ;;
120 esac
121 # Set selected value.
122 case $value in
123 quit)
124 echo "Quit..."
125 exit 0 ;;
126 *)
127 tazpkg get-install xorg-server
128 tazpkg get-install xorg-xf86-video-$value
129 Xorg -configure :1
130 mv -f /root/xorg.conf.new /etc/X11/xorg.conf
131 patch_xorg_kbd
132 sed -i 's|/usr/bin/Xvesa|/usr/bin/Xorg|' /etc/slim.conf
133 sed -i s/"^xserver_arguments"/'\#xserver_arguments'/ /etc/slim.conf
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 X session.\n\
147 Window Manager : \Z2$WM\Zn" 16 70 5 \
148 $(Xvesa -listmodes 2>&1 | grep ^0x | awk '{ printf "%s %s\n",$2,$3 }' | sort -nr | grep x[1-2][4-6]) \
149 "xterm" "800x600x16" \
150 "xorg" "Installer Xorg" \
151 "wm" "Choose Window Manager" \
152 "quit" "Quitter" \
153 2>&1 1>&3`
154 retval=$?
155 exec 3>&-
156 # Continue, exit or help...
157 case $retval in
158 0)
159 continue ;;
160 1)
161 echo "Cancel pressed..."
162 exit 0 ;;
163 255)
164 if test -n "$value"; then
165 continue
166 else
167 echo "ESC pressed..."
168 exit 0
169 fi ;;
170 esac
171 # Set selected value.
172 case $value in
173 xorg)
174 install_xorg ;;
175 xterm)
176 Xvesa -ac -shadow -screen 800x600x16 -br &
177 exec xterm -cr orange -geometry 80x35+0-0 ;;
178 *)
179 NEW_SCREEN=$value ;;
180 esac
181 }
183 # Slim config if root.
184 slim_config()
185 {
186 if test $(id -u) = 0; then
187 # /etc/X11/screen.conf exists for Live mode, if this file does not
188 # exist tazx is executed at boot time.
189 mkdir -p /etc/X11
190 echo "SCREEN=$NEW_SCREEN" > /etc/X11/screen.conf
191 # Get current screen size and sed config file with the new value.
192 if [ -f /etc/slim.conf ]; then
193 RES=$(grep ^xserver_arguments /etc/slim.conf | \
194 sed 's/xserver_arguments.*-screen *//' | awk '{ print $1 }')
195 #sed -i "s/\(xserver_arguments.*-screen\).*/\1 $NEW_SCREEN/" /etc/slim.conf
196 sed -i s/"-screen $RES"/"-screen $NEW_SCREEN"/ /etc/slim.conf
197 fi
198 fi
199 }
201 # Window manager specific configuration.
202 wm_config()
203 {
204 case $WM in
205 ob|openbox)
206 WM=openbox-session
207 XSEVER_OPTS="dpms +extension Composite"
208 # Check if a personal autostart script exists if OB is installed.
209 if [ -d "/var/lib/tazpkg/installed/openbox" ]; then
210 if [ ! -f "$HOME/.config/openbox/autostart.sh" ]; then
211 mkdir -p $HOME/.config/openbox
212 cp /etc/xdg/openbox/autostart.sh $HOME/.config/openbox
213 fi
214 # Script for default user (uid=1000).
215 if [ ! -f "/home/$USER/.config/openbox/autostart.sh" ]; then
216 mkdir -p /home/$USER/.config/openbox
217 cp /etc/xdg/openbox/autostart.sh /home/$USER/.config/openbox
218 fi
219 if [ ! -f "/home/$USER/.config/openbox/menu.xml" ]; then
220 mkdir -p /home/$USER/.config/openbox
221 cp /etc/xdg/openbox/menu.xml /home/$USER/.config/openbox
222 fi
223 chown -R $USER.$USER /home/$USER/.config
224 fi ;;
225 jwm)
226 WM=jwm
227 XSEVER_OPTS="dpms +extension Composite"
228 JWM_CONFIG=$HOME/.jwmrc
229 if [ -d "/var/lib/tazpkg/installed/jwm" ]; then
230 if [ ! -f "$JWM_CONFIG" ]; then
231 cp /etc/jwm/system.jwmrc $JWM_CONFIG
232 fi
233 # In Live mode default user/root JWM config does not exist and
234 # $HOME is not set, this is because tazx is executed by boot
235 # scripts.
236 if [ ! -f "/home/$USER/.jwmrc" ]; then
237 cp /etc/jwm/system.jwmrc /home/$USER/.jwmrc
238 chown $USER.$USER /home/$USER/.jwmrc
239 fi
240 if [ ! -f "/root/.jwmrc" -a `id -u` = 0 ]; then
241 cp /etc/jwm/system.jwmrc /root/.jwmrc
242 fi
243 fi ;;
244 pekwm)
245 WM=pekwm
246 XSEVER_OPTS="dpms"
247 if [ -d "/var/lib/tazpkg/installed/pekwm" ]; then
248 if [ -d "$HOME/.pekwm" ]; then
249 cp -R /etc/pekwm $HOME/.pekwm
250 fi
251 # In Live mode we want config before starting pekwm the first time.
252 if [ ! -d "/home/$USER/.pekwm" ]; then
253 cp -R /etc/pekwm /home/$USER/.pekwm
254 chown -R $USER.$USER /home/$USER/.pekwm
255 chmod +x /home/$USER/.pekwm/start
256 fi
257 if [ ! -d "/root/.pekwm" -a `id -u` = 0 ]; then
258 cp -R /etc/pekwm /root/.pekwm
259 chmod +x /root/.pekwm/start
260 fi
261 fi ;;
262 e17|enlightenment)
263 WM=enlightenment_start
264 XSEVER_OPTS="dpms -terminate" ;;
265 fluxbox)
266 WM=startfluxbox
267 XSEVER_OPTS="dpms" ;;
268 dwm|karmen)
269 WM=$WM-session
270 XSEVER_OPTS="dpms" ;;
271 awesome)
272 WM=awesome
273 XSEVER_OPTS="dpms" ;;
274 esac
275 }
277 # Sample xinitrc for user (WM can be specified with F1 at slim login).
278 xinitrc_sample()
279 {
280 cat > $FILE << "EOF"
281 # ~/.xinitrc: Executed by slim login manager to startx X session.
282 # You can use F1 with Slim to chage your window manager or configure
283 # it permanently with your personnal applications.conf file.
284 #
285 . $HOME/.config/slitaz/applications.conf
287 case $1 in
288 e17|enlightenment*)
289 exec enlightenment_start ;;
290 openbox|openbox-session|ob)
291 exec openbox-session ;;
292 dwm|dwm-session)
293 exec dwm-session ;;
294 fluxbox|startfluxbox)
295 exec startfluxbox ;;
296 awesome)
297 exec awesome ;;
298 pekwm)
299 exec pekwm ;;
300 karmen|karmen-session)
301 exec karmen-session ;;
302 jwm)
303 lxpanel &
304 exec jwm ;;
305 *)
306 exec $WINDOW_MANAGER ;;
307 esac
308 EOF
309 # Set default WM in applications.conf user file. Default WM can be
310 # configured graphicaly with 'desktopbox tazapps'
311 . $CONFIG
312 sed -i s/"WINDOW_MANAGER=.*"/"WINDOW_MANAGER=\"$WM\""/ \
313 $CONFIG
314 }
316 # ~/.xinitrc for slim login.
317 creat_xinitrc()
318 {
319 FILE=$HOME/.xinitrc
320 CONFIG=$HOME/.config/slitaz/applications.conf
321 if [ ! -f $CONFIG ]; then
322 mkdir -p $HOME/.config/slitaz
323 cp /etc/slitaz/applications.conf $CONFIG
324 fi
325 xinitrc_sample
326 # In Live mode default user needs a xinitrc, since tazx
327 # is executed only by root.
328 if [ ! -f /home/$USER/.xinitrc ]; then
329 FILE=/home/$USER/.xinitrc
330 CONFIG=/home/$USER/.config/slitaz/applications.conf
331 if [ ! -f $CONFIG ]; then
332 mkdir -p /home/$USER/.config/slitaz
333 cp /etc/slitaz/applications.conf $CONFIG
334 fi
335 xinitrc_sample
336 chown $USER.$USER $FILE
337 chown -R $USER.$USER /home/$USER/.config/slitaz
338 fi
339 }
341 # Create ~/.xsession to keep the configuration selected (used
342 # only by startx, Slim login manager uses .xinitrc).
343 creat_xsession()
344 {
345 cat > $HOME/.xsession << _EOF_
346 # ~/.xsession: Start X window session manually on your system (startx).
347 #
348 _EOF_
349 if [ "$XSERVER " == "Xorg" ]; then
350 echo 'Xorg &' >> $HOME/.xsession
351 else
352 cat >> $HOME/.xsession << _EOT_
353 $XSERVER -ac -shadow $XSEVER_OPTS \\
354 -screen $NEW_SCREEN \\
355 -keybd $KEYBD \\
356 -mouse $MOUSE &
357 _EOT_
358 fi
359 echo '#xterm &' >> $HOME/.xsession
360 echo '#xpad &' >> $HOME/.xsession
361 # LXpanel by default with JWM.
362 if [ "$WM" = "jwm" ]; then
363 echo 'lxpanel &' >> $HOME/.xsession
364 fi
365 echo "exec $WM" >> $HOME/.xsession
366 chmod 700 $HOME/.xsession
367 }
369 ###################
370 # Tazx sequence #
371 ###################
373 case "$1" in
374 show-config)
375 . /etc/X11/screen.conf
376 echo ""
377 echo "X11 screen resolution: $SCREEN"
378 echo ""
379 echo "Slim configuration for X server:"
380 cat /etc/slim.conf | grep ^default_xserver
381 cat /etc/slim.conf | grep ^xserver_arguments
382 echo "" ;;
383 install-xorg)
384 # WM can be specified on cmdline.
385 if [ -n "$2" ]; then
386 WM=$2
387 fi
388 install_xorg
389 slim_config
390 wm_config
391 creat_xinitrc
392 creat_xsession ;;
393 *)
394 # WM can be specified on cmdline.
395 if [ -n "$1" ]; then
396 WM=$1
397 fi
398 [ -n "$NEW_SCREEN" ] || screen_config_dialog
399 slim_config
400 wm_config
401 creat_xinitrc
402 creat_xsession ;;
403 esac
405 exit 0