#! /bin/sh
#
# Gtkdialog to execute program as root from a WM menu.
# - SliTaz GNU/Linux 2008.
#
VERSION=20080113

# Usage.
if [ -z "$1" ]; then
    echo "Slitaz subox version : $VERSION"
    echo -e "\nUsage : subox program\n"
    exit 0
fi

# Nothing to do if we are root
test $(id -u) = 0 && exec $1

# Keep command in an exported variable to be used by SU_DIALOG.
export SU_CMD=$@

# Main window and root password default entry set to 'root'.
export SU_DIALOG='
<window title="Subox">
  <vbox>

    <text use-markup="true">
      <label>"
<b>SliTaz - Subox</b>"
      </label>
    </text>
    <text wrap="true" width-chars="48">
      <label>"
Please enter root password to execute :"
      </label>
    </text>
    <text>
      <input>echo $SU_CMD</input>
    </text>

    <hbox>
      <text use-markup="true">
        <label>"<b>Root password :</b>"</label>
      </text>
      <entry visibility="false">
        <default>root</default>
        <variable>PASSWD</variable>
      </entry>
    </hbox>

    <hbox>
      <button ok>
        <action>echo $PASSWD | su -c "$SU_CMD" &</action>
        <action type="closewindow">SU_DIALOG</action>
      </button>
      <button cancel></button>
    </hbox>

  </vbox>
</window>
'

gtkdialog --center --program=SU_DIALOG
exit 0
