#!/bin/sh -e

. /etc/init.d/functions.sh
. /lib/rcscripts/sh/rc-std2parse.sh
. /etc/conf.d/snmpd

NAME=snmpd
DAEMON=/usr/sbin/$NAME
DESC=$NAME

snmpd_start () {
	local tmpf=/tmp/snmpv3_initial_user_pw

	if [ "$SNMP_ENABLED" = yes ]; then
		if [ -f ${tmpf}_tmp ]; then
			std2parse /etc/snmp/snmpd.conf
			[ "$STD2_SNMP_V3" != yes ] || mv ${tmpf}_tmp ${tmpf}
		fi
		start_daemon $DAEMON || return 1
	else
		information "disabled"
	fi
}

snmpd_stop () {
	stop_daemon $DAEMON
}

case "$1" in
	start)
		begin "Starting $DESC"
		snmpd_start
		end $?
		;;
	stop)
		begin "Stopping $DESC"
		snmpd_stop
		end $?
		;;
	restart)
		begin "Restarting $DESC"
		snmpd_stop && snmpd_start
		end $?
		;;
	*)
		error "Usage: $0 start|stop|restart"
		;;
esac

exit 0
