#!/bin/sh
# Simple wrapper script used to start JOSM in Debian
set -e

# First, the users preference as defined by $JAVA_HOME.  Next, the
# other JVMs known to work with josm, with the one working best
# first, and the less functional ones after that.  Override to a
# specific one using $JAVACMD
JAVA_CMDS="$JAVA_HOME/bin/java /usr/lib/jvm/java-6-sun/jre/bin/java /usr/lib/jvm/java-1.5.0-sun/jre/bin/java /usr/bin/jamvm /usr/bin/gij-4.1"

for jcmd in $JAVA_CMDS; do 
    if [ -x "$jcmd" -a -z "${JAVACMD}" ]; then
        JAVACMD="$jcmd"
    fi
done

if [ "$JAVACMD" ]; then
    echo "Using $JAVACMD to execute josm."
    exec $JAVACMD -jar /usr/share/josm/josm.jar "$@"
else    
    echo "No valid JVM found to run JOSM."
    echo "Please install one of those mentioned in README.Debian"
    echo "or set the JAVACMD environment variable prior running josm."
    exit 1
fi
