#! /bin/sh
#
# Modified from: @(#)skeleton  1.9  26-Feb-2001  miquels@cistron.nl
#

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/spfmilter
NAME=spfmilter
DESC="SPF Milter"
RUNDIR=/var/run/$NAME
USER=spfmilter

test -x $DAEMON || exit 0

# Include spfmilter defaults if available
if [ -f /etc/default/spfmilter ] ; then
	. /etc/default/spfmilter
fi

set -e

case "$1" in
  start)
	if [ -z "$NO_MACROS_CHECK" ]; then
		/usr/lib/sendmail -d64.5 -bt </dev/null | grep "milter_set_option(macros.envfrom" | grep "{auth_type}" >/dev/null || \
		echo "WARNING: {auth_type} not defined in Milter.macros.envfrom. Please see /usr/share/doc/spfmilter/README.Debian.gz for more information."
	fi
	echo -n "Starting $DESC: "
	start-stop-daemon --start --quiet --exec $DAEMON -- \
		--user $USER --pidfile $RUNDIR/$NAME.pid \
		$DAEMON_OPTS $RUNDIR/$NAME.sock 
	echo "$NAME."
	;;
  stop)
	echo -n "Stopping $DESC: "
	start-stop-daemon --stop --exec $DAEMON
	echo "$NAME."
	;;
  restart|force-reload)
	echo -n "Restarting $DESC: "
	start-stop-daemon --stop --exec $DAEMON
	sleep 1
	start-stop-daemon --start --quiet --exec $DAEMON -- \
		--user $USER --pidfile $RUNDIR/$NAME.pid \
		$DAEMON_OPTS $RUNDIR/$NAME.sock 
	echo "$NAME."
	;;
  *)
	N=/etc/init.d/$NAME
	echo "Usage: $N {start|stop|restart|force-reload}" >&2
	exit 1
	;;
esac

exit 0
