#!/bin/sh
#
# @(#)select_runtime.sh	1.6 98/07/14 SMI
# Copyright 1997 Sun Microsystems, Inc.
#

#
# Clear JAVA_HOME if set to avoid conflicts with java scripts
#
if [ -n "$JAVA_HOME" ]; then
    echo "JAVA_HOME=; export JAVA_HOME; "
fi

#
# If HOTJAVA_RUNTIME is set then force use of bundled runtime
#
if [ -n "$HOTJAVA_RUNTIME" ]; then
    HOTJAVA_HOME=${HOTJAVA_HOME:-/usr/dt/appconfig/hotjava}
    jre_home=${HOTJAVA_HOME}/runtime
    echo "JDK_HOME=; JRE_HOME=${jre_home};"
    exit 0
fi

#
# Dont do anything if JDK_HOME or JRE_HOME are already set
#
if [ -n "$JDK_HOME" -o -n "$JRE_HOME" ]; then
    exit 0
fi

#
# If bundled java is java version 1.1.6 or later; then use it
#
if [ -x /usr/java/bin/java ]; then
    jvmrev=`java -version 2>&1 | awk '{print $3}' | sed 's/"//g'`
    jvmmajor=`echo $jvmrev | cut -d. -f1`
    jvmminor=`echo $jvmrev | cut -d. -f2`
    jvmdotdot=`echo $jvmrev | cut -d. -f3`

    if [ "$jvmmajor" -eq 1 ] && ( [ "$jvmminor" -gt 1 ] ||
	 ( [ "$jvmminor" -eq 1 ] && [ "$jvmdotdot" -ge 6 ] ) )
    then
	alt_jdk_home=/usr/java
	echo "JDK_HOME=${JDK_HOME:-${alt_jdk_home}};"
    fi
fi
