#!/bin/sh

# PROVIDE: amavisd-milter
# REQUIRE: amavisd
# BEFORE: mail
# KEYWORD: shutdown

#
# Add the following lines to /etc/rc.conf to enable amavisd-milter:
#
# amavisd_milter_enable="YES"
# amavisd_milter_flags="<set as needed>"
#

. /etc/rc.subr

name="amavisd_milter"
rcvar=amavisd_milter_enable

load_rc_config $name

# Set defaults
: ${amavisd_milter_enable:="NO"}
: ${amavisd_milter_user="%%AMAVISUSER%%"}
: ${amavisd_milter_socket:="%%RUNDIR%%/amavisd-milter.sock"}
: ${amavisd_milter_socket_perm:="0666"}
: ${amavisd_am_pdp_socket:="%%AMAVISDIR%%/amavisd.sock"}

pidfile="${amavisd_milter_pidfile:-%%RUNDIR%%/amavisd-milter.pid}"
command="%%PREFIX%%/sbin/amavisd-milter"
command_args="-p ${pidfile} -s ${amavisd_milter_socket} -S ${amavisd_am_pdp_socket}"
required_files="%%PREFIX%%/etc/amavisd.conf"
start_postcmd="amavisd_milter_postcmd"

amavisd_milter_postcmd()
{
	if [ -e ${amavisd_milter_socket} ]; then
		chmod ${amavisd_milter_socket_perm} ${amavisd_milter_socket}
	fi
}

run_rc_command "$1"
