slitaz-tools view tinyutils/tazx @ rev 813

Current state, features stabilized and open for bugfixes and translations.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Mon Sep 09 03:27:04 2013 +0300 (2013-09-09)
parents a1290b22987c
children c79e656b37a5
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-2013 SliTaz GNU/Linux - GNU GPL v3.
8 # Authors: Christophe Lincoln <pankso@slitaz.org>
9 # Pascal Bellard <pascal.bellard@slitaz.org>
10 #
11 . /lib/libtaz.sh
12 . /etc/slitaz/slitaz.conf
13 export TEXTDOMAIN='slitaz-tools' #i18n
15 : ${DIALOG=dialog}
17 # Default value.
18 WM=lxde-session
20 # Default user for config files in Live mode, id is 1000 since it is
21 # created by /etc/init.d/bootopts.sh.
22 USER=$(cat /etc/passwd | grep 1000 | cut -d ":" -f 1)
24 #
25 # Functions
26 #
28 # Save chunk of xorg.conf into specified file
29 save_chunk() {
30 sed -e '/Section "'${1#*-}'"/,/EndSection/!d' \
31 -e "s/EndSection/EndSection\n/" $xorg_template > \
32 $xorg_config/$1.conf
33 }
35 # Populate xorg.conf.d.
36 xorg_conf_d() {
37 # Define the xorg.conf.d (can be /etc/X11/xorg.conf.d or /usr/share/X11/xorg.conf.d)
38 xorg_config=/etc/X11/xorg.conf.d
40 # Define the xorg.conf.new place.
41 xorg_template=/root/xorg.conf.new
43 # Obtain a default configuration file from Xorg.
44 Xorg -configure :2
46 # Backup existing config.
47 tar -cf $xorg_config/../Previous_xorg.conf.d.tar $xorg_config/ &> /dev/null
49 # Put the different sections in separate files in the config directory.
50 save_chunk 10-ServerLayout
51 sed -i '/Core/d' $xorg_config/10-ServerLayout.conf
52 save_chunk 20-Files
53 save_chunk 30-Module
54 save_chunk 50-Monitor
55 save_chunk 60-Device
56 save_chunk 70-Screen
58 # Remove the template.
59 rm $xorg_template
61 # Configure the keyboard with the right keymap.
62 keymap=$(cat /etc/keymap.conf)
63 keyboard_config=$xorg_config/40-Keyboard.conf
64 variant=""
65 # this XkbOption moved from 40-evdev.conf (xorg-xf86-input-evdev)
66 options="terminate:ctrl_alt_bksp"
67 case $keymap in
68 fr_CH-latin1)
69 # Swiss FrenCH
70 layout="ch"; variant="fr" ;;
71 uk)
72 # English UK
73 layout="gb" ;;
74 ru)
75 # Russian
76 layout="us,ru"
77 options="grp:ctrl_shift_toggle, grp_led:scroll, $options" ;;
78 ua)
79 # Ukrainian
80 layout="us,ua,ru"
81 options="grp:ctrl_shift_toggle, $options" ;;
82 slovene)
83 # Slovenian
84 layout="si"; options="grp:alt_shift_toggle, $options" ;;
85 us-acentos)
86 layout="us"; variant="intl" ;;
87 *)
88 # Use clean /etc/keymap.conf value.
89 keymap=${keymap%-latin1}
90 keymap=${keymap%-lat2}
91 keymap=${keymap%-lat6}
92 layout=${keymap%-abnt2}
93 esac
95 cat > $keyboard_config << EOC
96 Section "InputClass"
97 Identifier "Keyboard Defaults"
98 MatchIsKeyboard "yes"
99 Option "XkbLayout" "$layout"
100 Option "XkbVariant" "$variant"
101 Option "XkbOptions" "$options"
102 EndSection
103 EOC
104 [ x$variant == x ] && sed -i '/XkbVariant/d' $keyboard_config
106 # Create a xorg.conf if needed.
107 if [ ! -f /etc/X11/xorg.conf ]; then
108 cat > /etc/X11/xorg.conf << EOT
109 # You can put here your own Xorg configurations. This config file is read
110 # before all files in /etc/X11/xorg.conf.d and will NOT be erased by any
111 # updates.
112 EOT
113 fi
114 }
116 # Install xorg server.
117 install_xorg() {
118 [ -f "/var/lib/tazpkg/packages.list" ] || tazpkg recharge
119 exec 3>&1
120 value=$($DIALOG \
121 --clear --colors \
122 --title " $(_n 'Install Xorg') " \
123 --menu "$(_n 'Tazx helps you to select your X driver.')" 16 70 8 \
124 $(fgrep xorg-xf86-video /var/lib/tazpkg/packages.list | cut -d- -f4 | \
125 while read x; do echo $x; _ 'driver'; done) \
126 "quit" "$(_n 'Quit')" \
127 2>&1 1>&3)
128 retval=$?
129 exec 3>&-
131 # Continue or exit.
132 case $retval in
133 0) continue ;;
134 1|255) exit 0 ;;
135 esac
137 # Set selected value.
138 case $value in
139 quit) exit 0 ;;
140 *)
141 installed=/var/lib/tazpkg/installed/
142 [ -d "$installed/xorg-server" ] || tazpkg get-install xorg-server
143 [ -d "$installed/xorg-xf86-video-$value" ] || \
144 tazpkg get-install xorg-xf86-video-$value
145 xorg_conf_d ;;
146 esac
147 }
149 # Screen configuration dialog. TODO: menus items to enable/disable X on boot
150 # and sed /etc/rcS.conf to remove slim from RUN_DAEMONS.
151 config_dialog() {
152 exec 3>&1
153 value=$($DIALOG \
154 --clear --colors \
155 --title " $(_n 'Configure X') " \
156 --menu "\
157 $(_n 'Tazx dialog helps you to configure your Xorg server.')\n\n\
158 $(_n 'Window Manager:') \Z2$WM\Zn \n\
159 $(_n 'X server:') \Z2Xorg\Zn" 16 70 3 \
160 "xorg" "$(_n 'Install or reconfigure Xorg')" \
161 "xfbdev" "$(_n 'Install TinyX server Xfbdev')" \
162 "quit" "$(_n 'Quit Tazx utility')" \
163 2>&1 1>&3)
164 retval=$?
165 exec 3>&-
167 # Continue or exit.
168 case $retval in
169 0) continue ;;
170 1|255) exit 0 ;;
171 esac
173 # Set selected value.
174 case $value in
175 xorg)
176 install_xorg ;;
177 xfbdev)
178 # FIXME: Much to do here, for now just install Xfbdev.
179 tazpkg get-install xorg-server-Xfbdev ;;
180 *) exit 0 ;;
181 esac
182 }
184 # Window manager specific configuration.
185 wm_config() {
186 case $WM in
187 ob|openbox)
188 WM=openbox-session
189 # Check if a personal autostart script exists if OB is installed.
190 if [ -d "$INSTALLED/openbox" ]; then
191 if [ ! -f "$HOME/.config/openbox/autostart.sh" ]; then
192 mkdir -p $HOME/.config/openbox
193 cp /etc/xdg/openbox/autostart.sh $HOME/.config/openbox
194 fi
195 # Script for default user (uid=1000).
196 if [ ! -f "/home/$USER/.config/openbox/autostart.sh" ]; then
197 mkdir -p /home/$USER/.config/openbox
198 cp /etc/xdg/openbox/autostart.sh /home/$USER/.config/openbox
199 fi
200 if [ ! -f "/home/$USER/.config/openbox/menu.xml" ]; then
201 mkdir -p /home/$USER/.config/openbox
202 cp /etc/xdg/openbox/menu.xml /home/$USER/.config/openbox
203 fi
204 chown -R $USER.users /home/$USER/.config
205 fi ;;
206 jwm)
207 WM=jwm
208 JWM_CONFIG=$HOME/.jwmrc
209 if [ -d "$INSTALLED/jwm" ]; then
210 if [ ! -f "$JWM_CONFIG" ]; then
211 cp /etc/jwm/system.jwmrc $JWM_CONFIG
212 fi
213 # In Live mode default user/root JWM config does not exist and
214 # $HOME is not set, this is because tazx is executed by boot
215 # scripts.
216 if [ ! -f "/home/$USER/.jwmrc" ]; then
217 cp /etc/jwm/system.jwmrc /home/$USER/.jwmrc
218 chown $USER.users /home/$USER/.jwmrc
219 fi
220 if [ ! -f "/root/.jwmrc" -a $(id -u) = 0 ]; then
221 cp /etc/jwm/system.jwmrc /root/.jwmrc
222 fi
223 fi ;;
224 pekwm)
225 WM=pekwm
226 if [ -d "$INSTALLED/pekwm" ]; then
227 if [ -d "$HOME/.pekwm" ]; then
228 cp -R /etc/pekwm $HOME/.pekwm
229 fi
230 # In Live mode we want config before starting pekwm the first time.
231 if [ ! -d "/home/$USER/.pekwm" ]; then
232 cp -R /etc/pekwm /home/$USER/.pekwm
233 chown -R $USER.users /home/$USER/.pekwm
234 chmod +x /home/$USER/.pekwm/start
235 fi
236 if [ ! -d "/root/.pekwm" -a `id -u` = 0 ]; then
237 cp -R /etc/pekwm /root/.pekwm
238 chmod +x /root/.pekwm/start
239 fi
240 fi ;;
241 e17|enlightenment)
242 WM=enlightenment_start ;;
243 fluxbox)
244 WM=startfluxbox ;;
245 dwm|karmen)
246 WM=$WM-session ;;
247 awesome)
248 WM=awesome ;;
249 xfce|xfce4)
250 WM=xfce4-session ;;
251 esac
252 }
254 # Sample xinitrc for user (WM can be specified with F1 at slim login).
255 xinitrc_sample() {
256 cat > $1 << "EOF"
257 # ~/.xinitrc: Executed by slim login manager to startx X session.
258 # You can use F1 with Slim to change your window manager or configure
259 # it permanently with your personal applications.conf file.
260 #
261 . $HOME/.config/slitaz/applications.conf
263 case $1 in
264 e17|enlightenment*) exec enlightenment_start ;;
265 openbox|openbox-session|ob) exec openbox-session ;;
266 dwm|dwm-session) exec dwm-session ;;
267 fluxbox|startfluxbox) exec startfluxbox ;;
268 awesome) exec awesome ;;
269 pekwm) exec pekwm ;;
270 karmen|karmen-session) exec karmen-session ;;
271 jwm) lxpanel & exec jwm ;;
272 xfce|xfce4|xfce4-session) xfce4-session ;;
273 *) exec $WINDOW_MANAGER ;;
274 esac
275 EOF
276 # Set default WM in applications.conf user file. Default WM can be
277 # configured graphically with 'desktopbox tazapps'
278 . $CONFIG
279 sed -i 's|WINDOW_MANAGER=.*|WINDOW_MANAGER="'$WM'"|' $CONFIG
280 }
282 # ~/.xinitrc for X login from a DM.
283 creat_xinitrc() {
284 local APCONF=/etc/slitaz/applications.conf
286 CONFIG=$HOME/.config/slitaz/applications.conf
287 if [ ! -f $CONFIG ]; then
288 mkdir -p $(dirname $CONFIG); cp $APCONF $CONFIG
289 fi
290 xinitrc_sample $HOME/.xinitrc
292 # Make .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 CONFIG=/etc/skel/.config/slitaz/applications.conf
296 mkdir -p $(dirname $CONFIG); cp -f $APCONF $CONFIG
297 xinitrc_sample /etc/skel/.xinitrc
298 fi
300 # In Live mode default user needs a xinitrc, since tazx
301 # is executed only by root.
302 CONFIG=/home/$USER/.config/slitaz/applications.conf
303 if [ ! -f $CONFIG ]; then
304 mkdir -p $(dirname $CONFIG); cp $APCONF $CONFIG
305 fi
306 chown -R $USER.users /home/$USER/.config/slitaz
308 FILE=/home/$USER/.xinitrc
309 if [ ! -f $FILE ]; then
310 xinitrc_sample $FILE
311 chown $USER.users $FILE
312 fi
313 }
315 # Create ~/.xsession to keep the configuration selected (used
316 # only by startx, Slim login manager uses .xinitrc).
317 creat_xsession() {
318 local xsession=$HOME/.xsession
319 [ -f $xsession ] && cp -f $xsession $HOME/.previous_xsession
320 cat > $xsession << _EOF_
321 # ~/.xsession: Start X window session manually on your system (startx).
322 #
323 Xorg &
324 #xterm &
325 _EOF_
326 # LXpanel by default with JWM.
327 if [ "$WM" = "jwm" ]; then
328 echo 'lxpanel &' >> $xsession
329 fi
330 echo "exec $WM" >> $xsession
331 chmod 700 $xsession
332 }
335 # Commands - WM can be specified on cmdline.
337 case "$1" in
338 install-xorg)
339 check_root $@
340 if [ -n "$2" ]; then
341 WM=$2
342 fi
343 echo "xorg" > /etc/X11/screen.conf
344 install_xorg
345 wm_config
346 creat_xinitrc
347 creat_xsession ;;
348 config-xorg)
349 check_root $@
350 if [ -n "$2" ]; then
351 WM=$2
352 fi
353 echo "xorg" > /etc/X11/screen.conf
354 wm_config
355 creat_xinitrc
356 creat_xsession
357 xorg_conf_d
358 if grep -qs screen= /proc/cmdline ; then
359 MODE="$(sed 's/.*screen=\([0-9]*x[0-9]*\).*/\1/' < /proc/cmdline)"
360 sed -i "s/.*EndSubSection.*/\\t\\tModes\\t\"$MODE\"\\n&/" \
361 /etc/X11/xorg.conf.d/70-Screen.conf
362 fi ;;
363 *)
364 # User can get a new .xinitrc with tazx from cmdline.
365 if [ -n "$1" ]; then
366 WM=$1
367 fi
368 if test $(id -u) = 0; then
369 echo "xorg" > /etc/X11/screen.conf
370 config_dialog
371 fi
372 wm_config
373 creat_xinitrc
374 creat_xsession ;;
375 esac
377 exit 0