#!/bin/sh

# PROVIDE: obspamd
# REQUIRE: NETWORKING SERVERS syslogd named
# BEFORE:  DAEMON
# KEYWORD: shutdown

#
# Define these spamd_* variables in one of these files:
#       /etc/rc.conf
#       /etc/rc.conf.local
#
# obspamd_enable="YES"	# Run the spamd(8) daemon (YES/NO).
# obspamd_flags=""	# Extra flags for spamd(8) (if enabled).
#
# DO NOT CHANGE THESE DEFAULT VALUES HERE
#
obspamd_enable=${obspamd_enable:-"NO"}

. /etc/rc.subr

name="obspamd"
rcvar=obspamd_enable

command="/usr/local/libexec/spamd"
start_precmd="obspamd_precmd"
start_postcmd="obspamd_postcmd"
restart_postcmd="obspamd_postcmd"
stop_postcmd="obspamd_cleanup"
pidfile="/var/run/spamd.pid"

obspamd_precmd()
{
	_rc=0
	echo "${obspamd_flags}" | egrep "(^\-b| \-b)" 2>&1 > /dev/null
	return 0
}

obspamd_postcmd()
{
	if [ -x /usr/local/sbin/spamd-setup ]; then
		if [ -r /usr/local/etc/spamd/spamd.conf ]; then
			echo "${obspamd_flags}" | egrep "(^\-b| \-b)" 2>&1 > /dev/null
			if [ $? -eq 0 ]; then
				/usr/local/sbin/spamd-setup -bD
			else
				/usr/local/sbin/spamd-setup -D
			fi
		fi
	fi
}

obspamd_cleanup()
{
	/bin/rm -f ${pidfile}
}

load_rc_config $name
run_rc_command "$1"
