slitaz-tools view tinyutils/tazx @ rev 67

Improved sed on slim.conf (thanks Pascal)
author Christophe Lincoln <pankso@slitaz.org>
date Sat Feb 23 00:54:38 2008 +0100 (2008-02-23)
parents b7cf20bb05db
children ee9bb9111f35
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 # 20080222 <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 # /etc/X11/screen.conf exist for Live mode, if this file dos not
100 # exist tazx is executed at boot time.
101 mkdir -p /etc/X11
102 echo "SCREEN=$NEW_SCREEN" > /etc/X11/screen.conf ;;
103 esac
104 }
106 # Slim config if root.
107 slim_config()
108 {
109 if test $(id -u) = 0; then
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 "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 # ~/.xinitrc for slim login.
130 creat_xinitrc()
131 {
132 echo "$WM" > $HOME/.xinitrc
133 if [ ! -f /home/hacker/.xinitrc ]; then
134 echo "$WM" > /home/hacker/.xinitrc
135 chown hacker.hacker /home/hacker/.xinitrc
136 fi
137 }
139 # Copy a JWM system config if any present in user home.
140 jwm_config()
141 {
142 if [ ! -f "$HOME/.jwmrc" ]; then
143 cp /etc/jwm/system.jwmrc $HOME/.jwmrc
144 JWM_CONFIG=$HOME/.jwmrc
145 change_jwm_background
146 fi
147 # In Live mode hacker JWM config dose not exist, this is
148 # because tazx is executed at boot time by root.
149 if [ ! -f "/home/hacker/.jwmrc" ]; then
150 cp /etc/jwm/system.jwmrc /home/hacker/.jwmrc
151 JWM_CONFIG=/home/hacker/.jwmrc
152 change_jwm_background
153 chown hacker.hacker $JWM_CONFIG
154 fi
155 }
157 # Creat ~/.xsession to keep the configuration selected (used
158 # only by startx, Slim login manager use .xinitrc).
159 creat_xsession()
160 {
161 cat > $HOME/.xsession << _EOT_
162 # ~/.xsession: Start X window session on your system.
163 #
164 $XSERVER -ac -shadow $XSEVER_OPTS -screen $NEW_SCREEN -mouse $MOUSE &
165 #xterm &
166 #xpad &
167 exec $WM
168 _EOT_
169 chmod 700 $HOME/.xsession
170 }
172 # Console message.
173 console_message()
174 {
175 echo ""
176 echo "X server : $XSERVER"
177 echo "Screen : $NEW_SCREEN"
178 echo "Exec WM : $WM"
179 echo ""
180 }
182 ###################
183 # Tazx sequence #
184 ###################
186 screen_config_dialog
187 slim_config
188 e17_stuff
189 creat_xinitrc
190 jwm_config
191 creat_xsession
192 console_message
194 exit 0