slitaz-tools view tinyutils/tazx @ rev 540

Changed group tux to group users.
author Christopher Rogers <slaxemulator@gmail.com>
date Sat Jan 22 21:21:24 2011 +0000 (2011-01-22)
parents 1ab714afb4a0
children 0f5e3af5a51d
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.
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=tazdialog}
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 ####################
21 # Tazx functions #
22 ####################
24 # Populate xorg.conf.d.
25 xorg_conf_d()
26 {
27 # Define the xorg.conf.d (can be /etc/X11/xorg.conf.d or /usr/share/X11/xorg.conf.d)
28 xorg_config=/etc/X11/xorg.conf.d
30 # Define the xorg.conf.new place.
31 xorg_template=/root/xorg.conf.new
33 # Obtain a default configuration file from Xorg.
34 Xorg -configure :1
36 # Backup existing config.
37 tar -cf $xorg_config/../Previous_xorg.conf.d.tar $xorg_config/ &> /dev/null
39 # Put the differents sections in separate files in the configuration directory.
40 sed -e '/Section "ServerLayout"/,/EndSection/!d' -e "s/EndSection/EndSection\n/" $xorg_template | grep -v Core > $xorg_config/10-ServerLayout.conf
41 sed -e '/Section "Files"/,/EndSection/!d' -e "s/EndSection/EndSection\n/" $xorg_template > $xorg_config/20-Files.conf
42 sed -e '/Section "Module"/,/EndSection/!d' -e "s/EndSection/EndSection\n/" $xorg_template > $xorg_config/30-Module.conf
43 sed -e '/Section "Monitor"/,/EndSection/!d' -e "s/EndSection/EndSection\n/" $xorg_template > $xorg_config/50-Monitor.conf
44 sed -e '/Section "Device"/,/EndSection/!d' -e "s/EndSection/EndSection\n/" $xorg_template > $xorg_config/60-Device.conf
45 sed -e '/Section "Screen"/,/EndSection/!d' -e "s/EndSection/EndSection\n/" $xorg_template > $xorg_config/70-Screen.conf
47 # Remove the template.
48 rm $xorg_template
50 # Configure the keyboard with the right keymap.
51 keymap=`cat /etc/keymap.conf`
52 keyboard_config=$xorg_config/40-Keyboard.conf
53 echo 'Section "InputClass"
54 Identifier "Keyboard Defaults"
55 MatchIsKeyboard "yes"' > $keyboard_config
56 case $keymap in
57 fr_CH-latin1)
58 # Swiss FrenCH
59 echo ' Option "XkbLayout" "ch"
60 Option "XkbVariant" "fr"' >> $keyboard_config
61 ;;
62 en)
63 # Englisk UK
64 echo ' Option "XkbLayout" "en"
65 Option "XkbVariant" "en"' >> $keyboard_config
66 ;;
67 ru)
68 # Russian
69 echo ' Option "XkbLayout" "us,ru(winkeys)"
70 Option "XkbVariant" "grp:alt_shift_toggle"' >> $keyboard_config
71 ;;
72 slovene)
73 # Slovenian
74 echo ' Option "XkbLayout" "si"
75 Option "XkbOptions" "grp:alt_shift_toggle"' >> $keyboard_config
76 ;;
77 *)
78 # Use clean /etc/keymap.conf value.
79 keymap=${keymap%-latin1}
80 keymap=${keymap%-lat2}
81 keymap=${keymap%-lat6}
82 keymap=${keymap%-abnt2}
83 echo ' Option "XkbLayout" "'$keymap\" >> $keyboard_config
84 ;;
85 esac
87 echo 'Endsection' >> $keyboard_config
89 # Create a xorg.conf if needed.
90 [ ! -f /etc/X11/xorg.conf ] && echo "# You can put here your own Xorg configurations.
91 # This configuration file is read before all files in /etc/X11/xorg.conf.d
92 # This file will not be erased by any updates." > /etc/X11/xorg.conf
93 }
95 # Install xorg server
96 install_xorg()
97 {
98 tazpkg recharge
99 exec 3>&1
100 value=`$DIALOG --clear --colors --title " Install Xorg " \
101 --menu \
102 "The 'tazx' application helps you to select your X driver." 16 70 5 \
103 $(grep xorg-xf86-video /var/lib/tazpkg/packages.list | cut -d- -f4 | while read x; do echo $x; echo driver; done) \
104 "quit" "Quitter" \
105 2>&1 1>&3`
106 retval=$?
107 exec 3>&-
108 # Continue, exit...
109 case $retval in
110 1)
111 echo "Cancel pressed..."
112 exit 0 ;;
113 255)
114 if test -z "$value"; then
115 echo "ESC pressed..."
116 exit 0
117 fi ;;
118 esac
119 # Set selected value.
120 case $value in
121 quit)
122 echo "Quit..."
123 exit 0 ;;
124 *)
125 tazpkg get-install xorg-server
126 tazpkg get-install xorg-xf86-video-$value
127 xorg_conf_d
128 sed -i 's|/usr/bin/Xvesa|/usr/bin/Xorg|' /etc/slim.conf
129 sed -i s/"^xserver_arguments"/'\#xserver_arguments'/ /etc/slim.conf
130 XSERVER=Xorg ;;
131 esac
132 }
134 # Screen configuration dialog.
135 screen_config_dialog()
136 {
137 exec 3>&1
138 value=`$DIALOG \
139 --clear --colors \
140 --title " Configure X " \
141 --menu \
142 "The 'tazx' application helps you to configure your X session.\n\
143 Window Manager : \Z2$WM\Zn \n\
144 X server : \Z2Xorg\Zn" 16 70 5 \
145 "xorg" "Install or reconfigure Xorg" \
146 "text" "Disable X autostart" \
147 "quit" "Quit Tazx utility" \
148 2>&1 1>&3`
149 retval=$?
150 exec 3>&-
151 # Continue, exit or help...
152 case $retval in
153 0)
154 continue ;;
155 1)
156 echo "Cancel pressed..."
157 exit 0 ;;
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 text)
171 sed -i s/'slim'/''/ /etc/rcS.conf
172 exit 0 ;;
173 *)
174 continue ;;
175 esac
176 }
178 # Window manager specific configuration.
179 wm_config()
180 {
181 case $WM in
182 ob|openbox)
183 WM=openbox-session
184 # Check if a personal autostart script exists if OB is installed.
185 if [ -d "/var/lib/tazpkg/installed/openbox" ]; then
186 if [ ! -f "$HOME/.config/openbox/autostart.sh" ]; then
187 mkdir -p $HOME/.config/openbox
188 cp /etc/xdg/openbox/autostart.sh $HOME/.config/openbox
189 fi
190 # Script for default user (uid=1000).
191 if [ ! -f "/home/$USER/.config/openbox/autostart.sh" ]; then
192 mkdir -p /home/$USER/.config/openbox
193 cp /etc/xdg/openbox/autostart.sh /home/$USER/.config/openbox
194 fi
195 if [ ! -f "/home/$USER/.config/openbox/menu.xml" ]; then
196 mkdir -p /home/$USER/.config/openbox
197 cp /etc/xdg/openbox/menu.xml /home/$USER/.config/openbox
198 fi
199 chown -R $USER.users /home/$USER/.config
200 fi ;;
201 jwm)
202 WM=jwm
203 JWM_CONFIG=$HOME/.jwmrc
204 if [ -d "/var/lib/tazpkg/installed/jwm" ]; then
205 if [ ! -f "$JWM_CONFIG" ]; then
206 cp /etc/jwm/system.jwmrc $JWM_CONFIG
207 fi
208 # In Live mode default user/root JWM config does not exist and
209 # $HOME is not set, this is because tazx is executed by boot
210 # scripts.
211 if [ ! -f "/home/$USER/.jwmrc" ]; then
212 cp /etc/jwm/system.jwmrc /home/$USER/.jwmrc
213 chown $USER.users /home/$USER/.jwmrc
214 fi
215 if [ ! -f "/root/.jwmrc" -a `id -u` = 0 ]; then
216 cp /etc/jwm/system.jwmrc /root/.jwmrc
217 fi
218 fi ;;
219 pekwm)
220 WM=pekwm
221 if [ -d "/var/lib/tazpkg/installed/pekwm" ]; then
222 if [ -d "$HOME/.pekwm" ]; then
223 cp -R /etc/pekwm $HOME/.pekwm
224 fi
225 # In Live mode we want config before starting pekwm the first time.
226 if [ ! -d "/home/$USER/.pekwm" ]; then
227 cp -R /etc/pekwm /home/$USER/.pekwm
228 chown -R $USER.users /home/$USER/.pekwm
229 chmod +x /home/$USER/.pekwm/start
230 fi
231 if [ ! -d "/root/.pekwm" -a `id -u` = 0 ]; then
232 cp -R /etc/pekwm /root/.pekwm
233 chmod +x /root/.pekwm/start
234 fi
235 fi ;;
236 e17|enlightenment)
237 WM=enlightenment_start ;;
238 fluxbox)
239 WM=startfluxbox ;;
240 dwm|karmen)
241 WM=$WM-session ;;
242 awesome)
243 WM=awesome ;;
244 xfce|xfce4)
245 WM=xfce4-session ;;
246 esac
247 }
249 # Sample xinitrc for user (WM can be specified with F1 at slim login).
250 xinitrc_sample()
251 {
252 cat > $FILE << "EOF"
253 # ~/.xinitrc: Executed by slim login manager to startx X session.
254 # You can use F1 with Slim to change your window manager or configure
255 # it permanently with your personal applications.conf file.
256 #
257 . $HOME/.config/slitaz/applications.conf
259 case $1 in
260 e17|enlightenment*)
261 exec enlightenment_start ;;
262 openbox|openbox-session|ob)
263 exec openbox-session ;;
264 dwm|dwm-session)
265 exec dwm-session ;;
266 fluxbox|startfluxbox)
267 exec startfluxbox ;;
268 awesome)
269 exec awesome ;;
270 pekwm)
271 exec pekwm ;;
272 karmen|karmen-session)
273 exec karmen-session ;;
274 jwm)
275 lxpanel &
276 exec jwm ;;
277 xfce|xfce4|xfce4-session)
278 xfce4-session ;;
279 *)
280 exec $WINDOW_MANAGER ;;
281 esac
282 EOF
283 # Set default WM in applications.conf user file. Default WM can be
284 # configured graphically with 'desktopbox tazapps'
285 . $CONFIG
286 sed -i s/"WINDOW_MANAGER=.*"/"WINDOW_MANAGER=\"$WM\""/ \
287 $CONFIG
288 }
290 # ~/.xinitrc for X login from a DM.
291 creat_xinitrc()
292 {
293 FILE=$HOME/.xinitrc
294 CONFIG=$HOME/.config/slitaz/applications.conf
295 if [ ! -f $CONFIG ]; then
296 mkdir -p $HOME/.config/slitaz
297 cp /etc/slitaz/applications.conf $CONFIG
298 fi
299 xinitrc_sample
300 # .xinitrc and config for /etc/skel so new added user will get
301 # a working X session.
302 if test $(id -u) = 0; then
303 FILE=/etc/skel/.xinitrc
304 CONFIG=/etc/skel/.config/slitaz/applications.conf
305 mkdir -p /etc/skel/.config/slitaz
306 cp -f /etc/slitaz/applications.conf $CONFIG
307 xinitrc_sample
308 fi
309 # In Live mode default user needs a xinitrc, since tazx
310 # is executed only by root.
311 CONFIG=/home/$USER/.config/slitaz/applications.conf
312 if [ ! -f $CONFIG ]; then
313 mkdir -p /home/$USER/.config/slitaz
314 cp /etc/slitaz/applications.conf $CONFIG
315 fi
316 chown -R $USER.users /home/$USER/.config/slitaz
317 if [ ! -f /home/$USER/.xinitrc ]; then
318 FILE=/home/$USER/.xinitrc
319 xinitrc_sample
320 chown $USER.users $FILE
321 fi
322 }
324 # Create ~/.xsession to keep the configuration selected (used
325 # only by startx, Slim login manager uses .xinitrc).
326 creat_xsession()
327 {
328 [ -f $HOME/.xsession ] && cp -f $HOME/.xsession $HOME/.previous_xsession
329 cat > $HOME/.xsession << _EOF_
330 # ~/.xsession: Start X window session manually on your system (startx).
331 #
332 Xorg &
333 #xterm &
334 _EOF_
335 # LXpanel by default with JWM.
336 if [ "$WM" = "jwm" ]; then
337 echo 'lxpanel &' >> $HOME/.xsession
338 fi
339 echo "exec $WM" >> $HOME/.xsession
340 chmod 700 $HOME/.xsession
341 }
343 ###################
344 # Tazx sequence #
345 ###################
347 case "$1" in
348 install-xorg)
349 # WM can be specified on cmdline.
350 if [ -n "$2" ]; then
351 WM=$2
352 fi
353 echo "xorg" > /etc/X11/screen.conf
354 install_xorg
355 wm_config
356 creat_xinitrc
357 creat_xsession ;;
358 config-xorg)
359 # WM can be specified on cmdline.
360 if [ -n "$2" ]; then
361 WM=$2
362 fi
363 echo "xorg" > /etc/X11/screen.conf
364 wm_config
365 creat_xinitrc
366 creat_xsession
367 xorg_conf_d ;;
368 *)
369 # WM can be specified on cmdline.
370 if [ -n "$1" ]; then
371 WM=$1
372 fi
373 # User can get a new .xinitrc with tazx from cmdline.
374 if test $(id -u) = 0; then
375 echo "xorg" > /etc/X11/screen.conf
376 screen_config_dialog
377 fi
378 wm_config
379 creat_xinitrc
380 creat_xsession ;;
381 esac
383 exit 0