slitaz-tools view tinyutils/subox @ rev 501

fix password autosave that remain see http://labs.slitaz.org/issues/207
author frederic guilbault <fredericguilbault@live.ca>
date Tue Oct 19 22:02:18 2010 +0000 (2010-10-19)
parents cd27820e187d
children b9d5184b7527
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>" && AUTO_SAVED_PASSWD=true
56 else {AUTO_SAVED_PASSWD=false}
57 fi
59 export SU_DIALOG=''${SU_DIALOG}'
60 <variable>PASSWD</variable>
61 </entry>
62 </hbox>
64 <hbox>
65 <checkbox>
66 <variable>AUTOSAVE</variable>'
68 if [ $AUTO_SAVED_PASSWD = "true" ]
69 then SU_DIALOG="$SU_DIALOG <default>true</default>"
70 else SU_DIALOG="$SU_DIALOG <default>false</default>"
71 fi
73 export SU_DIALOG=''${SU_DIALOG}'
74 <default>false</default>
75 </checkbox>
76 <button ok>
77 <action>echo $PASSWD | su -c "$SU_CMD" &</action>
78 <action>[ $AUTOSAVE == true ] && echo $PASSWD > '$HOME/.config/slitaz/subox.conf'</action>
79 <action>[ $AUTOSAVE == true ] && chmod 0600 '$HOME/.config/slitaz/subox.conf'</action>
80 <action type="closewindow">SU_DIALOG</action>
81 <action>[ $AUTOSAVE == false ] && cat /dev/null > '$HOME/.config/slitaz/subox.conf'</action>
82 </button>
83 <button cancel></button>
84 </hbox>
86 </vbox>
87 </window>'
89 gtkdialog --center --program=SU_DIALOG > /dev/null
91 exit 0