slitaz-tools view tazbox/tazbox @ rev 595

Dev null when killing Xorg at boot
author Christophe Lincoln <pankso@slitaz.org>
date Mon May 16 22:19:25 2011 +0200 (2011-05-16)
parents b094a088e5d2
children fa3a1c65911d
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)")
41 EOT
42 }
44 # Su frontend GUI's
45 su_main() {
46 text=$(gettext "Slitaz admin password")
47 note=$(gettext "Please enter root password (default root) to execute:")
48 yad --title="Slitaz - su" --window-icon=$icon \
49 --width=520 --height=160 \
50 --text="<b>$text</b>\n$note\n$SU_CMD\n" \
51 --image="slitaz-menu" --image-on-top \
52 --center --on-top --form $PASSWD \
53 --field="`gettext "Password:"`:H" $CHECKED \
54 --field="`gettext "Autosave password"`:CHK"
55 }
57 su_error() {
58 text=$(gettext "Error: wrong password!")
59 yad --title="Slitaz - su error" --width=520 --height=60 \
60 --image="error" --image-on-top --center --on-top \
61 --text="\n\t<b>$text</b>" --button="gtk-close:1"
62 }
64 # User may press cancel on download.
65 cancel_dl() {
66 if [ "$?" == 1 ]; then
67 echo "CANCEL"
68 rm -f $DOWNLOADS/$(basename $url)
69 fi
70 }
72 # Output a command in a GTK window
73 output_command() {
74 yad --text-info --title="TazBox Output" --window-icon=$icon \
75 --geometry="560x210+0-24" --fore="#ffffff" --back="#000000"
76 }
78 # Logout GUI function
79 logout_main() {
80 text=$(gettext "<b>SliTaz Logout.</b> Please choose an action:")
81 yad --entry --title="SliTaz Logout" --window-icon=$icon \
82 --width=440 --height=140 --text="$text" \
83 --image="slitaz-menu" --image-on-top \
84 --center --on-top --entry-text \
85 "`gettext \"Close X session\"` : exit" \
86 "`gettext \"Reboot system\"` : reboot" \
87 "`gettext \"Shutdown system\"` : halt"
88 }
90 # Locale functions
91 locale_main() {
92 text=$(gettext "Language configuration")
93 db=/usr/share/i18n/locales
94 for locale in $(ls -1 $db | grep ^[a-z][a-z]_[A-Z][A-Z])
95 do
96 desc=$(grep ^title $db/$locale | cut -d '"' -f 2)
97 echo -e "$locale \n $desc"
98 done | \
99 yad --list --title="SliTaz locale" --window-icon=$icon \
100 --width=500 --height=380 --separator="" \
101 --center --sticky --on-top \
102 --image=preferences-desktop-locale --image-on-top \
103 --text="<b>$text</b>" --print-column=1 \
104 --column $(gettext "Name") --column $(gettext "Description")
105 }
107 locale() {
108 locale=$(locale_main)
109 # Deal with --button values
110 case $? in
111 1) exit 0 ;;
112 *) continue ;;
113 esac
114 # System language configuration.
115 [ "$locale" ] && tazlocale init $locale
116 }
118 # Keymap functions
119 keymap_main() {
120 text=$(gettext "Keyboard configuration")
121 tmp=/tmp/keymap.list
122 echo > $tmp
123 cd /usr/share/kbd/keymaps/i386
124 # We first need a list to sort and then use \n for Yad list.
125 for i in $(find *rty *rtz dvorak -name *.map.gz)
126 do
127 keymap=$(basename $i)
128 type=$(dirname $i)
129 echo -e "$keymap|$type" >> $tmp
130 done
131 for i in $(sort $tmp)
132 do
133 keymap=$(echo $i | cut -d "|" -f 1)
134 type=$(echo $i | cut -d "|" -f 2)
135 echo -e "${keymap%.map.gz} \n $type"
136 done | \
137 yad --list $opts --title="SliTaz keymap" --window-icon=$icon \
138 --width=500 --height=380 --separator="" \
139 --center --sticky --on-top \
140 --image=input-keyboard --image-on-top \
141 --text="<b>$text</b>" --print-column=1 \
142 --column $(gettext "Keymap") --column $(gettext "Type")
143 rm -f $tmp
144 }
146 keymap() {
147 keymap=$(keymap_main)
148 # Deal with --button values
149 case $? in
150 1) exit 0 ;;
151 *) continue ;;
152 esac
153 # System keymap configuration
154 [ "$keymap" ] && tazkeymap init $keymap
155 }
157 #
158 # Commands
159 #
160 case "$1" in
161 su)
162 # Keep command in an exported variable to be used by Yad. 4 arguments
163 # should be enuff: appname --opt --opt -v /dev/sda. Nothing to do if
164 # we are root.
165 test $(id -u) = 0 && exec $2 $3 $4 $5
166 export SU_CMD="$2 $3 $4 $5"
167 # Check if a password has been saved before launching main dialog
168 if [ -s $HOME/.config/slitaz/subox.conf ]; then
169 PASSWD=$(cat $HOME/.config/slitaz/subox.conf)
170 CHECKED="TRUE"
171 fi
172 # Display the main dialog (ask for password)
173 main=$(su_main)
174 # Deal with --button values and exit if cancelled to avoid erasing
175 # saved password.
176 case $? in
177 1) exit 0 ;;
178 *) continue ;;
179 esac
180 # Save or erase Autosaved password
181 if [ $(echo $main | cut -f2 -d"|") == "TRUE" ]; then
182 echo $main | cut -f 1 -d "|" > $HOME/.config/slitaz/subox.conf
183 chmod 0600 $HOME/.config/slitaz/subox.conf
184 else
185 cat /dev/null > $HOME/.config/slitaz/subox.conf
186 fi
187 # Try to login & execute. If password is wrong execute error dialog
188 echo $main | cut -f 1 -d "|" | su -c "$SU_CMD &" || su_error ;;
189 logout)
190 # Logout window with actions
191 main=`logout_main`
192 # Deal with --button values
193 case $? in
194 1) exit 0 ;;
195 *) continue ;;
196 esac
197 # Deal with $main values
198 case "$main" in
199 *exit) openbox --exit || jwm -exit ;;
200 *reboot) reboot ;;
201 *halt) poweroff ;;
202 esac ;;
203 out)
204 # Pipe a command into a GTK window
205 output_command ;;
206 out-dl)
207 # A tiny GTK window for Busybox wget output
208 url=$2
209 [ -d $DOWNLOADS ] || mkdir -p $DOWNLOADS
210 busybox wget -c -P $DOWNLOADS $url 2>1 | output_command
211 cancel_dl ;;
212 locale)
213 locale ;;
214 keymap)
215 keymap ;;
216 boot)
217 # This command is used at first boot to configure system.
218 Xorg -br -quiet -nolisten tcp :1 &
219 DISPLAY=:1 openbox &
220 locale
221 keymap
222 killall Xorg 2>/dev/null ;;
223 *)
224 usage ;;
225 esac
227 exit 0