#!/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

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

   daemon /usr/local/sbin/snmpd > /dev/null 2>&1
	RETVAL=$?
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/snmpd
	echo
	echo -e "\r"
	/IBM/bin/gentrap 0 0 /etc/rc.d/init.d/snmpd &
	;;
  stop)
	echo -n "Shutting down snmpd: "
	/IBM/bin/gentrap 6 0 /etc/rc.d/init.d/snmpd &
	rm -f /var/snmp/snmpd.local.nvram
	killproc snmpd
	RETVAL=$?
	[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/snmpd
	echo
	;;
  restart)
        $0 stop
        $0 start
	RETVAL=$?
        ;;
  status)
        status snmpd
	RETVAL=$?
        ;;
  *)
	echo "Usage: snmpd {start|stop|restart|status}"
	exit 1
esac

exit $RETVAL
