#!/bin/ksh
# runs a given cmdline su'ed as root if necessary.  
#  @(#)rootrun	1.7 98/08/13 19:01:14  

cmd="$1"
prompt="$2"
exitval=0

# Don't need JAVA_HOME here, we already know which java to use.
unset JAVA_HOME

set `/bin/id`
if [ $1 != "uid=0(root)" ]; then

    # give access to display
    /usr/openwin/bin/xhost +$host_name 1>/dev/null;

    # try a maximum of 3 times
    for i in 1 2 3 ; do
	echo "$prompt"
	/usr/bin/su root -c "$cmd" 
	exitval=$?
	if [ "$exitval" != 1 ] ; then
	    break;
	fi
    done

    # remove access to display
    /usr/openwin/bin/xhost -$host_name 1>/dev/null;
else
    # user is root.. run it directly
    ksh -c "$cmd"
    exitval=$?
fi

# exit with underlying return code
exit $exitval
