slitaz-tools view tinyutils/tazx @ rev 98

Added tag 1.9.3 for changeset bcdf06f0074a
author Christophe Lincoln <pankso@slitaz.org>
date Mon Mar 10 20:43:55 2008 +0100 (2008-03-10)
parents b4d5ddf5a00d
children 413b0181d008
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 'tazx' to configure your default WM: tazx e17
158 #
159 if [ -z $1 ]; then
160 1=jwm
161 fi
163 case $1 in
164 e17|enlightenment_start)
165 exec enlightenment_start
166 ;;
167 openbox|openbox-session)
168 exec openbox-session
169 ;;
170 jwm|*)
171 lxpanel &
172 exec jwm
173 ;;
174 esac
175 EOF
176 }
178 # ~/.xinitrc for slim login.
179 creat_xinitrc()
180 {
181 FILE=$HOME/.xinitrc
182 xinitrc_sample
183 # Set default WM.
184 sed -i s/'1=jwm'/"1=$WM"/ $FILE
185 # In Live mode hacker needs a xinitrc, since tazx
186 # is executed only by root.
187 if [ ! -f /home/hacker/.xinitrc ]; then
188 FILE=/home/hacker/.xinitrc
189 xinitrc_sample
190 chown hacker.hacker $FILE
191 fi
192 }
194 # Copy a JWM system config if any present in user home.
195 jwm_config()
196 {
197 JWM_CONFIG=$HOME/.jwmrc
198 if [ ! -f "$JWM_CONFIG" ]; then
199 cp /etc/jwm/system.jwmrc $JWM_CONFIG
200 fi
201 change_jwm_background
202 # In Live mode hacker JWM config dose not exist, this is
203 # because tazx is executed at boot time by root.
204 if [ ! -f "/home/hacker/.jwmrc" ]; then
205 JWM_CONFIG=/home/hacker/.jwmrc
206 cp /etc/jwm/system.jwmrc $JWM_CONFIG
207 change_jwm_background
208 chown hacker.hacker $JWM_CONFIG
209 fi
210 }
212 # Creat ~/.xsession to keep the configuration selected (used
213 # only by startx, Slim login manager use .xinitrc).
214 creat_xsession()
215 {
216 cat > $HOME/.xsession << _EOF_
217 # ~/.xsession: Start X window session manually on your system (startx).
218 #
219 $XSERVER -ac -shadow $XSEVER_OPTS -screen $NEW_SCREEN -mouse $MOUSE &
220 #xterm &
221 #xpad &
222 #lxpanel &
223 exec $WM
224 _EOF_
225 chmod 700 $HOME/.xsession
226 }
228 ###################
229 # Tazx sequence #
230 ###################
232 [ -n "$NEW_SCREEN" ] || screen_config_dialog
233 slim_config
234 e17_stuff
235 openbox_stuff
236 creat_xinitrc
237 jwm_config
238 creat_xsession
240 exit 0