slitaz-tools view tinyutils/subox @ rev 464

subox: can save and remember passwd
author Christophe Lincoln <pankso@slitaz.org>
date Wed Mar 24 22:03:29 2010 +0100 (2010-03-24)
parents 89e957d86a6e
children a8fe4b3aaf04
line source
1 #!/bin/sh
2 #
3 # Gtkdialog to execute program as root from a WM menu.
4 # (c) SliTaz GNU/Linux 2008-2010 - GNU gpl.
5 #
6 VERSION=20100324
8 # Usage.
9 if [ -z "$1" ]; then
10 echo "Slitaz subox version : $VERSION"
11 echo -e "\nUsage : subox program\n"
12 exit 0
13 fi
15 # Nothing to do if we are root
16 test $(id -u) = 0 && exec $1
18 # Include gettext helper script.
19 . /usr/bin/gettext.sh
21 # Export package name for gettext.
22 TEXTDOMAIN='subox'
23 export TEXTDOMAIN
25 # Keep command in an exported variable to be used by SU_DIALOG.
26 export SU_CMD=$1
28 # Main window and root password default entry set to 'root'.
29 SU_DIALOG='
30 <window title="Subox" skip_taskbar_hint="true">
31 <vbox>
33 <text use-markup="true">
34 <label>"
35 <b>SliTaz - Subox</b>"
36 </label>
37 </text>
38 <text wrap="true" width-chars="50">
39 <label>"'`gettext "
40 Please enter root password (default root) to execute :"`'
41 '$@'
42 "
43 </label>
44 </text>
46 <hbox>
47 <text use-markup="true">
48 <label>"'`gettext "<b>Admin password :</b>"`'"</label>
49 </text>
50 <entry visibility="false">'
52 # Check if we have a saved passwd.
53 if [ -s $HOME/.config/slitaz/subox.conf ]; then
54 PASSWD=`cat $HOME/.config/slitaz/subox.conf`
55 [ -n "$PASSWD" ] && SU_DIALOG="$SU_DIALOG <default>$PASSWD</default>"
56 fi
58 export SU_DIALOG=''${SU_DIALOG}'
59 <variable>PASSWD</variable>
60 </entry>
61 </hbox>
63 <hbox>
64 <checkbox>
65 <label>"'`gettext "Autosave password"`'"</label>
66 <variable>AUTOSAVE</variable>
67 <default>false</default>
68 </checkbox>
69 <button ok>
70 <action>echo $PASSWD | su -c "$SU_CMD" &</action>
71 <action>[ $AUTOSAVE == true ] && echo $PASSWD > '$HOME/.config/slitaz/subox.conf'</action>
72 <action>[ $AUTOSAVE == true ] && chmod 0600 '$HOME/.config/slitaz/subox.conf'</action>
73 <action type="closewindow">SU_DIALOG</action>
74 </button>
75 <button cancel></button>
76 </hbox>
78 </vbox>
79 </window>'
81 gtkdialog --center --program=SU_DIALOG > /dev/null
83 exit 0