#!/bin/sh
#
# $NetBSD: courierfilter.sh,v 1.6 2008/02/19 18:45:24 jlam Exp $
#
# Courier mail filter daemon
#
# PROVIDE: courierfilter
# REQUIRE: DAEMON
# KEYWORD: shutdown

. /etc/rc.subr

name="courierfilter"
rcvar=${name}
command="/usr/pkg/sbin/${name}"
pidfile="/var/courier/tmp/${name}.pid"

restart_cmd="${name}_doit restart"
start_precmd="${name}_prestart"
start_cmd="${name}_doit start"
stop_cmd="${name}_doit stop"

mkdir_perms()
{
	dir="$1"; user="$2"; group="$3"; mode="$4"
	test -d $dir || /bin/mkdir -p $dir
	/usr/sbin/chown $user $dir
	/usr/bin/chgrp $group $dir
	/bin/chmod $mode $dir
}

courierfilter_prestart()
{
	# Courier filter directories
	mkdir_perms /var/courier/allfilters \
			courier mail 0750
	mkdir_perms /var/courier/filters \
			courier mail 0750
	mkdir_perms /usr/pkg/etc/courier/filters \
			courier mail 0750
	mkdir_perms /usr/pkg/etc/courier/filters/active \
			courier mail 0750
	mkdir_perms /var/courier/tmp \
			courier mail 0770
}

courierfilter_doit()
{
	action=$1

	case $action in
	restart)	echo "Restarting ${name}." ;;
	start)		echo "Starting ${name}." ;;
	stop)		echo "Stopping ${name}." ;;
	esac

	${command} $action
}

load_rc_config $name
run_rc_command "$1"
