#!/bin/sh
#Barry Kauler 2011, GPL3 (/usr/share/doc/legal)
#specified in /etc/sudoers or /etc/sudo.conf, gui-helper for sudo. (path compiled-in to my sudo PET)
#110513 display name of app that is requesting to run.
#120201 rodin.s: internationalized.

export TEXTDOMAIN=askpass
export OUTPUT_CHARSET=UTF-8

PSALL="`ps`"
CALLEDAPP="`echo "$PSALL" | grep -o ' sudo \-A .*' | tr -s ' ' | cut -f 4 -d ' '`"
if [ "$CALLEDAPP" ];then
 INSERTMSG="    <text><label>$(gettext 'This application wants to run:')</label></text>
    <text><label>${CALLEDAPP}</label></text>
    <text><label>$(gettext 'The administrator password is required:')</label></text>
"
else
 INSERTMSG="<text><label>$(gettext 'Please enter the administrator password required to run this application:')</label></text>"
fi

if [ $DISPLAY ];then
 export ASKDIALOG="
<window title=\"AskPass\" decorated=\"false\" window_position=\"1\" skip_taskbar_hint=\"true\">
  <vbox>
  <frame>
    ${INSERTMSG}
    <entry visible_char=\"x\" visibility=\"false\"  width_chars=\"25\">
      <variable>ADMINPASSWORD</variable>
    </entry>

    <hbox>
     <button ok></button>
    </hbox>
  </frame>
  </vbox>
</window>
"
 RETVAL="`gtkdialog3 --program=ASKDIALOG 2>/dev/null`"
 eval "$RETVAL"
else
 echo >/dev/console
 echo -n "$(gettext 'Type admin password required to run this app:') " >/dev/console
 read -t 30 ADMINPASSWORD
 [ "$ADMINPASSWORD" = "" ] && echo '...failed' >/dev/console
fi

#echo "$RETVAL"

echo "$ADMINPASSWORD" #return password to sudo.
###END###
