#!/bin/sh
#Written by Danny Bickson, HUJI
# Revised by Ohad Serfaty , TAU
CURRENT_DIR=$(pwd)
CLASSES_DIR="$CURRENT_DIR/Classes/"
BASE_DIR="$CURRENT_DIR/Classes/Base/"

. colors.sh

# Verify JAVA_HOME :
echo -n "Verifying JAVA_HOME...   "
if [ -n "$JAVA_HOME" ]; then
	verify 0 "Using JAVA_HOME : $JAVA_HOME"
else
	verify 1  " JAVA_HOME Enviroment variable is not defined. Please install JDK or define it manually."
	exit 1
fi

# verify java executable :
echo -n "Verifying Java Executable...  "
JAVA=$JAVA_HOME/bin/java
test -f $JAVA
verify $?  "Missing Java executable : $JAVA"

# verify java version (1.4* or 1.5*)
echo -n "Checking Java version......"
ret=`${JAVA} -version 2>&1 | grep --regexp="1\.[4|5]"`
verify $? "Wrong java version. Should be 1.4.*"

# verify display settings :
echo -n "Checking display settings.."
if [ -z $DISPLAY ]; then
	verify 1 "Missing Display settings. "
	echo "on tsch/csh You should \"setenv DISPLAY <IP_adddress>:0\""  
	echo "on bash You should \"export DISPLAY=<IP_adddress>:0\""  
	exit 1
else
	verify 0	
fi


LOG_PARAM="-Djava.util.logging.config.file=$BASE_DIR\conf\logging.properties"
DIMES_CLASS_PATH="$CLASSES_DIR"
DIMES_JARS_PATH="$CLASSES_DIR/JARs"
PROPERTIES_FILE="$BASE_DIR/conf/properties.xml"
${JAVA} $LOG_PARAM -classpath $DIMES_CLASS_PATH AgentLauncher $DIMES_JARS_PATH $PROPERTIES_FILE >/dev/null 2>/dev/null &
