#################################################
#	
#################################################
#Please, specify the directory where Java is
# installed to "JAVA_DIR" in the define below. 
#################################################
#
#################################################
#PATH Where is Java installed
#################################################
JAVA_DIR="/usr/java/j2sdk1.4.0_02"
if [ ! -x "$JAVA_DIR" ];then
   JAVA_DIR="/usr/java/j2sdk1.4.1_02"
   if [ ! -x "$JAVA_DIR" ];then
	JAVA_DIR="/usr/java/j2re1.4.1_02"
   fi
fi
#################################################
#PATH Where is SiI project installed
#################################################
JAVA_CMD="$PWD"

#################################################
#PATH Where is HELP installed
#################################################
#JAVA_HELP="/usr/local/JAVAGUI/jh1.1.3/javahelp/lib"
#copied to classes
JAVA_HELP="$PWD/classes" 
#

SETCOLOR_SUCCESS="echo -en \\033[1;32m"
SETCOLOR_FAILURE="echo -en \\033[1;31m"
SETCOLOR_WARNING="echo -en \\033[1;33m"
SETCOLOR_NORMAL="echo -en \\033[0;39m"
$SETCOLOR_NORMAL
cd ${JAVA_CMD}
#################################################
#LD_LIBRARY_PATH checking
#################################################
if [ ! -x "$LD_LIBRARY_PATH" ];then
	$SETCOLOR_WARNING
	#echo " LD_LIBRARY_PATH $LD_LIBRARY_PATH not defined !"
	$SETCOLOR_NORMAL
	#echo "check if it is already defined in /etc/profile - previous call"
	LDFLAGS=`grep -l LD_LIBRARY_PATH /etc/profile `
	if [ -z $LDFLAGS ]; then
	cat <<EOF  >> /etc/profile

#
LD_LIBRARY_PATH="/usr/lib"
export LD_LIBRARY_PATH
echo "LD_LIBRARY_PATH is $LD_LIBRARY_PATH"
EOF
	echo " LD_LIBRARY_PATH added to /etc/profile"
fi
	#call our definition
	LD_LIBRARY_PATH="/usr/lib"
	export LD_LIBRARY_PATH
        #echo "LD_LIBRARY_PATH is $LD_LIBRARY_PATH"
fi
#call our definition
MODULECONF="/etc/modules.conf"
export MODULECONF
#################################################
#JNI LIBRARY checking
#################################################
if [ ! -f "/usr/lib/libSiCommand.so" ];then
	$SETCOLOR_WARNING
	echo " JNI library not found: copying......"
	cp ${JAVA_CMD}/jni/*.so /usr/lib
	sync
	$SETCOLOR_NORMAL
else
	#compare version
	cp -u ${JAVA_CMD}/jni/*.so /usr/lib
fi
echo "Starting GUI.."
${JAVA_DIR}/bin/java -classpath "${JAVA_CMD}/classes:${JAVA_DIR}/jre/lib/sunrsasign.jar:${JAVA_DIR}/jre/lib/rt.jar:${JAVA_DIR}/jre/lib/i18n.jar:${JAVA_DIR}/lib/tools.jar:${JAVA_DIR}/lib/dt.jar:${JAVA_HELP}/jh.jar" sataraid.MainApp&
