#!/bin/sh
stop="K45percsnmpd"
start="S55percsnmpd"
snmpagtdir="/etc/percsnmp"
snmpconf="percsnmpd.conf"
agent="/usr/sbin/percagent"
bagent="percagent"
main="/usr/sbin/percmain"
script="percsnmpd"

[ "$1" = "" ] && cmdline=1

if [ -d /etc/rc.d ] ; then
  rcdir="/etc/rc.d"
else
  rcdir="/etc"
fi

if [ -d /etc/rc.d/init.d ] ; then
  initdir="/etc/rc.d/init.d"
else
  initdir="/etc/init.d"
fi

#1. Remove the startup/shutdown rc links

rm -f $rcdir/rc0.d/$stop 2>/dev/null

rm -f $rcdir/rc1.d/$stop 2>/dev/null

rm -f $rcdir/rc6.d/$stop 2>/dev/null

rm -f $rcdir/rc2.d/$start 2>/dev/null

rm -f $rcdir/rc3.d/$start 2>/dev/null

rm -f $rcdir/rc4.d/$start 2>/dev/null

rm -f $rcdir/rc5.d/$start 2>/dev/null

#2. Remove the files installed by percagent.

[ -f /etc/snmp/${snmpconf} ] &&  rm -f  /etc/snmp/${snmpconf}
[ -f /usr/local/share/snmp/${snmpconf} ] &&  rm -f  /usr/local/share/snmp/${snmpconf} 
[ -f /usr/share/snmp/${snmpconf} ] && rm -f  /usr/share/snmp/${snmpconf} 

[ -f ${snmpagtdir}/perc.mib ] && rm -f ${snmpagtdir}/perc.mib 
[ -f ${snmpagtdir}/percsnmptrap.conf ] && rm -f ${snmpagtdir}/percsnmptrap.conf 
[ -f ${snmpagtdir}/readme.txt ] && rm -f ${snmpagtdir}/readme.txt  

#Stopping percagent
apid=`pidof $bagent | cut -f1 -d" "`
if [ "$apid" != "" ] ; then
  if [ -x ${snmpagtdir}/${script} ] ; then 
		${snmpagtdir}/${script} stop 
	else
   [ -x ${initdir}/${script} ] &&  ${initdir}/${script} stop 
	fi
fi

[ -x $agent ] && rm -f $agent
[ -x $main ]  && rm -f $main

rm -f ${snmpagtdir}/${script}

[ -f $initdir/${script} ] && rm -f $initdir/${script}
#Check whether uninstall called from RPM or command line
#If it is called from command line, remove the files
if [ "$cmdline" = "1" ] ; then 
	rm -rf ${snmpagtdir}
	echo Uninstallation of $vendor Agent is complete.
fi
