#!/bin/bash

# ucd-snmp init file for snmpd
#
# chkconfig: - 50 50
# description: Simple Network Management Protocol (SNMP) Daemon
#
# processname: snmpd
# config: /etc/snmp/snmpd.local.conf
# config: /etc/snmp/snmpd.conf
# config: /usr/share/snmp/snmpd.local.conf
# config: /usr/share/snmp/snmpd.conf

# source function library
. /etc/rc.d/init.d/functions

RETVAL=0

if [  $#  = 2 ]; then
      trap=$2   
else
      trap=sendtrap
fi

case "$1" in
  start)
	    echo -n "Starting snmpd: "
	    rm -f /var/snmp/snmpd.local.nvram
	    /IBM/bin/readNvram 101   # alt write community name 
	    /IBM/bin/readNvram 102   # write community name 
	    /IBM/bin/readNvram 103   # alt read community name
	    /IBM/bin/readNvram 104   # read community name

            nice -n 0 /usr/local/sbin/snmpd > /dev/null 2>&1
	    RETVAL=$?
	    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/snmpd
	    echo
	    echo -e "\r"
	    if [ "$trap" = "sendtrap" ]; then   
                /IBM/bin/gentrap 0 0 /etc/rc.d/init.d/snmpd &
            fi
	    ;;
  stop)
	    echo -n "Shutting down snmpd: "

	    if [ "$trap" = "sendtrap" ]; then    
                /IBM/bin/gentrap 6 0 /etc/rc.d/init.d/snmpd &
            fi

	    rm -f /var/snmp/snmpd.local.nvram
	    killproc snmpd
	    RETVAL=$?
	    [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/snmpd
	    echo
	    ;;
  restart)
        $0 stop $trap  
        $0 start $trap  
	      RETVAL=$?
        ;;
  status)
        status snmpd
	      RETVAL=$?
        ;;
  *)
	echo "Usage: snmpd {start|stop|restart|status} [sendtrap|notrap]"
	exit 1
esac

exit $RETVAL
