#!/bin/sh
#
# Start/stops the mxfilter daemons. /etc/init.d script.
#

mkdir /var/mxfilter
chown postfix /var/mxfilter
chmod 700 /var/mxfilter

PATH=/sbin:/bin:/usr/sbin:/usr/bin
MXFILTER=/usr/local/sbin/mxfilterd
MXFILTER_USER=postfix

MXFILTER_PID=/var/run/mxfilter
MXFILTERSH_PID=/var/run/mxfiltersh
REJECT_UNSIGNED_BOUNCE_PID=/var/run/mxfilter_reject_unsigned_bounce
SIGN_AUTH_RELAY_PID=/var/run/mxfilter_sign_auth_relay
OUTMAIL_IP=127.0.0.1

test -f ${MXFILTER} || exit 0

case "$1" in
	start)
		echo -n "Starting mxfilter daemons:"
		echo -n " mxfilter"
		start-stop-daemon --start --quiet --pidfile ${MXFILTER_PID} --background --chuid ${MXFILTER_USER} --exec ${MXFILTER}
		echo -n " mxfiltersh"
		start-stop-daemon --start --quiet --pidfile ${MXFILTERSH_PID} --background --chuid ${MXFILTER_USER} --exec ${MXFILTER} -- -sh ${OUTMAIL_IP}
		echo -n " reject_unsigned_bounce"
		start-stop-daemon --start --quiet --pidfile ${REJECT_UNSIGNED_BOUNCE_PID} --background --chuid ${MXFILTER_USER} --exec ${MXFILTER} -- -reject_unsigned_bounce
		echo -n " sign_auth_relay"
		start-stop-daemon --start --quiet --pidfile ${SIGN_AUTH_RELAY_PID} --background --chuid ${MXFILTER_USER} --exec ${MXFILTER} -- -sign_auth_relay
		echo "."
		;;
	stop)
		echo -n "Stopping mxfilter daemons:"
		echo -n " mxfilter"
		start-stop-daemon --stop --quiet --exec ${MXFILTER}
		echo "."
		;;
	*)
		echo "Usage: $0 {start|stop}"
		exit 1
		;;
esac

exit 0

