slitaz-tools view tinyutils/tazx @ rev 797

Regenerate tazdrop.pot
author Claudinei Pereira <claudinei@slitaz.org>
date Sat Jan 26 15:53:49 2013 -0200 (2013-01-26)
parents 29fe613b2eb6
children a1290b22987c
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 :2
49 # Backup existing config.
50 tar -cf $xorg_config/../Previous_xorg.conf.d.tar $xorg_config/ &> /dev/null
52 # Put the different 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 variant=""
79 # this XkbOption moved from 40-evdev.conf (xorg-xf86-input-evdev)
80 options="terminate:ctrl_alt_bksp"
81 case $keymap in
82 fr_CH-latin1)
83 # Swiss FrenCH
84 layout="ch"; variant="fr" ;;
85 uk)
86 # English UK
87 layout="gb" ;;
88 ru)
89 # Russian
90 layout="us,ru"
91 options="grp:ctrl_shift_toggle, grp_led:scroll, $options" ;;
92 slovene)
93 # Slovenian
94 layout="si"; options="grp:alt_shift_toggle, $options" ;;
95 us-acentos)
96 layout="us"; variant="intl" ;;
97 *)
98 # Use clean /etc/keymap.conf value.
99 keymap=${keymap%-latin1}
100 keymap=${keymap%-lat2}
101 keymap=${keymap%-lat6}
102 layout=${keymap%-abnt2}
103 esac
105 cat > $keyboard_config << EOC
106 Section "InputClass"
107 Identifier "Keyboard Defaults"
108 MatchIsKeyboard "yes"
109 Option "XkbLayout" "$layout"
110 Option "XkbVariant" "$variant"
111 Option "XkbOptions" "$options"
112 EndSection
113 EOC
114 [ "x$variant" != "x" ] && sed -i '/XkbVariant/d' $keyboard_config
116 # Create a xorg.conf if needed.
117 if [ ! -f /etc/X11/xorg.conf ]; then
118 cat > /etc/X11/xorg.conf << EOT
119 # You can put here your own Xorg configurations. This config file is read
120 # before all files in /etc/X11/xorg.conf.d and will NOT be erased by any
121 # updates.
122 EOT
123 fi
124 }
126 # Install xorg server.
127 install_xorg()
128 {
129 [ -f "/var/lib/tazpkg/packages.list" ] || tazpkg recharge
130 exec 3>&1
131 value=`$DIALOG --clear --colors --title " $(gettext "Install Xorg") " \
132 --menu "\
133 $(gettext "Tazx helps you to select your X driver.")" 16 70 5 \
134 $(fgrep xorg-xf86-video /var/lib/tazpkg/packages.list | cut -d- -f4 | \
135 while read x; do echo $x; echo driver; done) \
136 "quit" "Quitter" \
137 2>&1 1>&3`
138 retval=$?
139 exec 3>&-
141 # Continue or exit.
142 case $retval in
143 0) continue ;;
144 1|255) exit 0 ;;
145 esac
147 # Set selected value.
148 case $value in
149 quit) exit 0 ;;
150 *)
151 installed=/var/lib/tazpkg/installed/
152 [ -d "$installed/xorg-server" ] || tazpkg get-install xorg-server
153 [ -d "$installed/xorg-xf86-video-$value" ] || \
154 tazpkg get-install xorg-xf86-video-$value
155 xorg_conf_d ;;
156 esac
157 }
159 # Screen configuration dialog. TODO: menus items to enable/disable X on boot
160 # and sed /etc/rcS.conf to remove slim from RUN_DAEMONS.
161 config_dialog()
162 {
163 exec 3>&1
164 value=`$DIALOG \
165 --clear --colors \
166 --title " Configure X " \
167 --menu "\
168 $(gettext "Tazx dialog helps you to configure your Xorg server.")\n\
169 $(gettext "Window Manager:") \Z2$WM\Zn \
170 $(gettext "X server:") \Z2Xorg\Zn" 16 70 5 \
171 "xorg" "$(gettext "Install or reconfigure Xorg")" \
172 "xfbdev" "$(gettext "Install TinyX server Xfbdev")" \
173 "quit" "$(gettext "Quit Tazx utility")" \
174 2>&1 1>&3`
175 retval=$?
176 exec 3>&-
178 # Continue or exit.
179 case $retval in
180 0) continue ;;
181 1|255) exit 0 ;;
182 esac
184 # Set selected value.
185 case $value in
186 xorg)
187 install_xorg ;;
188 xfbdev)
189 # FIXME: Much to do here, for now just install Xfbdev.
190 tazpkg get-install xorg-server-Xfbdev ;;
191 *) exit 0 ;;
192 esac
193 }
195 # Window manager specific configuration.
196 wm_config()
197 {
198 case $WM in
199 ob|openbox)
200 WM=openbox-session
201 # Check if a personal autostart script exists if OB is installed.
202 if [ -d "/var/lib/tazpkg/installed/openbox" ]; then
203 if [ ! -f "$HOME/.config/openbox/autostart.sh" ]; then
204 mkdir -p $HOME/.config/openbox
205 cp /etc/xdg/openbox/autostart.sh $HOME/.config/openbox
206 fi
207 # Script for default user (uid=1000).
208 if [ ! -f "/home/$USER/.config/openbox/autostart.sh" ]; then
209 mkdir -p /home/$USER/.config/openbox
210 cp /etc/xdg/openbox/autostart.sh /home/$USER/.config/openbox
211 fi
212 if [ ! -f "/home/$USER/.config/openbox/menu.xml" ]; then
213 mkdir -p /home/$USER/.config/openbox
214 cp /etc/xdg/openbox/menu.xml /home/$USER/.config/openbox
215 fi
216 chown -R $USER.users /home/$USER/.config
217 fi ;;
218 jwm)
219 WM=jwm
220 JWM_CONFIG=$HOME/.jwmrc
221 if [ -d "/var/lib/tazpkg/installed/jwm" ]; then
222 if [ ! -f "$JWM_CONFIG" ]; then
223 cp /etc/jwm/system.jwmrc $JWM_CONFIG
224 fi
225 # In Live mode default user/root JWM config does not exist and
226 # $HOME is not set, this is because tazx is executed by boot
227 # scripts.
228 if [ ! -f "/home/$USER/.jwmrc" ]; then
229 cp /etc/jwm/system.jwmrc /home/$USER/.jwmrc
230 chown $USER.users /home/$USER/.jwmrc
231 fi
232 if [ ! -f "/root/.jwmrc" -a `id -u` = 0 ]; then
233 cp /etc/jwm/system.jwmrc /root/.jwmrc
234 fi
235 fi ;;
236 pekwm)
237 WM=pekwm
238 if [ -d "/var/lib/tazpkg/installed/pekwm" ]; then
239 if [ -d "$HOME/.pekwm" ]; then
240 cp -R /etc/pekwm $HOME/.pekwm
241 fi
242 # In Live mode we want config before starting pekwm the first time.
243 if [ ! -d "/home/$USER/.pekwm" ]; then
244 cp -R /etc/pekwm /home/$USER/.pekwm
245 chown -R $USER.users /home/$USER/.pekwm
246 chmod +x /home/$USER/.pekwm/start
247 fi
248 if [ ! -d "/root/.pekwm" -a `id -u` = 0 ]; then
249 cp -R /etc/pekwm /root/.pekwm
250 chmod +x /root/.pekwm/start
251 fi
252 fi ;;
253 e17|enlightenment)
254 WM=enlightenment_start ;;
255 fluxbox)
256 WM=startfluxbox ;;
257 dwm|karmen)
258 WM=$WM-session ;;
259 awesome)
260 WM=awesome ;;
261 xfce|xfce4)
262 WM=xfce4-session ;;
263 esac
264 }
266 # Sample xinitrc for user (WM can be specified with F1 at slim login).
267 xinitrc_sample()
268 {
269 cat > $FILE << "EOF"
270 # ~/.xinitrc: Executed by slim login manager to startx X session.
271 # You can use F1 with Slim to change your window manager or configure
272 # it permanently with your personal applications.conf file.
273 #
274 . $HOME/.config/slitaz/applications.conf
276 case $1 in
277 e17|enlightenment*)
278 exec enlightenment_start ;;
279 openbox|openbox-session|ob)
280 exec openbox-session ;;
281 dwm|dwm-session)
282 exec dwm-session ;;
283 fluxbox|startfluxbox)
284 exec startfluxbox ;;
285 awesome)
286 exec awesome ;;
287 pekwm)
288 exec pekwm ;;
289 karmen|karmen-session)
290 exec karmen-session ;;
291 jwm)
292 lxpanel &
293 exec jwm ;;
294 xfce|xfce4|xfce4-session)
295 xfce4-session ;;
296 *)
297 exec $WINDOW_MANAGER ;;
298 esac
299 EOF
300 # Set default WM in applications.conf user file. Default WM can be
301 # configured graphically with 'desktopbox tazapps'
302 . $CONFIG
303 sed -i s/"WINDOW_MANAGER=.*"/"WINDOW_MANAGER=\"$WM\""/ \
304 $CONFIG
305 }
307 # ~/.xinitrc for X login from a DM.
308 creat_xinitrc()
309 {
310 FILE=$HOME/.xinitrc
311 CONFIG=$HOME/.config/slitaz/applications.conf
312 if [ ! -f $CONFIG ]; then
313 mkdir -p $HOME/.config/slitaz
314 cp /etc/slitaz/applications.conf $CONFIG
315 fi
316 xinitrc_sample
317 # .xinitrc and config for /etc/skel so new added user will get
318 # a working X session.
319 if test $(id -u) = 0; then
320 FILE=/etc/skel/.xinitrc
321 CONFIG=/etc/skel/.config/slitaz/applications.conf
322 mkdir -p /etc/skel/.config/slitaz
323 cp -f /etc/slitaz/applications.conf $CONFIG
324 xinitrc_sample
325 fi
326 # In Live mode default user needs a xinitrc, since tazx
327 # is executed only by root.
328 CONFIG=/home/$USER/.config/slitaz/applications.conf
329 if [ ! -f $CONFIG ]; then
330 mkdir -p /home/$USER/.config/slitaz
331 cp /etc/slitaz/applications.conf $CONFIG
332 fi
333 chown -R $USER.users /home/$USER/.config/slitaz
334 if [ ! -f /home/$USER/.xinitrc ]; then
335 FILE=/home/$USER/.xinitrc
336 xinitrc_sample
337 chown $USER.users $FILE
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 [ -f $HOME/.xsession ] && cp -f $HOME/.xsession $HOME/.previous_xsession
346 cat > $HOME/.xsession << _EOF_
347 # ~/.xsession: Start X window session manually on your system (startx).
348 #
349 Xorg &
350 #xterm &
351 _EOF_
352 # LXpanel by default with JWM.
353 if [ "$WM" = "jwm" ]; then
354 echo 'lxpanel &' >> $HOME/.xsession
355 fi
356 echo "exec $WM" >> $HOME/.xsession
357 chmod 700 $HOME/.xsession
358 }
361 # Commands - WM can be specified on cmdline.
363 case "$1" in
364 install-xorg)
365 check_root
366 if [ -n "$2" ]; then
367 WM=$2
368 fi
369 echo "xorg" > /etc/X11/screen.conf
370 install_xorg
371 wm_config
372 creat_xinitrc
373 creat_xsession ;;
374 config-xorg)
375 check_root
376 if [ -n "$2" ]; then
377 WM=$2
378 fi
379 echo "xorg" > /etc/X11/screen.conf
380 wm_config
381 creat_xinitrc
382 creat_xsession
383 xorg_conf_d
384 if grep -qs screen= /proc/cmdline ; then
385 MODE="$(sed 's/.*screen=\([0-9]*x[0-9]*\).*/\1/' < /proc/cmdline)"
386 sed -i "s/.*EndSubSection.*/\\t\\tModes\\t\"$MODE\"\\n&/" \
387 /etc/X11/xorg.conf.d/70-Screen.conf
388 fi ;;
389 *)
390 # User can get a new .xinitrc with tazx from cmdline.
391 if [ -n "$1" ]; then
392 WM=$1
393 fi
394 if test $(id -u) = 0; then
395 echo "xorg" > /etc/X11/screen.conf
396 config_dialog
397 fi
398 wm_config
399 creat_xinitrc
400 creat_xsession ;;
401 esac
403 exit 0