#!/bin/bash
#
# (c) Copyright 2002 Hewlett-Packard Development Company, L.P.
#
# init file for IDA agent
#
# processname: cmaidad

NAME="IDA agent"
PNAME="cmaidad"
PFLAGS="-p 15 -s OK -l /var/log/hp-snmp-agents/cma.log"

# source function library
if [ -f /etc/rc.d/init.d/functions ]; then
. /etc/rc.d/init.d/functions
elif [ -f /etc/rc.config ]; then
. /etc/rc.config
elif [ -f /etc/rc.d/functions ]; then
. /etc/rc.d/functions
elif [ -f /etc/rc.status ]; then
. /etc/rc.status
fi

if [ -z "$LOGFILE" ]; then
LOGFILE=/var/spool/compaq/cma.log
fi

storechon () {
    printf "  $*" | tee -a "$LOGFILE"
}

storecho()
{
    printf "  $*\n" | tee -a "$LOGFILE"
}

showsuccess()
{
if [ -f /etc/rc.d/init.d/functions ]; then
  echo_success
elif [ -f /etc/rc.status ]; then
  rc_reset
  rc_status -v
else
  printf "\t\t[ SUCCESS ]\n"
fi

}
showfailure()
{
if [ -f /etc/rc.d/init.d/functions ]; then
   echo_failure
elif [ -f /etc/rc.status ]; then
   rc_failed
   rc_status -v
else
  printf "\t\t[ FAILED ]\n"
fi
}

#different distros put pidof in different places
if [ -f /sbin/pidof ]; then
  PIDOF=/sbin/pidof
elif [ -f /bin/pidof ]; then
  PIDOF=/bin/pidof
fi

if [ -d /opt/hp/hp-snmp-agents ]
then
	LD_LIBRARY_PATH="/opt/hp/hp-snmp-agents/storage/bin"
else
	LD_LIBRARY_PATH="/opt/compaq/storage/bin"
fi

STSYSDIR="/var/spool/compaq/hpasm/registry/stsys"
export LD_LIBRARY_PATH

if [ "$1" = "start" ]; then
   pidlist=`$PIDOF cmaidad`
   if [ ! -z "$pidlist" ]
   then
	storechon "Already started $NAME ($PNAME): " 1>&2
	showsuccess
	storecho
	exit 0
   fi      
   
   if [ -d /var/spool/compaq/hpasm/registry/ida ]; then
      rm -rf /var/spool/compaq/hpasm/registry/ida
   fi
   pidlist=`$PIDOF cmascsid cmasasd`
   if [ -z "$pidlist" -a -d "$STSYSDIR" ]; then
	   rm -rf "$STSYSDIR"
   fi
fi

if [ "x$CMAINCLUDE" = "x" ]; then
   if [ -d /opt/hp/hp-snmp-agents ]; then
        CMAINCLUDE=/opt/hp/hp-snmp-agents/server/etc/cmad
   else
	CMAINCLUDE=/opt/compaq/foundation/etc/cmad
   fi
fi

. $CMAINCLUDE

