slitaz-tools view tinyutils/tazx @ rev 697

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