#!/bin/sh
#
# $Header: cluvfy.sbs 18-mar-2005.17:21:02 smishra Exp $
#
# cluvfy.sbs 
#
# Copyright (c) 2003, 2005, Oracle. All rights reserved.  
#
#    NAME
#      cluvfy.sbs - Starts the cluster verification driver
#
#    DESCRIPTION
#      This requires these environmental variables.
#      CV_HOME: home for CV tools
#      CV_JDKHOME: java home
#      CV_DESTLOC: the remote locations where the required files can be
#                  copied and executed. The user MUST have write permission
#                  on this location, on all the nodes.
#
#    NOTES
#      
#
#    Build: 031705

AWK=/bin/awk
if [ -z "$ECHO" ]; then ECHO=/bin/echo; fi

validateInput()
{
##validates if any value is assigned to the script variables
PARAM_NAME=$1
valid=`$ECHO $PARAM_NAME | $AWK '/^%/ { print "false"; }'`
if [ "$valid" = "false" ];
then
return 1;
fi

return 0;
}

ORACLE_HOME=%s_OracleHome%
JREDIR=%s_jreLocation%
DESTLOC=%s_destLocation%

validateInput $ORACLE_HOME
ret=$?
if [ "$ret" = "0" ];
then
  CV_HOME=$ORACLE_HOME
fi

if [ "X$CV_HOME" = "X" ];
then
  $ECHO "Set CV_HOME environmental variable before proceeding."
  exit 1
fi

validateInput $JREDIR
ret=$?
if [ "$ret" != "0" ];
then
  if [ -z "$CV_JDKHOME" ];
  then
     $ECHO "Set CV_JDKHOME to a valid JRE 1.4 location"
     exit 1
  fi
  JREDIR=$CV_JDKHOME
fi

REM_CVHOME="-DCV_HOME=$CV_HOME"

CVUJAR=$CV_HOME/jlib/cvu.jar
SRVMJAR=$CV_HOME/jlib/srvm.jar

JRE=$JREDIR/bin/java
JREJAR=$JREDIR/lib/rt.jar

CLASSPATH=$JREJAR:$CVUJAR:$SRVMJAR


#Check RemoteExec destination location
if [ "X$CV_DESTLOC" = "X" ]
then
    validateInput $DESTLOC
    ret=$?
    if [ "$ret" = "0" ];
    then
	CV_DESTLOC=$DESTLOC
    fi
fi

#If remote destination location is empty show error msg. Proceed with default.
if [ "X$CV_DESTLOC" != "X" ]
then
    REM_DESTLOC="-DCV_DESTLOC=$CV_DESTLOC"
else
    REM_DESTLOC="-DCV_DESTLOC=/tmp"
fi

REM_ENV="$REM_DESTLOC $REM_CVHOME"

if [ "X$SRVM_TRACE" != "X" ]
then
  TRACE="-DTRACING.ENABLED=true -DTRACING.LEVEL=2"
fi

LD_LIBRARY_PATH=$CV_HOME/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH

# Run cluvfy driver for sparc64
$JRE -d64 -classpath $CLASSPATH $REM_ENV $TRACE oracle.ops.verification.client.CluvfyDriver "$@"
exit $?
