#!/bin/sh
#
#     @(#)hotjava.sh	1.48 97/10/13
# 
# Copyright 1996-1997 Sun Microsystems, Inc.
#

#
# Determine HOTJAVA_HOME
#

if [ -z "${HOTJAVA_HOME}" ] ; then
    HOTJAVA_HOME=`dirname $0`
    HOTJAVA_HOME=`cd ${HOTJAVA_HOME}/.. ; /bin/pwd`
    echo "HOTJAVA_HOME is set to ${HOTJAVA_HOME}"
fi

if [ ! -d "${HOTJAVA_HOME}" ] ; then
    echo "Invalid HOTJAVA_HOME: ${HOTJAVA_HOME}" 1>&2 
    exit 1
fi

if [ ! -r "${HOTJAVA_HOME}/lib/hotjava.properties" ] ; then
    echo "Could not read properties file: ${HOTJAVA_HOME}/lib/hotjava.properties" 1>&2 
    exit 1
fi

if [ ! -r "${HOTJAVA_HOME}/lib/hotjavaBrowser.properties" ]; then
    echo "Could not read properties file: ${HOTJAVA_HOME}/lib/hotjavaBrowser.properties" 1>&2
    exit 1
fi

arch=`uname -p`
# arch is used for the ssl libraries

if [ -n "${JRE_HOME}" ] ; then
    if [ ! -d "${JRE_HOME}" ] ; then
        echo "Invalid JRE_HOME: ${JRE_HOME}" 1>&2
	exit 1
    fi
    rthome="${JRE_HOME}"
else
    rthome="${HOTJAVA_HOME}/runtime"
fi


if [ -n "${JDK_HOME}" ] ; then
    if [ ! -d "${JDK_HOME}" ] ; then
        echo "Invalid JDK_HOME: ${JDK_HOME}" 1>&2
	exit 1
    fi
    rtclasses="${JDK_HOME}/lib/classes.zip:${JDK_HOME}/classes"
    rtbinhome="${JDK_HOME}/bin"
    jhome=${JDK_HOME}
    prog=java
else
    rtclasses="${rthome}/classes:${rthome}/lib/rt.jar:${rthome}/lib/i18n.jar"
    rtbinhome="${rthome}/bin"
    jhome=${rthome}
    prog=jre
fi

#
# Set Paths
#

hjclasses="${HOTJAVA_HOME}/classes:${HOTJAVA_HOME}/lib/classes.zip"
hjclasses="${hjclasses}:$HOTJAVA_HOME/lib/ssl.jar:${rtclasses}:$HOTJAVA_HOME/lib/x509v1.jar:$HOTJAVA_HOME/lib"

if [ -z "$CLASSPATH" ] ; then
    CLASSPATH="${hjclasses}"
else
    CLASSPATH="${hjclasses}:$CLASSPATH"
fi
export CLASSPATH


PATH="${HOTJAVA_HOME}/bin:${rtbinhome}/bin:$PATH"
export PATH


hjlibs="${HOTJAVA_HOME}/lib/${arch}/ssl"

LD_LIBRARY_PATH="${hjlibs}:${LD_LIBRARY_PATH}"
export LD_LIBRARY_PATH

#
# Parse arguments
#

logfile="${HOTJAVA_LOG:-/dev/null}"

while [ $# != 0 ]; do
  case "$1" in 
    -debug) prog=jdb; logfile=/dev/tty  ;;
    -log) shift; logfile="$1" ;;
    -help|--help|-\?) cat <<EOF
Welcome to HotJava Browser!

Optional Environment Variables:
    Set HOTJAVA_LOG environment variable to a file to log output to
    (/dev/tty ok).  For logging on a single run, use the -log switch.

    Set JDK_HOME environment variable to point to a full top level JDK
    directory.

    Set JRE_HOME environment variable to point to an alternate
    Java Runtime Environment directory.

    Use the -nosplash switch to supress the display of the splash page.

Usage:

    hotjava [ -log log_file ] [-nosplash] [ java_interpreter_options ] [ URL ]

To see the available "java_interpreter_options", type:

    ${rtbinhome}/${prog} -help

EOF
        exit ;;
    -trace) args="${args} $1" ;;
    -nosplash) args="${args} $1";;
    -D*) args="${args} $1" ;;
    -*) opts="${opts} $1" ;;
    *)  args="${args} $1" ;;
  esac
  shift
done

#
# Select a java interpreter
#
JAVA="${rtbinhome}/${prog}"
if [ ! -x "${JAVA}" ] ; then
    echo "Can't execute: ${JAVA}" 1>&2
    exit 1
fi

#
# Set the JAVA_HOME directory.  jre pays attention to this.
#
JAVA_HOME=${jhome}
export JAVA_HOME

#
# Add WWW_HOME option
#
if [ ! -z "${WWW_HOME}" ] ; then
    opts="${opts} -Dwww.home=${WWW_HOME}"
fi

#
# Start HotJava
#

exec ${JAVA} -ms4m -mx32m \
    -Dhotjava.home=${HOTJAVA_HOME} -Djava.home=${jhome} ${opts} \
    sunw.hotjava.Main ${args} 1>> "${logfile}" 2>&1

