#!/bin/sh
#
# ssadm - frontend for all SunScreen ADMinistration via the command line
#
# @(#)ssadm.sh	1.5 99/04/23 Sun Microsystems, Inc.
#
# We invoke the Java ssadm program if it is there and the -raw option is not
# specified.  The Java ssadm program handles character set translation and
# communication with a remote SunScreen for remote administration.
#
# If we can't find the Java ssadm class or if -raw is specified, we just
# exec(2) the backend program.  This won't do remote administration, and it
# won't handle the general case of arbitrary locale and character encodings but
# it should at least allow basic local installation and/or recovery from
# disasters.
#

raw=false
ssdir=/opt/SUNWicg/SunScreen
classdir=${ssdir}/admin
package=com.sun.sunscreen.internal.ssadm
packagedir=com/sun/sunscreen/internal/ssadm

if [ "$1" = "-raw" ]
then
    shift
    raw=true
elif [ ! -s ${classdir}/${packagedir}/Client.class ]
then
    raw=true
fi

if $raw
then
    if [ "$1" = "-n" ]
    then
	shift
	exec </dev/null
    fi
    case "$1" in
    lib/*)	exec "${ssdir}/$@";;
	*)	exec "${ssdir}/ssadm/$@";;
    esac
fi

if [ -t 0 ] && [ -t 1 ] || [ "${SSADM_ISATTY:-0}" -gt 0 ]
then isatty=-y
else isatty=
fi

if [ "${LANG:-C}" != "C" ]
then lang="-l $LANG"
else lang=
fi

if [ -n "$SSADM_USER" ] || SSADM_USER=`/bin/logname`
then user="-U $SSADM_USER"
else user=
fi

if [ -n "$SSADM_TICKET_FILE" ]
then ticket="-F $SSADM_TICKET_FILE"
fi

CLASSPATH=$classdir
export CLASSPATH
exec java ${package}.Client $isatty $lang $user $ticket ${1+"$@"}
