#!/usr/bin/ksh
#set -x
########################################################################
# This script will invoke the vtsk and middle server
# Usage instructions pass -k for only SunVTS kernel, -a for both javabridge
# and SunVTS kernel and -j for the Java Bridge
#
# Author : Raghu
# Creation Date : 27th Nov 2006
#Modified the script to remove changes related to BUI
# Date : Nov 3 - Raghu
########################################################################
#

echo "___________________________________________"
echo "STATUS MESSAGES FOR  InvokeVtsAgent	"
echo "------------------------------------------"

# Check for the existence of the rmiregistry
platform=`/usr/bin/isainfo | cut -c1-5`

echo "value of $ 0" $0
#Compute path to {root}/usr/sunvts/bin folder and {root}/usr/sunvts/lib folder
#binPath and libPath

case $0 in
        /*)
           getSunvtsPath=$(dirname $0)
        ;;

        *)
           getSunvtsPath=$(pwd)/$(dirname $0)
           getSunvtsPath=`(cd ${getSunvtsPath};pwd)`
        ;;
esac

binPath=$getSunvtsPath
echo "Complete path to /usr/sunvts/bin folder is: "$binPath
libPathCompute=`echo $getSunvtsPath|awk '{print substr($getSunvtsPath,0,(length($getSunvtsPath)-3))}'`
echo "Complete path to /usr/sunvts folder is: "$libPathCompute
libPath=$libPathCompute"lib"
echo "Complete path to /usr/sunvts/lib folder is: "$libPath

# check for the 32bit or 64bit
bit=`isainfo -kv | cut -d ' ' -f1`

#Path of Verbose log file
logfile='/var/sunvts/logs/sunvts.startup'

#Help for options
usage()
{
echo >&2 "Usage: $0 [-kh] "
echo >&2 "-k to invoke SunVTS agent only."
echo >&2 "-h for the help."
}


# For Sparc platforms.
if [ $platform = "sparc" ]; then
while getopts :kh opt
do
	case "$opt" in
	k)
	echo >&2 "Starting the SunVTS agent...\n">>$logfile
	$binPath/sparcv9/vtsk
	exit 1;;
	h)
	usage;
	exit 1;;
	\?)
	echo >&2 "Incorrect option ! "
	usage;
	exit 1;;
	esac
done
echo >&2 "No options found, starting with the default options..."
	$binPath/sparcv9/vtsk


fi
# For x86 platforms.
if [ $platform = "amd64" ]; then
while getopts :kh opt
do
	case "$opt" in
	k)
	echo >&2 "Starting the SunVTS agent...\n">>$logfile
	$binPath/64/vtsk
	exit 1;;
	h)
	usage;
	exit 1;;
	\?)
	echo >&2 "Incorrect option ! "
	usage;
	exit 1;;
	esac
done
echo >&2 "No options found, starting with the default options..."
	$binPath/64/vtsk
fi

if [ $platform = "i386" ]; then
while getopts :kh opt
do
	case "$opt" in
	k)
	echo >&2 "Starting the SunVTS agent...\n">>$logfile
	$binPath/vtsk
	exit 1;;
	h)
	usage;
	exit 1;;
	\?)
	echo >&2 "Incorrect option !"
	usage;
	exit 1;;
	esac
done
echo >&2 "No options found, starting with the default options..."
	$binPath/vtsk
fi
exit 1
