#!/bin/sh
# simple script to execute java with the appropriate options to run Jalview
# Change JAVA_CMD to the location of your java binary if necessary
# Change the values of the -Xms and -Xmx parameters if you are getting
# out of memory errors
#

# JAVA8_CMD should be set before running this script.
# The best place to do that is in $BIRCH/local/local.profile.source
# For testing purposes, you can uncomment the line below and
# modify it for the appropriate Java command on your system.
#JAVA8_CMD="/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.322.b06-6.fc35.x86_64/jre/bin/java"


if [ ! -z "$JAVA17_CMD" ]
then
    JAVA_CMD="$JAVA17_CMD"
else    
    JAVA_CMD="java"
fi

echo "JAVA_CMD: " $JAVA_CMD

# Check for Java17
JVERSION=`$JAVA_CMD -version 2>&1 | head -n 1 | cut -f2 -d'"' | cut -f1 -d"."`
echo "JVERSION: "$JVERSION


if [ "$JVERSION" = "17" ] 
then
    $JAVA_CMD -jar $BIRCH/java/Jalview/jalview-all-2.11.2.1-j1.8.jar "$@"
else
    MESSAGE="Jalview requires Java17."
    TITLE="Dependencies"
    java -jar $BIRCH/script/OkayBox2.jar "$MESSAGE" "$TITLE"
    chooseviewer.py $BIRCH/public_html/birchadmin/dependencies/dependencies.html
fi