#! /bin/sh
#
# Copyright 1998 - 2004 Double Precision, Inc.
# See COPYING for distribution information.
#

prefix="/usr/pkg"
exec_prefix="/usr/pkg"
libexecdir="/usr/pkg/libexec"
sysconfdir="/usr/pkg/etc/courier"
localstatedir="/var/courier"
piddir="/var/courier/tmp"
pkglibexecdir="/usr/pkg/libexec/courier"

filterbindir="${pkglibexecdir}/filters"
filteractivedir="${sysconfdir}/filters/active"
pidfile="${piddir}/courierfilter.pid"

cmd="$1"
filter="$2"

case "$cmd" in
start)
	;;
stop)
	;;
*)
	filter=""
	;;
esac

if test "$filter" = ""
then
	echo "Usage: $0 (start | stop) [ filter ]" >&2
	exit 1
fi

case "$filter" in
*/*)
	filter=""
	;;
*)
	if test ! -x $filterbindir/$filter
	then
		filter=""
	fi
	;;
esac

if test "$filter" = ""
then
	echo "This filter is not installed in $filterbindir" >&2
	echo >&2
	exit 1
fi

case "$cmd" in
start)
	test ! -x $filterbindir/$filter \
		|| ln -s $filterbindir/$filter $filteractivedir/$filter \
		|| exit 1
	;;
stop)
	rm -f $filteractivedir/$filter || exit 1
	;;
esac

test -f "$pidfile" && kill -HUP "`cat $pidfile`" 2>/dev/null
exit 0
