#!/bin/sh

# You can force selection of a particular JVM by specifying it here.
# Leave blank to allow automatic selection of JVM from path.
JAVA=

# The location of the shared files.  Leave blank to use the shared files
# in the same directory as this launch script.
SHARE=

# Make sure java exists in path.
if [ -z "${JAVA}" ]; then
   JAVA=`which java`
   if [ -z "${JAVA}" ]; then
      echo "Unable to start Ivory.  No Java Virtual Machine found."
      exit 1;
   fi
fi

# Make sure that the java virtual machine is 1.5 or greater.
JAVA_VERSION=`${JAVA} -version 2>&1 | awk '/version/{print $3}' | sed -e 's/\"//g'`
MAJOR_JAVA_VERSION=`echo ${JAVA_VERSION} | sed -e 's/\([0-9][0-9]*\)\.\([0-9][0-9]*\).*/\1/'`
MINOR_JAVA_VERSION=`echo ${JAVA_VERSION} | sed -e 's/\([0-9][0-9]*\)\.\([0-9][0-9]*\).*/\2/'`
if [ "${MAJOR_JAVA_VERSION}" -lt "1" ] || [ "${MINOR_JAVA_VERSION}" -lt "5" ]; then
   echo "Unable to start Ivory.  Java Virtual Machine version is not version 1.5 or greater."
   exit 1;
fi

# Locate the shared files.
if [ -z "${SHARE}" ]; then
   SHARE=`echo ${0} | sed -e 's#\(.*\)/.*#\1#'`
fi

cd ${SHARE}

# Set the classpath.
for i in $( find . -name \*.jar ); do
   CLASSPATH=${CLASSPATH}:${i}
done

# Launch the application.
${JAVA} -Djava.library.path=. -classpath ${CLASSPATH} com.ivorymahjongg.mahjongg.Main
