slitaz-tools view tinyutils/tazx @ rev 584

tazx: remove text mode option since now we can only use boot option
author Christophe Lincoln <pankso@slitaz.org>
date Fri Apr 29 21:27:38 2011 +0200 (2011-04-29)
parents b6972d7bcf5e
children 221221001c4b
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 en)
62 # Englisk UK
63 echo ' Option "XkbLayout" "en"
64 Option "XkbVariant" "en"' >> $keyboard_config ;;
65 ru)
66 # Russian
67 echo ' Option "XkbLayout" "us,ru(winkeys)"
68 Option "XkbVariant" "grp:alt_shift_toggle"' >> $keyboard_config ;;
69 slovene)
70 # Slovenian
71 echo ' Option "XkbLayout" "si"
72 Option "XkbOptions" "grp:alt_shift_toggle"' >> $keyboard_config ;;
73 us-acentos)
74 echo ' Option "XkbLayout" "us"
75 Option "XkbVariant" "intl"' >> $keyboard_config ;;
76 *)
77 # Use clean /etc/keymap.conf value.
78 keymap=${keymap%-latin1}
79 keymap=${keymap%-lat2}
80 keymap=${keymap%-lat6}
81 keymap=${keymap%-abnt2}
82 echo ' Option "XkbLayout" "'$keymap\" >> $keyboard_config
83 ;;
84 esac
86 echo 'Endsection' >> $keyboard_config
88 # Create a xorg.conf if needed.
89 [ ! -f /etc/X11/xorg.conf ] && echo "# You can put here your own Xorg configurations.
90 # This configuration file is read before all files in /etc/X11/xorg.conf.d
91 # This file will not be erased by any updates." > /etc/X11/xorg.conf
92 }
94 # Install xorg server.
95 install_xorg()
96 {
97 tazpkg recharge
98 exec 3>&1
99 value=`$DIALOG --clear --colors --title " Install Xorg " \
100 --menu \
101 "The 'tazx' application helps you to select your X driver." 16 70 5 \
102 $(grep xorg-xf86-video /var/lib/tazpkg/packages.list | cut -d- -f4 | while read x; do echo $x; echo driver; done) \
103 "quit" "Quitter" \
104 2>&1 1>&3`
105 retval=$?
106 exec 3>&-
107 # Continue, exit...
108 case $retval in
109 1)
110 echo "Cancel pressed..."
111 exit 0 ;;
112 255)
113 if test -z "$value"; then
114 echo "ESC pressed..."
115 exit 0
116 fi ;;
117 esac
118 # Set selected value.
119 case $value in
120 quit)
121 echo "Quit..."
122 exit 0 ;;
123 *)
124 tazpkg get-install xorg-server
125 tazpkg get-install xorg-xf86-video-$value
126 xorg_conf_d
127 XSERVER=Xorg ;;
128 esac
129 }
131 # Screen configuration dialog.
132 screen_config_dialog()
133 {
134 exec 3>&1
135 value=`$DIALOG \
136 --clear --colors \
137 --title " Configure X " \
138 --menu \
139 "The 'tazx' application helps you to configure your Xorg.\n\
140 Window Manager : \Z2$WM\Zn \n\
141 X server : \Z2Xorg\Zn" 16 70 5 \
142 "xorg" "Install or reconfigure Xorg" \
143 "quit" "Quit Tazx utility" \
144 2>&1 1>&3`
145 retval=$?
146 exec 3>&-
147 # Continue, exit or help...
148 case $retval in
149 0)
150 continue ;;
151 1)
152 echo "Cancel pressed..."
153 exit 0 ;;
154 255)
155 if test -n "$value"; then
156 continue
157 else
158 echo "ESC pressed..."
159 exit 0
160 fi ;;
161 esac
162 # Set selected value.
163 case $value in
164 xorg)
165 install_xorg ;;
166 *)
167 continue ;;
168 esac
169 }
171 # Window manager specific configuration.
172 wm_config()
173 {
174 case $WM in
175 ob|openbox)
176 WM=openbox-session
177 # Check if a personal autostart script exists if OB is installed.
178 if [ -d "/var/lib/tazpkg/installed/openbox" ]; then
179 if [ ! -f "$HOME/.config/openbox/autostart.sh" ]; then
180 mkdir -p $HOME/.config/openbox
181 cp /etc/xdg/openbox/autostart.sh $HOME/.config/openbox
182 fi
183 # Script for default user (uid=1000).
184 if [ ! -f "/home/$USER/.config/openbox/autostart.sh" ]; then
185 mkdir -p /home/$USER/.config/openbox
186 cp /etc/xdg/openbox/autostart.sh /home/$USER/.config/openbox
187 fi
188 if [ ! -f "/home/$USER/.config/openbox/menu.xml" ]; then
189 mkdir -p /home/$USER/.config/openbox
190 cp /etc/xdg/openbox/menu.xml /home/$USER/.config/openbox
191 fi
192 chown -R $USER.users /home/$USER/.config
193 fi ;;
194 jwm)
195 WM=jwm
196 JWM_CONFIG=$HOME/.jwmrc
197 if [ -d "/var/lib/tazpkg/installed/jwm" ]; then
198 if [ ! -f "$JWM_CONFIG" ]; then
199 cp /etc/jwm/system.jwmrc $JWM_CONFIG
200 fi
201 # In Live mode default user/root JWM config does not exist and
202 # $HOME is not set, this is because tazx is executed by boot
203 # scripts.
204 if [ ! -f "/home/$USER/.jwmrc" ]; then
205 cp /etc/jwm/system.jwmrc /home/$USER/.jwmrc
206 chown $USER.users /home/$USER/.jwmrc
207 fi
208 if [ ! -f "/root/.jwmrc" -a `id -u` = 0 ]; then
209 cp /etc/jwm/system.jwmrc /root/.jwmrc
210 fi
211 fi ;;
212 pekwm)
213 WM=pekwm
214 if [ -d "/var/lib/tazpkg/installed/pekwm" ]; then
215 if [ -d "$HOME/.pekwm" ]; then
216 cp -R /etc/pekwm $HOME/.pekwm
217 fi
218 # In Live mode we want config before starting pekwm the first time.
219 if [ ! -d "/home/$USER/.pekwm" ]; then
220 cp -R /etc/pekwm /home/$USER/.pekwm
221 chown -R $USER.users /home/$USER/.pekwm
222 chmod +x /home/$USER/.pekwm/start
223 fi
224 if [ ! -d "/root/.pekwm" -a `id -u` = 0 ]; then
225 cp -R /etc/pekwm /root/.pekwm
226 chmod +x /root/.pekwm/start
227 fi
228 fi ;;
229 e17|enlightenment)
230 WM=enlightenment_start ;;
231 fluxbox)
232 WM=startfluxbox ;;
233 dwm|karmen)
234 WM=$WM-session ;;
235 awesome)
236 WM=awesome ;;
237 xfce|xfce4)
238 WM=xfce4-session ;;
239 esac
240 }
242 # Sample xinitrc for user (WM can be specified with F1 at slim login).
243 xinitrc_sample()
244 {
245 cat > $FILE << "EOF"
246 # ~/.xinitrc: Executed by slim login manager to startx X session.
247 # You can use F1 with Slim to change your window manager or configure
248 # it permanently with your personal applications.conf file.
249 #
250 . $HOME/.config/slitaz/applications.conf
252 case $1 in
253 e17|enlightenment*)
254 exec enlightenment_start ;;
255 openbox|openbox-session|ob)
256 exec openbox-session ;;
257 dwm|dwm-session)
258 exec dwm-session ;;
259 fluxbox|startfluxbox)
260 exec startfluxbox ;;
261 awesome)
262 exec awesome ;;
263 pekwm)
264 exec pekwm ;;
265 karmen|karmen-session)
266 exec karmen-session ;;
267 jwm)
268 lxpanel &
269 exec jwm ;;
270 xfce|xfce4|xfce4-session)
271 xfce4-session ;;
272 *)
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\""/ \
280 $CONFIG
281 }
283 # ~/.xinitrc for X login from a DM.
284 creat_xinitrc()
285 {
286 FILE=$HOME/.xinitrc
287 CONFIG=$HOME/.config/slitaz/applications.conf
288 if [ ! -f $CONFIG ]; then
289 mkdir -p $HOME/.config/slitaz
290 cp /etc/slitaz/applications.conf $CONFIG
291 fi
292 xinitrc_sample
293 # .xinitrc and config for /etc/skel so new added user will get
294 # a working X session.
295 if test $(id -u) = 0; then
296 FILE=/etc/skel/.xinitrc
297 CONFIG=/etc/skel/.config/slitaz/applications.conf
298 mkdir -p /etc/skel/.config/slitaz
299 cp -f /etc/slitaz/applications.conf $CONFIG
300 xinitrc_sample
301 fi
302 # In Live mode default user needs a xinitrc, since tazx
303 # is executed only by root.
304 CONFIG=/home/$USER/.config/slitaz/applications.conf
305 if [ ! -f $CONFIG ]; then
306 mkdir -p /home/$USER/.config/slitaz
307 cp /etc/slitaz/applications.conf $CONFIG
308 fi
309 chown -R $USER.users /home/$USER/.config/slitaz
310 if [ ! -f /home/$USER/.xinitrc ]; then
311 FILE=/home/$USER/.xinitrc
312 xinitrc_sample
313 chown $USER.users $FILE
314 fi
315 }
317 # Create ~/.xsession to keep the configuration selected (used
318 # only by startx, Slim login manager uses .xinitrc).
319 creat_xsession()
320 {
321 [ -f $HOME/.xsession ] && cp -f $HOME/.xsession $HOME/.previous_xsession
322 cat > $HOME/.xsession << _EOF_
323 # ~/.xsession: Start X window session manually on your system (startx).
324 #
325 Xorg &
326 #xterm &
327 _EOF_
328 # LXpanel by default with JWM.
329 if [ "$WM" = "jwm" ]; then
330 echo 'lxpanel &' >> $HOME/.xsession
331 fi
332 echo "exec $WM" >> $HOME/.xsession
333 chmod 700 $HOME/.xsession
334 }
336 ###################
337 # Tazx sequence #
338 ###################
340 case "$1" in
341 install-xorg)
342 # WM can be specified on cmdline.
343 if [ -n "$2" ]; then
344 WM=$2
345 fi
346 echo "xorg" > /etc/X11/screen.conf
347 install_xorg
348 wm_config
349 creat_xinitrc
350 creat_xsession ;;
351 config-xorg)
352 # WM can be specified on cmdline.
353 if [ -n "$2" ]; then
354 WM=$2
355 fi
356 echo "xorg" > /etc/X11/screen.conf
357 wm_config
358 creat_xinitrc
359 creat_xsession
360 xorg_conf_d
361 if grep -qs screen= /proc/cmdline ; then
362 MODE="$(sed 's/.*screen=\([0-9]*x[0-9]*\).*/\1/' < /proc/cmdline)"
363 sed -i "s/.*EndSubSection.*/\\t\\tModes\\t\"$MODE\"\\n&/" \
364 /etc/X11/xorg.conf.d/70-Screen.conf
365 fi ;;
366 *)
367 # WM can be specified on cmdline.
368 if [ -n "$1" ]; then
369 WM=$1
370 fi
371 # User can get a new .xinitrc with tazx from cmdline.
372 if test $(id -u) = 0; then
373 echo "xorg" > /etc/X11/screen.conf
374 screen_config_dialog
375 fi
376 wm_config
377 creat_xinitrc
378 creat_xsession ;;
379 esac
381 exit 0