slitaz-tools view tinyutils/tazx @ rev 74

Tazx: NEW_SCREEN can be predefined
author Pascal Bellard <pascal.bellard@slitaz.org>
date Mon Feb 25 22:00:27 2008 +0000 (2008-02-25)
parents 0fd5a7bdf689
children 1437b2cd2616
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 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 # Sample xinitrc for user (WM can be specified with F1 at slim login).
130 xinitrc_sample()
131 {
132 cat > $FILE << "EOF"
133 # ~/.xinitrc: Executed by slim login manager to startx X session.
134 #
135 case $1 in
136 e17|enlightenment_start)
137 exec enlightenment_start
138 ;;
139 *)
140 exec jwm
141 ;;
142 esac
143 EOF
144 }
146 # ~/.xinitrc for slim login.
147 creat_xinitrc()
148 {
149 FILE=$HOME/.xinitrc
150 xinitrc_sample
151 # In Live mode hacker needs a xinitrc, since tazx
152 # is executed only by root.
153 if [ ! -f /home/hacker/.xinitrc ]; then
154 FILE=/home/hacker/.xinitrc
155 xinitrc_sample
156 chown hacker.hacker $FILE
157 fi
158 }
160 # Copy a JWM system config if any present in user home.
161 jwm_config()
162 {
163 if [ ! -f "$HOME/.jwmrc" ]; then
164 cp /etc/jwm/system.jwmrc $HOME/.jwmrc
165 JWM_CONFIG=$HOME/.jwmrc
166 change_jwm_background
167 fi
168 # In Live mode hacker JWM config dose not exist, this is
169 # because tazx is executed at boot time by root.
170 if [ ! -f "/home/hacker/.jwmrc" ]; then
171 cp /etc/jwm/system.jwmrc /home/hacker/.jwmrc
172 JWM_CONFIG=/home/hacker/.jwmrc
173 change_jwm_background
174 chown hacker.hacker $JWM_CONFIG
175 fi
176 }
178 # Creat ~/.xsession to keep the configuration selected (used
179 # only by startx, Slim login manager use .xinitrc).
180 creat_xsession()
181 {
182 cat > $HOME/.xsession << _EOF_
183 # ~/.xsession: Start X window session manually on your system (startx).
184 #
185 $XSERVER -ac -shadow $XSEVER_OPTS -screen $NEW_SCREEN -mouse $MOUSE &
186 #xterm &
187 #xpad &
188 exec $WM
189 _EOF_
190 chmod 700 $HOME/.xsession
191 }
193 ###################
194 # Tazx sequence #
195 ###################
197 [ -n "$NEW_SECREEN" ] || screen_config_dialog
198 slim_config
199 e17_stuff
200 creat_xinitrc
201 jwm_config
202 creat_xsession
204 exit 0