#!/bin/sh

#
# Check for JAVA settings
#

if [ ! -x "$JAVA_HOME" ] ; then
  echo "Error: JAVA_HOME is not defined correctly."
  exit 1
fi

JAVACMD="$JAVA_HOME/bin/java"

if [ ! -x "$JAVACMD" ] ; then
  echo "Error: JAVA_HOME is not defined correctly."
  echo "  We cannot execute $JAVACMD"
  exit 1
fi

#
# Build classpath
#

S=':'
CLASSPATH=''

for i in ./lib/*.jar; do
  CLASSPATH=$CLASSPATH$S$i
done

#
# Execute command
#
MAIN_CLASS=$2

if [ $1 = "configure" ]
then
	MAIN_CLASS="divconq.tool.Configure"
fi

if [ $1 = "sync" ] 
then
	MAIN_CLASS="divconq.tool.Sync"
fi

if [ $1 = "testdb" ] 
then
	MAIN_CLASS="divconq.test.TestDb"
fi

if [ $1 = "etlutil" ] 
then
	MAIN_CLASS="etime.util.Main"
fi

"$JAVACMD" -classpath "$CLASSPATH" $MAIN_CLASS $@
RESULT=$?
exit $RESULT
