#!/bin/sh
#
# Cmdline QPTune

# Determine the operating system and set up the proper libpath.
#
os=`uname -s`

#
#	If Mac OS X, set JAVA_HOME to /Library/Java/Home, if it is not
#	already set.  Also, clear SYBASE_JRE6
#
if [ $os = "Darwin" ]
then
	if [ "$JAVA_HOME" = "" ]
	then
		export JAVA_HOME=/Library/Java/Home
	fi
	export SYBASE_JRE6=""
fi

#
# See if SYBASE is defined.
#
if [ "$SYBASE" = "" ]
then
	echo "\$SYBASE environment is not set."
	exit 1
fi

#
# See if SYBASE_ASE is defined.
#
if [ "$SYBASE_ASE" = "" ]
then
	echo "\$SYBASE_ASE environment is not set."
	exit 1
fi

#
# See if SYBASE_JRE6 is defined.
#
if [ "$SYBASE_JRE6" = "" ]
then
	if [ "$JAVA_HOME" = "" ]
	then
		echo "\$SYBASE_JRE6 or \$JAVA_HOME environment is not set."
		exit 1
	fi
fi

if [ "$SYBASE_JRE6" != "" ]
then
	echo "\$SYBASE_JRE6 is set.  Use \$SYBASE_JRE6 as \$JAVA_HOME."
	JAVA_HOME=$SYBASE_JRE6
	export JAVA_HOME
fi

#
# Set up the libraries for the QPTune
#
libs="$SYBASE/$SYBASE_ASE/lib/qptune.jar:$SYBASE/jConnect-6_0/classes/jconn3.jar:$SYBASE/$SYBASE_ASE/lib/xercesImpl.jar:$SYBASE/$SYBASE_ASE/qptune/lib/xercesImpl.jar:$SYBASE/$SYBASE_ASE/lib/xml-apis.jar:$SYBASE/$SYBASE_ASE/qptune/lib/xml-apis.jar:$SYBASE/$SYBASE_ASE/qptune"

if [ $os = AIX ]
then
    LIBPATH="$JAVA_HOME/bin:$JAVA_HOME/bin/classic"
    export LIBPATH;
fi

"$JAVA_HOME/bin/java" -cp $libs com.sybase.qp.QPTune $*

