slitaz-tools view tinyutils/tazx @ rev 209

tazx: copy files for default user (uid=1000)
author Christophe Lincoln <pankso@slitaz.org>
date Mon Jun 09 23:42:17 2008 +0200 (2008-06-09)
parents 121a34444924
children db0e82bebc70
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.
5 #
6 # (c) 20080609 SliTaz GNU/Linux - GNU gpl v3.
7 # Authors: Christophe Lincoln <pankso@slitaz.org>
8 # Pascal Bellard <pascal.bellard@slitaz.org>
9 #
10 : ${DIALOG=tazdialog}
12 # Variables.
13 #
14 XSERVER=Xvesa
15 DOC=/usr/share/doc/slitaz-tools/tazx.txt
16 MOUSE=/dev/input/mice,5
17 # WM can be specified on cmdline.
18 if [ -n "$1" ]; then
19 WM=$1
20 else
21 WM=openbox
22 fi
23 # Default user for config files
24 USER=`cat /etc/passwd | grep 1000 | cut -d ":" -f 1`
26 ####################
27 # Tazx functions #
28 ####################
30 # Install xorg server
31 install_xorg()
32 {
33 tazpkg recharge
34 exec 3>&1
35 value=`$DIALOG --clear --colors --title " Install Xorg " \
36 --menu \
37 "L'application 'tazx' permet de configurer le driver X." 16 70 5 \
38 $(grep xorg-xf86-video /var/lib/tazpkg/packages.list | cut -d- -f4 | while read x; do echo $x; echo driver; done) \
39 "quit" "Quitter" \
40 2>&1 1>&3`
41 retval=$?
42 exec 3>&-
43 # Continue, exit...
44 case $retval in
45 1)
46 echo "Cancel pressed..."
47 exit 0 ;;
48 255)
49 if test -z "$value"; then
50 echo "ESC pressed..."
51 exit 0
52 fi ;;
53 esac
54 # Set selected value.
55 case $value in
56 quit)
57 echo "Quit..."
58 exit 0 ;;
59 *)
60 tazpkg get-install xorg-server
61 tazpkg get-install xorg-xf86-video-$value
62 Xorg -configure :1
63 mv /root/xorg.conf.new /etc/X11/xorg.conf
64 . /etc/keymap.conf
65 patch -p0 <<EOF
66 --- /etc/X11/xorg.conf
67 +++ /etc/X11/xorg.conf
68 @@ -30,2 +30,3 @@
69 Driver "kbd"
70 + Option "XkbLayout" "${KMAP%.kmap}"
71 EndSection
72 EOF
73 sed -i 's|/usr/bin/Xvesa|/usr/bin/Xorg|' /etc/slim.conf
74 sed -i s/"^xserver_arguments"/'\#xserver_arguments'/ /etc/slim.conf
75 XSERVER=Xorg;;
76 esac
77 }
79 # Screen configuration dialog.
80 screen_config_dialog()
81 {
82 exec 3>&1
83 value=`$DIALOG --help-button \
84 --clear --colors \
85 --title " Configure X " \
86 --menu \
87 "L'application 'tazx' permet de configurer une session X.\n\
88 Gestionnaire de fenêtres : \Z2$WM\Zn" 16 70 5 \
89 $(Xvesa -listmodes 2>&1 | grep ^0x | awk '{ printf "%s %s\n",$2,$3 }' | sort -nr | grep x[1-2][4-6]) \
90 "xterm" "800x600x16" \
91 "xorg" "Installer Xorg" \
92 "quit" "Quitter" \
93 2>&1 1>&3`
94 retval=$?
95 exec 3>&-
96 # Continue, exit or help...
97 case $retval in
98 0)
99 continue ;;
100 1)
101 echo "Cancel pressed..."
102 exit 0 ;;
103 2)
104 $DIALOG --clear \
105 --title " Aide - Help " --textbox "$DOC" 16 70
106 exec tazx ;;
107 255)
108 if test -n "$value"; then
109 continue
110 else
111 echo "ESC pressed..."
112 exit 0
113 fi ;;
114 esac
115 # Set selected value.
116 case $value in
117 xorg)
118 install_xorg;;
119 xterm)
120 Xvesa -ac -shadow -screen 800x600x16 -br &
121 exec xterm -cr orange -geometry 80x35+0-0 ;;
122 *)
123 NEW_SCREEN=$value ;;
124 esac
125 }
127 # Slim config if root.
128 slim_config()
129 {
130 if test $(id -u) = 0; then
131 # /etc/X11/screen.conf exist for Live mode, if this file dos not
132 # exist tazx is executed at boot time.
133 mkdir -p /etc/X11
134 echo "SCREEN=$NEW_SCREEN" > /etc/X11/screen.conf
135 # Get current screen size and sed config file with the new value.
136 if [ -f /etc/slim.conf ]; then
137 RES=$(grep ^xserver_arguments /etc/slim.conf | sed 's/xserver_arguments.*-screen *//')
138 sed -i "s/\(xserver_arguments.*-screen\).*/\1 $NEW_SCREEN/" /etc/slim.conf
139 fi
140 JWM_CONFIG=/etc/jwm/system.jwmrc
141 fi
142 }
144 # e17 start with enlightenment_start.
145 e17_stuff()
146 {
147 if [ "$WM" == "e17" ]; then
148 WM=enlightenment_start
149 XSEVER_OPTS="dpms -terminate"
150 fi
151 }
153 # Openbox with openbox-session.
154 openbox_stuff()
155 {
156 if [ "$WM" == "openbox" -o "$WM" == "ob" ]; then
157 WM=openbox-session
158 XSEVER_OPTS="dpms +extension Composite"
159 fi
160 # Check if a personnal autostart script exist if OB is installed.
161 if [ -d "/var/lib/tazpkg/installed/openbox" ]; then
162 if [ ! -f "$HOME/.config/openbox/autostart.sh" ]; then
163 mkdir -p $HOME/.config/openbox
164 cp /etc/xdg/openbox/autostart.sh $HOME/.config/openbox
165 fi
166 # Script for default user (uid=1000).
167 if [ ! -f "/home/$USER/.config/openbox/autostart.sh" ]; then
168 mkdir -p /home/$USER/.config/openbox
169 cp /etc/xdg/openbox/autostart.sh /home/$USER/.config/openbox
170 fi
171 if [ ! -f "/home/$USER/.config/openbox/menu.xml" ]; then
172 mkdir -p /home/$USER/.config/openbox
173 cp /etc/xdg/openbox/menu.xml /home/$USER/.config/openbox
174 fi
175 chown -R $USER.$USER /home/$USER/.config
176 fi
177 }
179 # Sample xinitrc for user (WM can be specified with F1 at slim login).
180 xinitrc_sample()
181 {
182 cat > $FILE << "EOF"
183 # ~/.xinitrc: Executed by slim login manager to startx X session.
184 # You can use F1 with Slim or 'tazx' to configure permanantly
185 # your default WM: tazx e17
186 #
187 WM=openbox-session
189 case $1 in
190 e17|enlightenment_start)
191 exec enlightenment_start
192 ;;
193 openbox|openbox-session|ob)
194 exec openbox-session
195 ;;
196 jwm)
197 lxpanel &
198 exec jwm
199 ;;
200 *)
201 exec $WM
202 ;;
203 esac
204 EOF
205 # Set default WM.
206 RES=`grep ^WM=[e-o] $FILE`
207 sed -i s/"$RES"/"WM=$WM"/ $FILE
208 }
210 # ~/.xinitrc for slim login.
211 creat_xinitrc()
212 {
213 FILE=$HOME/.xinitrc
214 xinitrc_sample
216 # In Live mode default user needs a xinitrc, since tazx
217 # is executed only by root.
218 if [ ! -f /home/$USER/.xinitrc ]; then
219 FILE=/home/$USER/.xinitrc
220 xinitrc_sample
221 chown $USER.$USER $FILE
222 fi
223 }
225 # Copy a JWM system config if any present in user home.
226 jwm_config()
227 {
228 if [ -d "/var/lib/tazpkg/installed/jwm" ]; then
229 JWM_CONFIG=$HOME/.jwmrc
230 if [ ! -f "$JWM_CONFIG" ]; then
231 cp /etc/jwm/system.jwmrc $JWM_CONFIG
232 fi
233 # In Live mode default user/root JWM config dose not exist and
234 # $HOME is ot set, this is because tazx is executed by boot
235 # scripts.
236 if [ ! -f "/home/$USER/.jwmrc" ]; then
237 JWM_CONFIG=/home/$USER/.jwmrc
238 cp /etc/jwm/system.jwmrc $JWM_CONFIG
239 chown $USER.$USER $JWM_CONFIG
240 fi
241 if [ ! -f "/root/.jwmrc" -a `id -u` = 0 ]; then
242 JWM_CONFIG=/root/.jwmrc
243 cp /etc/jwm/system.jwmrc $JWM_CONFIG
244 fi
245 fi
246 }
248 # Creat ~/.xsession to keep the configuration selected (used
249 # only by startx, Slim login manager use .xinitrc).
250 creat_xsession()
251 {
252 cat > $HOME/.xsession << _EOF_
253 # ~/.xsession: Start X window session manually on your system (startx).
254 #
255 _EOF_
256 if [ "$XSERVER " == "Xorg" ]; then
257 echo 'Xorg &' >> $HOME/.xsession
258 else
259 echo "$XSERVER -ac -shadow $XSEVER_OPTS -screen $NEW_SCREEN -mouse $MOUSE &" \
260 >> $HOME/.xsession
261 fi
262 echo '#xterm &' >> $HOME/.xsession
263 echo '#xpad &' >> $HOME/.xsession
264 # LXpanel by default with JWM.
265 if [ "$WM" = "jwm" ]; then
266 echo 'lxpanel &' >> $HOME/.xsession
267 fi
268 echo "exec $WM" >> $HOME/.xsession
269 chmod 700 $HOME/.xsession
270 }
272 ###################
273 # Tazx sequence #
274 ###################
276 [ -n "$NEW_SCREEN" ] || screen_config_dialog
277 slim_config
278 e17_stuff
279 openbox_stuff
280 creat_xinitrc
281 jwm_config
282 creat_xsession
284 exit 0