if [ "$1" == "heap" ]; then
       HPROF="-Xrunhprof:heap=sites,thread=y,depth=8"
       shift
elif [ "$1" == "cpu" ]; then
       HPROF="-Xrunhprof:heap=sites,cpu=samples,thread=y,depth=8"
       shift
else
       HPROF=""
fi

SBMDIR=$HOME/.SANbox_Manager
OUT=${SBMDIR}/out.txt

if [ ! -d ${SBMDIR} ]; then
        mkdir ${SBMDIR}
else
        if [ -f ${OUT} ]; then
                cp ${OUT} ${OUT}_bak
        fi
fi

check_display()
{
	if [ -z "$DISPLAY" ]; then 
		echo ""
		echo "$progname: DISPLAY environment variable must be set"
		exit 1
	fi
	XHOST=/usr/openwin/bin/xhost
	if [ ! -x $XHOST ]; then
		XHOST=/usr/bin/X11/xhost
	fi
	if [ -x $XHOST ]; then
		$XHOST>/dev/null 2>&1
		if [ $? -ne 0 ]; then
			echo ""
			echo "$progname: Unable to open DISPLAY: $DISPLAY"
			exit 1
		fi
	fi
}

do_start()
{
	check_display
	if [ ! -x $JAVAPATH ]; then
                echo ""
                echo "JRE path ($JAVAPATH) does not contain the java cmd.  Process terminated." 
		exit 1
	fi
	if [ $# -gt 1 ]; then
		LOGIN="-Dlogin=$2"
	fi
	if [ $# -gt 0 ]; then
		IP="-Dipaddr=$1"
	fi
      trap - INT
      export J2DFONTSCALER=t2k 
      cd ${PKG_INSTALL_ROOT}/usr/opt/SUNWsmgr2/bin2
      COMMAND="${JAVAPATH} ${IP} ${LOGIN} -classpath ${PKG_INSTALL_ROOT}/usr/opt/SUNWsmgr2/bin2/SANsurfer2.jar:${PKG_INSTALL_ROOT}/usr/opt/SUNWsmgr2/bin2/jdom.jar:${PKG_INSTALL_ROOT}/usr/opt/SUNWsmgr2/bin2/qmsCommon.jar:${PKG_INSTALL_ROOT}/usr/opt/SUNWsmgr2/bin2/sunCrypto.jar:${PKG_INSTALL_ROOT}/usr/opt/SUNWsmgr2/bin2/ComQDevice.jar com.qlogic.Application > ${OUT} 2>&1"
      eval "$COMMAND &"
      cd - >/dev/null
}

do_start $1 $2;
exit 0
