PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
NAME=treesize
DEFAULT=/etc/default/$NAME
INST_PATH=/opt/BIA-Net/TreeSize/


# The first existing directory is used for JAVA_HOME (if JAVA_HOME is not
# defined in $DEFAULT)
JDK_DIRS="/usr/lib/j2sdk1.4-sun /usr/lib/j2sdk1.4-ibm /usr/lib/j2sdk1.4 /usr/lib/j2sdk1.5 /usr/lib/j2se/1.4 /usr/lib/j2se/1.5 /usr/lib/kaffe"

# and search in /usr/java
for javadir in `ls -1 /usr/java/ 2>/dev/null`; do
	JDK_DIRS="/usr/java/$javadir $JDK_DIRS"
done

# overwrite settings from default file
if [ -f "$DEFAULT" ]; then
        . "$DEFAULT"
fi


# Look for the right JVM to use
for jdir in $JDK_DIRS; do
        if [ -r "$jdir/jre/bin/java" -a -z "${JAVA_HOME}" ]; then
                JAVA_HOME="$jdir"
        fi
done
export JAVA_HOME


# If the architecture is powerpc, set the JITC_PROCESSOR_TYPE
if [ $(dpkg --print-architecture) = powerpc ] ; then
  export JITC_PROCESSOR_TYPE=6
fi

if [ -z "$JAVA_HOME" ]; then
   echo "Could not start $NAME because no Java Runtime Environment"
   echo "(JRE) was found. Please download and install JRE 1.4 or "
   echo "higher and set"
   echo "JAVA_HOME in $DEFAULT to the JRE's installation directory."
   exit 0
fi

echo "Using JRE in Path: $JAVA_HOME"
echo "If you prefer another JRE set JAVA_HOME in $DEFAULT!"

cd $INST_PATH
$JAVA_HOME/jre/bin/java -jar TreeSize.jar

