#!/bin/sh
#
# //  DESCRIPTION:
# //      Controls the heap monitor function.

. $(/usr/bin/dirname $0)/setupCmdLine

# Issue error message if we are unable to determine valid profile
CMD_NAME=`basename $0`

if [ "${INV_PRF_SPECIFIED:=}" != "" ] && [ "$INV_PRF_SPECIFIED" = "true" ]
then
    java -cp "${WAS_HOME}/lib/commandlineutils.jar" com.ibm.ws.install.commandline.utils.CommandLineUtils -specifiedProfileNotExists -profileName $WAS_PROFILE_NAME
    exit 1
elif [ "${WAS_USER_SCRIPT_FILE_NOT_EXISTS:=}" != "" ] && [ "$WAS_USER_SCRIPT_FILE_NOT_EXISTS" = "true" ]
then
    java -cp "${WAS_HOME}/lib/commandlineutils.jar" com.ibm.ws.install.commandline.utils.CommandLineUtils -wasUserScriptFileNotExists -wasUserScript $WAS_USER_SCRIPT
    exit 1
elif [ "${NO_DFT_PRF_EXISTS:=}" != "" ] && [ "$NO_DFT_PRF_EXISTS" = "true" ]
then
    java -cp "${WAS_HOME}/lib/commandlineutils.jar" com.ibm.ws.install.commandline.utils.CommandLineUtils -noDefaultProfile -commandName $CMD_NAME
    exit 1
fi

rearg_match_arg_with_value()
{
  local matched=1
  case $1 in
    -instance)    dspntvmsg WAS7001
                  specify_profile $2 ;;
    -profileName) specify_profile $2 ;;
    -server.name) server=$2 ;;
    *)            matched=0  ;;
  esac
  return $matched
}

rearg_match_boolean_arg()
{
  local matched=1
  case $1 in
     -enable) mode=enable  ;;
    -disable) mode=disable ;;
     -status) mode=status  ;;
    -viewlog) mode=viewlog ;;
         -\?) mode=help    ;;
       -help) mode=help    ;;
           *) matched=0    ;;
  esac
  return $matched
}

mode=usage
server=$WAS_PROFILE_NAME
if [ "$WAS_PROFILE_NAME" = "default" ]; then
  server=server1
fi

. $(/usr/bin/dirname $0)/.rearg

$(/usr/bin/dirname $0)/wsadmin -profileName ${WAS_PROFILE_NAME} "$@" -wsadmin_classpath ${WAS_INSTALL_ROOT}/util/custom400.jar -f ${WAS_INSTALL_ROOT}/util/heapMonitor.jacl $mode $server
