slitaz-tools view tinyutils/tazx @ rev 99

Improved tazx and fix .xsession
author Christophe Lincoln <pankso@slitaz.org>
date Tue Mar 11 17:16:41 2008 +0100 (2008-03-11)
parents 2ec509854987
children 4eaba614e892
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 # 20080306 <pankso@slitaz.org> - GNU gpl v3.
7 #
8 : ${DIALOG=dialog}
10 # Variables.
11 #
12 XSERVER=Xvesa
13 DOC=/usr/share/doc/slitaz-tools/tazx.txt
14 MOUSE=/dev/input/mice,5
15 # WM can be specified on cmdline.
16 if [ -n "$1" ]; then
17 WM=$1
18 else
19 WM=jwm
20 fi
22 ####################
23 # Tazx functions #
24 ####################
26 # Change backgroud image if the 3/4 is not respected.
27 change_jwm_background()
28 {
29 if echo $NEW_SCREEN | grep -q '1280x1024'; then
30 sed -i s/'1024x768.png'/'1280x1024.png'/ $JWM_CONFIG
31 sed -i s/'1280x800.png'/'1280x1024.png'/ $JWM_CONFIG
32 fi
33 if echo $NEW_SCREEN | grep -q '1024x768'; then
34 sed -i s/'1280x1024.png'/'1024x768.png'/ $JWM_CONFIG
35 sed -i s/'1280x800.png'/'1024x768.png'/ $JWM_CONFIG
36 fi
37 if echo $NEW_SCREEN | grep -q '1280x800'; then
38 sed -i s/'1024x768.png'/'1280x800.png'/ $JWM_CONFIG
39 sed -i s/'1280x1024.png'/'1280x800.png'/ $JWM_CONFIG
40 fi
41 }
43 # Screen configuration dialog.
44 screen_config_dialog()
45 {
46 exec 3>&1
47 value=`$DIALOG --help-button \
48 --clear --colors \
49 --title " Configure X " \
50 --menu \
51 "L'application 'tazx' permet de configurer une session X.\n\
52 Gestionnaire de fenêtres : \Z2$WM\Zn" 16 70 5 \
53 "640x400x16" "TrueColor" \
54 "640x400x24" "TrueColor" \
55 "640x480x16" "TrueColor" \
56 "640x480x24" "TrueColor" \
57 "800x600x16" "TrueColor" \
58 "800x600x24" "TrueColor" \
59 "1024x768x16" "TrueColor" \
60 "1024x768x24" "TrueColor" \
61 "1280x800x16" "TrueColor" \
62 "1280x800x24" "TrueColor" \
63 "1280x1024x16" "TrueColor" \
64 "1280x1024x24" "TrueColor" \
65 "1600x1200x16" "TrueColor" \
66 "1600x1200x24" "TrueColor" \
67 "1920x1440x16" "TrueColor" \
68 "xterm" "800x600x16" \
69 "quit" "Quitter" \
70 2>&1 1>&3`
71 retval=$?
72 exec 3>&-
73 # Continue, exit or help...
74 case $retval in
75 0)
76 continue ;;
77 1)
78 echo "Cancel pressed..."
79 exit 0 ;;
80 2)
81 $DIALOG --clear \
82 --title " Aide - Help " --textbox "$DOC" 16 70
83 exec tazx ;;
84 255)
85 if test -n "$value"; then
86 continue
87 else
88 echo "ESC pressed..."
89 exit 0
90 fi ;;
91 esac
92 # Set selected value.
93 case $value in
94 xterm)
95 Xvesa -ac -shadow -screen 800x600x16 -br &
96 exec xterm -cr orange -geometry 80x35+0-0 ;;
97 *)
98 NEW_SCREEN=$value ;;
99 esac
100 }
102 # Slim config if root.
103 slim_config()
104 {
105 if test $(id -u) = 0; then
106 # /etc/X11/screen.conf exist for Live mode, if this file dos not
107 # exist tazx is executed at boot time.
108 mkdir -p /etc/X11
109 echo "SCREEN=$NEW_SCREEN" > /etc/X11/screen.conf
110 # Get current screen size and sed config file with the new value.
111 if [ -f /etc/slim.conf ]; then
112 RES=$(grep ^xserver_arguments /etc/slim.conf | sed 's/xserver_arguments.*-screen *//')
113 sed -i "s/\(xserver_arguments.*-screen\).*/\1 $NEW_SCREEN/" /etc/slim.conf
114 fi
115 JWM_CONFIG=/etc/jwm/system.jwmrc
116 change_jwm_background
117 fi
118 }
120 # e17 start with enlightenment_start.
121 e17_stuff()
122 {
123 if [ "$WM" == "e17" ]; then
124 WM=enlightenment_start
125 XSEVER_OPTS="dpms -terminate"
126 fi
127 }
129 # Openbox with openbox-session.
130 openbox_stuff()
131 {
132 if [ "$WM" == "openbox" -o "$WM" == "ob" ]; then
133 WM=openbox-session
134 XSEVER_OPTS="dpms -terminate"
135 fi
136 # Check if a personnal autostart script exist if OB is installed.
137 if [ -d "/var/lib/tazpkg/installed/openbox" ]; then
138 if [ ! -f "$HOME/.config/openbox/autostart.sh" ]; then
139 mkdir -p $HOME/.config/openbox
140 cp /etc/xdg/openbox/autostart.sh $HOME/.config/openbox
141 fi
142 # Script for hacker, Openbox can be used with a LiveCD flavor or
143 # LiveUSB.
144 if [ ! -f "/home/hacker/.config/openbox/autostart.sh" ]; then
145 mkdir -p /home/hacker/.config/openbox
146 cp /etc/xdg/openbox/autostart.sh /home/hacker/.config/openbox
147 chown -R hacker.hacker /home/hacker/.config
148 fi
149 fi
150 }
152 # Sample xinitrc for user (WM can be specified with F1 at slim login).
153 xinitrc_sample()
154 {
155 cat > $FILE << "EOF"
156 # ~/.xinitrc: Executed by slim login manager to startx X session.
157 # You can use F1 with Slim or 'tazx' to configure permanantly
158 # your default WM: tazx e17
159 #
160 WM=jwm
162 if [ -n $1 ]; then
163 WM=$1
164 fi
166 case $WM in
167 e17|enlightenment_start)
168 exec enlightenment_start
169 ;;
170 openbox|openbox-session)
171 exec openbox-session
172 ;;
173 jwm|*)
174 lxpanel &
175 exec jwm
176 ;;
177 esac
178 EOF
179 }
181 # ~/.xinitrc for slim login.
182 creat_xinitrc()
183 {
184 FILE=$HOME/.xinitrc
185 xinitrc_sample
188 # In Live mode hacker needs a xinitrc, since tazx
189 # is executed only by root.
190 if [ ! -f /home/hacker/.xinitrc ]; then
191 FILE=/home/hacker/.xinitrc
192 xinitrc_sample
193 chown hacker.hacker $FILE
194 fi
195 # Set default WM.
196 RES=`grep ^WM=[e-o] $HOME/.xinitrc`
197 sed -i s/"$RES"/"WM=$WM"/ $HOME/.xinitrc
198 }
200 # Copy a JWM system config if any present in user home.
201 jwm_config()
202 {
203 JWM_CONFIG=$HOME/.jwmrc
204 if [ ! -f "$JWM_CONFIG" ]; then
205 cp /etc/jwm/system.jwmrc $JWM_CONFIG
206 fi
207 change_jwm_background
208 # In Live mode hacker JWM config dose not exist, this is
209 # because tazx is executed at boot time by root.
210 if [ ! -f "/home/hacker/.jwmrc" ]; then
211 JWM_CONFIG=/home/hacker/.jwmrc
212 cp /etc/jwm/system.jwmrc $JWM_CONFIG
213 change_jwm_background
214 chown hacker.hacker $JWM_CONFIG
215 fi
216 }
218 # Creat ~/.xsession to keep the configuration selected (used
219 # only by startx, Slim login manager use .xinitrc).
220 creat_xsession()
221 {
222 cat > $HOME/.xsession << _EOF_
223 # ~/.xsession: Start X window session manually on your system (startx).
224 #
225 $XSERVER -ac -shadow $XSEVER_OPTS -screen $NEW_SCREEN -mouse $MOUSE &
226 #xterm &
227 #xpad &
228 _EOF_
229 # LXpanel by default with JWM.
230 if [ "$WM" = "jwm" ];then
231 echo 'lxpanel &' >> $HOME/.xsession
232 fi
233 echo 'exec $WM' >> $HOME/.xsession
234 chmod 700 $HOME/.xsession
235 }
237 ###################
238 # Tazx sequence #
239 ###################
241 [ -n "$NEW_SCREEN" ] || screen_config_dialog
242 slim_config
243 e17_stuff
244 openbox_stuff
245 creat_xinitrc
246 jwm_config
247 creat_xsession
249 exit 0