#!/bin/sh
#
# $Id: hagui.embedded,v 1.5 2009/08/03 06:45:02 paa Exp $
# $Copyrights: Copyright (c) 2010 Symantec Corporation.
# All rights reserved.
#
# THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE SECRETS OF
# SYMANTEC CORPORATION.  USE, DISCLOSURE OR REPRODUCTION IS PROHIBITED
# WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SYMANTEC CORPORATION.
#
# The Licensed Software and Documentation are deemed to be commercial
# computer software as defined in FAR 12.212 and subject to restricted
# rights as defined in FAR Section 52.227-19 "Commercial Computer
# Software - Restricted Rights" and DFARS 227.7202, "Rights in
# Commercial Computer Software or Commercial Computer Software
# Documentation", as applicable, and any successor regulations. Any use,
# modification, reproduction release, performance, display or disclosure
# of the Licensed Software and Documentation by the U.S. Government
# shall be solely in accordance with the terms of this Agreement.  $
#

# we explicitly do not want the environment's classpath
unset CLASSPATH
PATH=".:$PATH"
export PATH

VCS_HOME="/opt/VRTSvcs"
LIB_PATH=$VCS_HOME/gui/lib
LANG_PATH=$VCS_HOME/gui/lang

ATLIB_PATH=$VCS_HOME/gui/VxEAT/lib

EAT_HOME_DIR=${VCS_HOME}/gui/VxEAT
export EAT_HOME_DIR

EAT_ARGS=-Dvrtsat.home="${EAT_HOME_DIR}"

HPUX_ARGS=""
LNF_ARGS=-Dswing.metalTheme=steel

attrpooldir=$HOME/.vcsstore

mkdir -p $attrpooldir 2> /dev/null

if [ $? != 0 ]
then
        attrpooldir=/tmp/.vcsstore
        mkdir -p $attrpooldir
fi

mkdir -p $attrpooldir/attrpool
mkdir -p $attrpooldir/messages
ATTRPOOL_DIR=-Dattrpool.dir="$attrpooldir"
DEF_ATTRPOOL_DIR=-Ddefattrpool.dir="/var/VRTSvcs/gui"
GUI_BASE_DIR=-Dbase.dir="$attrpooldir"
GUI_INSTALL_DIR=-Dinstall.dir="/opt/VRTSvcs/gui"

PLAT=`uname`

###############################################################
# Find where java is installed
###############################################################

JAVA=""
CHECK_JAVA_VER="true"

# Check if JAVA_HOME has been specified
if [ "${JAVA_HOME}" != "" ] ; then
	if [ -x "${JAVA_HOME}/bin/java" ] ; then
		JAVA=${JAVA_HOME}/bin/java
	fi
fi

if [ "$JAVA" = "" ] ; then
	if [ -x $VCS_HOME/gui/jre/bin/java ] ; then
		JAVA=$VCS_HOME/gui/jre/bin/java
		CHECK_JAVA_VER="false"
	fi
fi

# Next, check if it's in path
if [ "$JAVA" = "" ] ; then
	if [ -x "`which java`" ] ; then
		JAVA="`which java`"
	fi
fi

# Check usual path
if [ "$JAVA" = "" ] ; then
	if [ -x /usr/bin/java ] ; then
		JAVA=/usr/bin/java
	fi
fi

if [ "$PLAT" = "SunOS" ]
then
	# Give preference to VRTSjre15 if installed
	tmp=`$PKGPARAM VRTSjre15 BASEDIR`
	if [ $? = 0 ]
	then
		JAVA=${tmp}/VRTSjre/jre1.5/bin/java
		CHECK_JAVA_VER="false"
	fi
fi

if [ "$JAVA" = "" ] ; then
	echo "ERROR: java not found."
	echo "Please include the program \"java\" (v1.5+) in your PATH variable OR"
	echo "set JAVA_HOME environment variable to point to install directory of Java v1.5+"
	exit 1
fi

if [ "$CHECK_JAVA_VER" = "true" ] ; then
	JAVA_VER=`$JAVA -fullversion 2>&1`
	OLD_VERSIONS="1.0. 1.1. 1.2. 1.3. 1.4."
	for old_version in $OLD_VERSIONS
	do
		TMP=`echo $JAVA_VER | grep "$old_version"`
		if [ $? = 0 ] ; then
			echo "ERROR: unsupported java version $JAVA_VER"
			echo "Please include the program \"java\" (v1.5+) in your PATH variable OR"
			echo "set JAVA_HOME environment variable to point to install directory of Java v1.5+"
			exit 1
		fi
	done
fi

if [ "$PLAT" = "HP-UX" ] ; then
        SHLIB_PATH=$SHLIB_PATH:$ATLIB_PATH
        export SHLIB_PATH
fi

LD_LIBRARY_PATH=$LIB_PATH:${ATLIB_PATH}:${EAT_HOME_DIR}/bin
export LD_LIBRARY_PATH

BCLASSPATH=${LANG_PATH}:${LIB_PATH}/VCSGui.jar:${LIB_PATH}/gui_images.jar:${LIB_PATH}/sounds.jar:${LIB_PATH}/VxHelpViewer.jar:${LIB_PATH}/VxHelpViewerl10n.jar

DEBUG=0
if [ "$1" = "-D" ] ; then 
	DEBUG=1
	shift 1
fi

if [ "$#" = 0 ] ; then	  
	if [ "$CSGA_DIR" = "" ] ; then
		CONF_PATH=$VCS_HOME/gui/
	else
		CONF_PATH=$CSGA_DIR	  
	fi
elif [ "$#" = 1 ] ; then
	CONF_PATH=$*
	shift 1
elif [ "$#" -gt 1 ] ; then
	if [ -d "$1" ] ; then
		CONF_PATH=$1
		shift 1
	elif [ "$1" != "-h" ] && [ "$1" != "-p" ] ; then
		echo "$1: configuration directory doesn't exist."
		exit 1
	fi
else
	echo "$SELFNAME: configuration directory is incorrect!"
	exit 1
fi


CLASSPATH=${CONF_PATH}:$BCLASSPATH:${ATLIB_PATH}/AtWrapper.jar
export CLASSPATH

if [ $DEBUG = 0 ] ; then
	exec $JAVA $GUI_BASE_DIR $DEF_ATTRPOOL_DIR $ATTRPOOL_DIR $GUI_INSTALL_DIR $EAT_ARGS $HPUX_ARGS $LNF_ARGS -classpath $CLASSPATH -mx128m VCSGui $* > /dev/null
else
	exec $JAVA $GUI_BASE_DIR $DEF_ATTRPOOL_DIR $ATTRPOOL_DIR $GUI_INSTALL_DIR $EAT_ARGS $HPUX_ARGS $LNF_ARGS -classpath $CLASSPATH -mx128m VCSGui $* 
fi

