#!/bin/ksh
# Compatibility Script with OMU Agent command. Requires correctly set BOOM_ROOT
# environment variable
# getdir: identify the path to the program and set
#         it as PROG_DIR
# Params: program-name and $0 from call

#Variable to hold Program Directory
PROG_DIR=

getdir() {
  prog="$1"
  call="$2"
  if [ -z "$prog" ]
  then
    return
  fi
  #   newdir=${0%/*}
  newdir=`echo "${call}"|sed "s/${prog}$//"`
  if [ -z "$newdir" ]
  then
    whichstr=`which ${prog}|grep -v "no ${prog}"`
    newdir=`echo "$whichstr"|sed "s/${prog}$//"`
    if [ -z "$newdir" ]
    then
      return
    fi
  fi
  if [ -d "$newdir" ]
  then
    PROG_DIR="$newdir"
  fi
}

if [ -z "$BOOM_ROOT" ]
then
  echo "To avoid negative performance impacts please set the BOOM_ROOT variable"
  getdir opcagt "$0"
  if [ -z "$PROG_DIR" ]
  then
    echo "Failed to identify the path for BOOM_ROOT."
    echo "Please set the BOOM_ROOT variable to the Agent directory!"
    exit 1
  fi
  BOOM_ROOT="$PROG_DIR"
else
  BOOM_ROOT="${BOOM_ROOT}/"
fi

if [ $# -eq 0 ]; then
echo 'opcmsga     OVO Message Agent                   AGENT,EA     (0000)   Running'
fi

case "$1" in
    "-status")
        echo 'opcmsga     OVO Message Agent                   AGENT,EA     (0000)   Running'
        ;;
    "-start");;
    "-stop") ;;
    "-help") echo "opcagt [-status | -type [-verbose] | -help]"
             ;;
    "-version") echo "8.21.000"
             ;;
    "-type") 
        if [ "$2" = "-verbose" ]
        then
          echo "AGENT_TYPE=HTTPS"
          echo "OVO_DATADIR=\"${BOOM_ROOT}\""
          echo "OVO_INSTALLDIR=\"${BOOM_ROOT}\""
          echo "OVOAGT_ACTDIR=\"${BOOM_ROOT}spi/\""
          echo "OVOAGT_MONDIR=\"${BOOM_ROOT}spi/\""
          echo "OVOAGT_CMDDIR=\"${BOOM_ROOT}spi/\""
          echo "OVOAGT_INSTRUMENTDIR=\"${BOOM_ROOT}spi/\""
          echo "OVOAGT_BINVERS=08.21.000"
          echo "OPC_MGMT_SERVER=null.null.null"
        else
          echo "HTTPS"
        fi
        ;;
    "-verbose") 
        if [ "$2" = "-type" ]
        then
          echo "AGENT_TYPE=HTTPS"
          echo "OVO_DATADIR=\"${BOOM_ROOT}\""
          echo "OVO_INSTALLDIR=\"${BOOM_ROOT}\""
          echo "OVOAGT_ACTDIR=\"${BOOM_ROOT}spi/\""
          echo "OVOAGT_MONDIR=\"${BOOM_ROOT}spi/\""
          echo "OVOAGT_CMDDIR=\"${BOOM_ROOT}spi/\""
          echo "OVOAGT_INSTRUMENTDIR=\"${BOOM_ROOT}spi/\""
          echo "OVOAGT_BINVERS=08.21.000"
          echo "OPC_MGMT_SERVER=null.null.null"
        else
          echo ""
        fi
        ;;
esac
exit 0

