#!/bin/sh
# launch something as root
# 
# (c) Eko M. Budi, 2004
# (c) Vector Linux, 2004
#
# Released under GNU GPL

vdir=$(dirname $0)

. $vdir/vasm-functions

TITLE=$1
shift
COMMANDS="$@"
#echo $TITLE
#echo $COMMANDS

if [ -z "$DISPLAY" ]; then
    echoc "Program $TITLE needs root privilege." cyan
    su root -c $COMMANDS
elif which kdesu &>/dev/null; then
    kdesu --caption "$TITLE" -c "$COMMANDS"
elif which gksu &>/dev/null; then
    gksu "$COMMANDS"
else
    passwordbox "This program needs root privilege. Please enter the password:" "$TITLE"
    result=$?
    if [ $result = 0 ]; then
	USERPASS1="`cat $freply`"
	xhost +si:localuser:root &> /dev/null
	$vdir/superx "$USERPASS1" "$COMMANDS" > /dev/null
	result=$?
	xhost -si:localuser:root &> /dev/null
	if [ $result != 0 ]; then 
	    infobox "Wrong password, cannot run $TITLE"
	    sleep 2
	fi
    fi
fi

clean_exit $result

