#!/bin/sh
#
# $NetBSD: dkim-filter.sh,v 1.2 2008/03/09 15:09:26 adrianp Exp $
#
# PROVIDE: dkimfilter
# REQUIRE: DAEMON
# BEFORE: mail

if [ -f /etc/rc.subr ]; then
	. /etc/rc.subr
fi

name="dkimfilter"
rcvar=$name
command="/usr/pkg/libexec/dkim-filter"
pidfile="/var/run/dkim-filter/${name}.pid"
command_args="-p local:/var/run/dkim-filter/${name}.sock -P ${pidfile} -l -x /usr/pkg/etc/dkim-filter.conf -u dkim:dkim"
required_files="/usr/pkg/etc/dkim-filter.conf"
start_precmd="dkimfilter_precmd"

dkimfilter_precmd()
{
	if [ ! -d /var/run/dkim-filter ]; then
		/bin/mkdir -p /var/run/dkim-filter
		/bin/chmod 0750 /var/run/dkim-filter
		/usr/sbin/chown dkim:dkim /var/run/dkim-filter
	fi

	if [ -f /var/run/dkim-filter/${name}.sock ]; then
		/bin/rm -f /var/run/dkim-filter/${name}.sock
	fi
}

if [ -f /etc/rc.subr ]; then
        load_rc_config $name
	run_rc_command "$1"
else
	echo -n " ${name}"
	${command} ${dkimfilter_flags} ${command_args}
fi
