#!/sbin/sh

# /etc/init.d/spfmilter to be linked with /etc/rc2.d/S87spfmilter
# By Christian Pelissier

#    usage: spfmilter [options] /path/to/socket

#    -l <spf-mechanism>               Specify a local SPF policy. (?)
#    -t                               Use the trusted-forwarder.com whitelist.
#    -m                               Mark mails and do not reject.
#    -X                               Do not fork into the background.
#    -d [<int>]                       Enable debugging to syslog.
#    -u <user|uid>                    Run as specified user or UID.
#    -x <exp>                         Set the default spf-message. (?)
#    -h                               Show this help.



PATH=/usr/sbin:/usr/bin

prefix=/usr/local
user=smmsp
options="-m -u $user"
socket="unix:/var/spfmilter/spfmilter.sock"

[ -x $prefix/sbin/spfmilter ] || exit 0

case "$1" in
  start)
        echo "Starting spfmilter: ... \c"
        $prefix/sbin/spfmilter $options $socket
        echo "done."
        ;;
  stop)
        echo "Shutting down spfmilter: ... \c"
        /usr/bin/pkill -u $user spfmilter
        echo "done."
        ;;
  restart)
        echo "Restarting spfmilter: ... \c"
        /usr/bin/pkill -u $user spfmilter
        sleep 2
        $prefix/sbin/spfmilter $options $socket
        echo "done."
        ;;
  *)
        echo "Usage: $0 {start|stop|restart}"
        exit 1
esac
exit 0
