slitaz-tools view tazbox/tazbox @ rev 608

Tiny edits
author Paul Issott <paul@slitaz.org>
date Wed Jun 01 19:27:03 2011 +0100 (2011-06-01)
parents fa3a1c65911d
children 4365931d7dd2
line source
1 #!/bin/sh
2 #
3 # SliTaz tiny GUI boxes for the desktop (su, logout, locale, etc)
4 # and as usual, please: KISS
5 #
6 # Note: $(gettext "text") doesn't work inside Yad so use `gettext \"text\"`
7 #
8 # Copyright (C) 2011 SliTaz GNU/linux - GNU gpl v3
9 # - Christophe Lincoln <pankso@slitaz.org>
10 #
12 # Download dir (may be in a config file)
13 DOWNLOADS=$HOME/Downloads
15 # Internationalization
16 . /usr/bin/gettext.sh
17 TEXTDOMAIN='tazbox'
18 export TEXTDOMAIN
20 # Icons for most windows
21 icon=/usr/share/pixmaps/slitaz-menu.png
23 #
24 # Functions
25 #
27 usage() {
28 cat << EOT
30 $(gettext "Usage:") $(basename $0) [command]
32 $(gettext "Commands:")
33 usage $(gettext "Display this short help usage")
34 su $(gettext "Execute a command as super-user")
35 logout $(gettext "Desktop logout box with actions")
36 out $(gettext "Pipe a command output into a GTK window")
37 out-dl $(gettext "Pipe Wget output into a GTK window")
38 locale $(gettext "Configure system language (root)")
39 keymap $(gettext "Configure system keymap (root)")
40 tz $(gettext "Configure system timezone (root)")
42 EOT
43 }
45 # Su frontend GUI's
46 su_main() {
47 text=$(gettext "Slitaz admin password")
48 note=$(gettext "Please enter root password (default root) to execute:")
49 yad --title="Slitaz - su" --window-icon=$icon \
50 --width=520 --height=160 \
51 --text="<b>$text</b>\n$note\n$SU_CMD\n" \
52 --image="slitaz-menu" --image-on-top \
53 --center --on-top --form $PASSWD \
54 --field="`gettext "Password:"`:H" $CHECKED \
55 --field="`gettext "Autosave password"`:CHK"
56 }
58 su_error() {
59 text=$(gettext "Error: wrong password!")
60 yad --title="Slitaz - su error" --width=520 --height=60 \
61 --image="error" --image-on-top --center --on-top \
62 --text="\n\t<b>$text</b>" --button="gtk-close:1"
63 }
65 # User may press cancel on download.
66 cancel_dl() {
67 if [ "$?" == 1 ]; then
68 echo "CANCEL"
69 rm -f $DOWNLOADS/$(basename $url)
70 fi
71 }
73 # Output a command in a GTK window
74 output_command() {
75 yad --text-info --title="TazBox Output" --window-icon=$icon \
76 --geometry="560x210+0-24" --fore="#ffffff" --back="#000000"
77 }
79 # Logout GUI function
80 logout_main() {
81 text=$(gettext "<b>SliTaz Logout.</b> Please choose an action:")
82 yad --entry --title="SliTaz Logout" --window-icon=$icon \
83 --width=440 --height=140 --text="$text" \
84 --image="slitaz-menu" --image-on-top \
85 --center --on-top --entry-text \
86 "`gettext \"Close X session\"` : exit" \
87 "`gettext \"Reboot system\"` : reboot" \
88 "`gettext \"Shutdown system\"` : halt"
89 }
91 # Locale functions
92 locale_main() {
93 text=$(gettext "Language configuration")
94 db=/usr/share/i18n/locales
95 for locale in $(ls -1 $db | grep ^[a-z][a-z]_[A-Z][A-Z])
96 do
97 desc=$(grep ^title $db/$locale | cut -d '"' -f 2)
98 echo -e "$locale \n $desc"
99 done | \
100 yad --list --title="SliTaz locale" --window-icon=$icon \
101 --width=500 --height=380 --separator="" \
102 --center --sticky --on-top \
103 --image=preferences-desktop-locale --image-on-top \
104 --text="<b>$text</b>" --print-column=1 \
105 --column $(gettext "Name") --column $(gettext "Description")
106 }
108 locale() {
109 locale=$(locale_main)
110 # Deal with --button values
111 case $? in
112 1) exit 0 ;;
113 *) continue ;;
114 esac
115 # System language configuration.
116 [ "$locale" ] && tazlocale init $locale
117 }
119 # Keymap functions
120 keymap_main() {
121 text=$(gettext "Keyboard configuration")
122 tmp=/tmp/keymap.list
123 echo > $tmp
124 cd /usr/share/kbd/keymaps/i386
125 # We first need a list to sort and then use \n for Yad list.
126 for i in $(find *rty *rtz dvorak -name *.map.gz)
127 do
128 keymap=$(basename $i)
129 type=$(dirname $i)
130 echo -e "$keymap|$type" >> $tmp
131 done
132 for i in $(sort $tmp)
133 do
134 keymap=$(echo $i | cut -d "|" -f 1)
135 type=$(echo $i | cut -d "|" -f 2)
136 echo -e "${keymap%.map.gz} \n $type"
137 done | \
138 yad --list $opts --title="SliTaz keymap" --window-icon=$icon \
139 --width=500 --height=380 --separator="" \
140 --center --sticky --on-top \
141 --image=input-keyboard --image-on-top \
142 --text="<b>$text</b>" --print-column=1 \
143 --column $(gettext "Keymap") --column $(gettext "Type")
144 rm -f $tmp
145 }
147 keymap() {
148 keymap=$(keymap_main)
149 # Deal with --button values
150 case $? in
151 1) exit 0 ;;
152 *) continue ;;
153 esac
154 # System keymap configuration
155 [ "$keymap" ] && tazkeymap init $keymap
156 }
158 # TZ functions
159 tz_main() {
160 text=$(gettext "TimeZone Configuration")
161 zi="/usr/share/zoneinfo/"
162 for t in $(find $zi -type f | sed s,$zi,,g)
163 do
164 echo -e "$t"
165 done | \
166 yad --list --title="SliTaz TZ" --window-icon=$icon \
167 --width=500 --height=380 --separator="" \
168 --center --sticky --on-top \
169 --image=preferences-desktop-locale --image-on-top \
170 --text="<b>$text</b>" --print-column=1 \
171 --column $(gettext "Name")
172 }
174 tz() {
175 timezone=$(tz_main)
176 case $? in
177 1) exit 0 ;;
178 *) continue ;;
179 esac
180 [ "$timezone" ] && echo $timezone > /etc/TZ
181 }
183 #
184 # Commands
185 #
186 case "$1" in
187 su)
188 # Keep command in an exported variable to be used by Yad. 4 arguments
189 # should be enuff: appname --opt --opt -v /dev/sda. Nothing to do if
190 # we are root.
191 test $(id -u) = 0 && exec $2 $3 $4 $5
192 export SU_CMD="$2 $3 $4 $5"
193 # Check if a password has been saved before launching main dialog
194 if [ -s $HOME/.config/slitaz/subox.conf ]; then
195 PASSWD=$(cat $HOME/.config/slitaz/subox.conf)
196 CHECKED="TRUE"
197 fi
198 # Display the main dialog (ask for password)
199 main=$(su_main)
200 # Deal with --button values and exit if cancelled to avoid erasing
201 # saved password.
202 case $? in
203 1) exit 0 ;;
204 *) continue ;;
205 esac
206 # Save or erase Autosaved password
207 if [ $(echo $main | cut -f2 -d"|") == "TRUE" ]; then
208 echo $main | cut -f 1 -d "|" > $HOME/.config/slitaz/subox.conf
209 chmod 0600 $HOME/.config/slitaz/subox.conf
210 else
211 cat /dev/null > $HOME/.config/slitaz/subox.conf
212 fi
213 # Try to login & execute. If password is wrong execute error dialog
214 echo $main | cut -f 1 -d "|" | su -c "$SU_CMD &" || su_error ;;
215 logout)
216 # Logout window with actions
217 main=`logout_main`
218 # Deal with --button values
219 case $? in
220 1) exit 0 ;;
221 *) continue ;;
222 esac
223 # Deal with $main values
224 case "$main" in
225 *exit) openbox --exit || jwm -exit ;;
226 *reboot) reboot ;;
227 *halt) poweroff ;;
228 esac ;;
229 out)
230 # Pipe a command into a GTK window
231 output_command ;;
232 out-dl)
233 # A tiny GTK window for Busybox wget output
234 url=$2
235 [ -d $DOWNLOADS ] || mkdir -p $DOWNLOADS
236 busybox wget -c -P $DOWNLOADS $url 2>1 | output_command
237 cancel_dl ;;
238 locale)
239 locale ;;
240 keymap)
241 keymap ;;
242 tz)
243 tz ;;
244 boot)
245 # This command is used at first boot to configure system.
246 Xorg -br -quiet -nolisten tcp :1 &
247 DISPLAY=:1 openbox &
248 locale
249 keymap
250 killall Xorg 2>/dev/null ;;
251 *)
252 usage ;;
253 esac
255 exit 0