slitaz-tools view tinyutils/tazx @ rev 118

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