slitaz-tools view tazbox/tazbox @ rev 625

Gettextize setmixer and make pot
author Christophe Lincoln <pankso@slitaz.org>
date Tue Jun 14 22:47:24 2011 +0200 (2011-06-14)
parents 4365931d7dd2
children 21047e4243e0
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 # some constants to be used inside functions
24 tmp="/tmp/keymap.list"
25 db="/usr/share/i18n/locales"
26 zi="/usr/share/zoneinfo/"
28 #
29 # Functions
30 #
32 usage() {
33 cat << EOT
35 $(gettext "Usage:") $(basename $0) [command]
37 $(gettext "Commands:")
38 usage $(gettext "Display this short help usage")
39 su $(gettext "Execute a command as super-user")
40 logout $(gettext "Desktop logout box with actions")
41 out $(gettext "Pipe a command output into a GTK window")
42 out-dl $(gettext "Pipe Wget output into a GTK window")
43 locale $(gettext "Configure system language (root)")
44 keymap $(gettext "Configure system keymap (root)")
45 tz $(gettext "Configure system timezone (root)")
46 setup $(gettext "System initial setup (locale, keymap & timezone)")
48 EOT
49 }
51 # Su frontend GUI's
52 su_main() {
53 text=$(gettext "Slitaz admin password")
54 note=$(gettext "Please enter root password (default root) to execute:")
55 yad --title="Slitaz - su" --window-icon=$icon \
56 --width=520 --height=160 \
57 --text="<b>$text</b>\n$note\n$SU_CMD\n" \
58 --image="slitaz-menu" --image-on-top \
59 --center --on-top --form $PASSWD \
60 --field="`gettext "Password:"`:H" $CHECKED \
61 --field="`gettext "Autosave password"`:CHK"
62 }
64 su_error() {
65 text=$(gettext "Error: wrong password!")
66 yad --title="Slitaz - su error" --width=520 --height=60 \
67 --image="error" --image-on-top --center --on-top \
68 --text="\n\t<b>$text</b>" --button="gtk-close:1"
69 }
71 # User may press cancel on download.
72 cancel_dl() {
73 if [ "$?" == 1 ]; then
74 echo "CANCEL"
75 rm -f $DOWNLOADS/$(basename $url)
76 fi
77 }
79 # Output a command in a GTK window
80 output_command() {
81 yad --text-info --title="TazBox Output" --window-icon=$icon \
82 --geometry="560x210+0-24" --fore="#ffffff" --back="#000000"
83 }
85 # Logout GUI function
86 logout_main() {
87 text=$(gettext "<b>SliTaz Logout.</b> Please choose an action:")
88 yad --entry --title="SliTaz Logout" --window-icon=$icon \
89 --width=440 --height=140 --text="$text" \
90 --image="slitaz-menu" --image-on-top \
91 --center --on-top --entry-text \
92 "`gettext \"Close X session\"` : exit" \
93 "`gettext \"Reboot system\"` : reboot" \
94 "`gettext \"Shutdown system\"` : halt"
95 }
97 # Generate keymap list
98 gen_kmap_list() {
99 echo > $tmp
100 cd /usr/share/kbd/keymaps/i386
101 # We first need a list to sort and then use \n for Yad list.
102 for i in $(find *rty *rtz dvorak -name *.map.gz)
103 do
104 keymap=$(basename $i)
105 type=$(dirname $i)
106 echo -e "$keymap|$type" >> $tmp
107 done
108 }
110 # Initial Config functions
111 setup_main() {
112 gen_kmap_list
113 title=$(gettext "SliTaz Initial Setup")
114 message=$(gettext "\n<big>Here you can set your preferences\nfor <b>locale, keymap and timezone</b></big>\n\n")
115 locale=$(ls -1 $db | grep ^[a-z][a-z]_[A-Z][A-Z] | tr "\n" "!")
116 keymap=$(cat $tmp | cut -d. -f1 | sort | tr "\n" "!")
117 timezone=$(find $zi -type f | sed s,$zi,,g | tr "\n" "!")
118 yad --width=500 --height=380 \
119 --image=$icon --title="$title" --form --text="$message" \
120 --field "Locale:CB" \
121 --field "Keymap:CB" \
122 --field "Timezone:CB" \
123 $locale \ $keymap \ $timezone
124 }
126 setup() {
127 choices=$(setup_main)
128 locale=$(echo $choices | cut -d"|" -f1)
129 keymap=$(echo $choices | cut -d"|" -f2)
130 timezone=$(echo $choices | cut -d"|" -f3)
131 [ $locale ] && tazlocale init $locale
132 [ $keymap ] && tazkeymap init $keymap
133 [ $timezone ] && echo $timezone > /etc/TZ
134 }
136 # Locale functions
137 locale_main() {
138 text=$(gettext "Language configuration")
139 for locale in $(ls -1 $db | grep ^[a-z][a-z]_[A-Z][A-Z])
140 do
141 desc=$(grep ^title $db/$locale | cut -d '"' -f 2)
142 echo -e "$locale \n $desc"
143 done | \
144 yad --list --title="SliTaz locale" --window-icon=$icon \
145 --width=500 --height=380 --separator="" \
146 --center --sticky --on-top \
147 --image=preferences-desktop-locale --image-on-top \
148 --text="<b>$text</b>" --print-column=1 \
149 --column $(gettext "Name") --column $(gettext "Description")
150 }
152 locale() {
153 locale=$(locale_main)
154 # Deal with --button values
155 case $? in
156 1) exit 0 ;;
157 *) continue ;;
158 esac
159 # System language configuration.
160 [ "$locale" ] && tazlocale init $locale
161 }
163 # Keymap functions
164 keymap_main() {
165 gen_kmap_list
166 text=$(gettext "Keyboard configuration")
167 for i in $(sort $tmp)
168 do
169 keymap=$(echo $i | cut -d "|" -f 1)
170 type=$(echo $i | cut -d "|" -f 2)
171 echo -e "${keymap%.map.gz} \n $type"
172 done | \
173 yad --list $opts --title="SliTaz keymap" --window-icon=$icon \
174 --width=500 --height=380 --separator="" \
175 --center --sticky --on-top \
176 --image=input-keyboard --image-on-top \
177 --text="<b>$text</b>" --print-column=1 \
178 --column $(gettext "Keymap") --column $(gettext "Type")
179 rm -f $tmp
180 }
182 keymap() {
183 keymap=$(keymap_main)
184 # Deal with --button values
185 case $? in
186 1) exit 0 ;;
187 *) continue ;;
188 esac
189 # System keymap configuration
190 [ "$keymap" ] && tazkeymap init $keymap
191 }
193 # TZ functions
194 tz_main() {
195 text=$(gettext "TimeZone Configuration")
196 for t in $(find $zi -type f | sed s,$zi,,g)
197 do
198 echo -e "$t"
199 done | \
200 yad --list --title="SliTaz TZ" --window-icon=$icon \
201 --width=500 --height=380 --separator="" \
202 --center --sticky --on-top \
203 --image=preferences-desktop-locale --image-on-top \
204 --text="<b>$text</b>" --print-column=1 \
205 --column $(gettext "Name")
206 }
208 tz() {
209 timezone=$(tz_main)
210 case $? in
211 1) exit 0 ;;
212 *) continue ;;
213 esac
214 [ "$timezone" ] && echo $timezone > /etc/TZ
215 }
217 #
218 # Commands
219 #
220 case "$1" in
221 su)
222 # Keep command in an exported variable to be used by Yad. 4 arguments
223 # should be enuff: appname --opt --opt -v /dev/sda. Nothing to do if
224 # we are root.
225 test $(id -u) = 0 && exec $2 $3 $4 $5
226 export SU_CMD="$2 $3 $4 $5"
227 # Check if a password has been saved before launching main dialog
228 if [ -s $HOME/.config/slitaz/subox.conf ]; then
229 PASSWD=$(cat $HOME/.config/slitaz/subox.conf)
230 CHECKED="TRUE"
231 fi
232 # Display the main dialog (ask for password)
233 main=$(su_main)
234 # Deal with --button values and exit if cancelled to avoid erasing
235 # saved password.
236 case $? in
237 1) exit 0 ;;
238 *) continue ;;
239 esac
240 # Save or erase Autosaved password
241 if [ $(echo $main | cut -f2 -d"|") == "TRUE" ]; then
242 echo $main | cut -f 1 -d "|" > $HOME/.config/slitaz/subox.conf
243 chmod 0600 $HOME/.config/slitaz/subox.conf
244 else
245 cat /dev/null > $HOME/.config/slitaz/subox.conf
246 fi
247 # Try to login & execute. If password is wrong execute error dialog
248 echo $main | cut -f 1 -d "|" | su -c "$SU_CMD &" || su_error ;;
249 logout)
250 # Logout window with actions
251 main=`logout_main`
252 # Deal with --button values
253 case $? in
254 1) exit 0 ;;
255 *) continue ;;
256 esac
257 # Deal with $main values
258 case "$main" in
259 *exit) openbox --exit || jwm -exit ;;
260 *reboot) reboot ;;
261 *halt) poweroff ;;
262 esac ;;
263 out)
264 # Pipe a command into a GTK window
265 output_command ;;
266 out-dl)
267 # A tiny GTK window for Busybox wget output
268 url=$2
269 [ -d $DOWNLOADS ] || mkdir -p $DOWNLOADS
270 busybox wget -c -P $DOWNLOADS $url 2>1 | output_command
271 cancel_dl ;;
272 locale)
273 locale ;;
274 keymap)
275 keymap ;;
276 tz)
277 tz ;;
278 setup)
279 setup ;;
280 boot)
281 # This command is used at first boot to configure system.
282 Xorg -br -quiet -nolisten tcp :1 &
283 DISPLAY=:1 openbox &
284 locale
285 keymap
286 killall Xorg 2>/dev/null ;;
287 *)
288 usage ;;
289 esac
291 exit 0