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


prefix=/usr/pkg
exec_prefix=${prefix}
sbindir=${exec_prefix}/sbin
libexecdir=${prefix}/libexec

if test ! -f /usr/pkg/etc/courier/sqwebmaild
then
	echo "/usr/pkg/etc/courier/sqwebmaild does not exist, forgot make install-configure?"
	exit 1
fi

. /usr/pkg/etc/courier/sqwebmaild

startpcp() {
	case "`cat /usr/pkg/etc/courier/calendarmode 2>/dev/null`" in
	net)
	/usr/bin/env -i - /bin/sh -c " set -a ;
		prefix=${prefix} ;
		exec_prefix=${exec_prefix} ;
		sbindir=${sbindir} ;
		libexecdir=${libexecdir} ;
		. /usr/pkg/etc/courier/sqwebmaild ; \
		/usr/pkg/sbin/courierlogger -pid=${PIDFILE}.pcp $LOGGEROPTS -start \
			${libexecdir}/courier/pcpd server"
		;;
	*)
		;;
	esac
}

case $1 in
start)
	startpcp

	/usr/bin/env -i - /bin/sh -c " set -a ;
		prefix=${prefix} ;
		exec_prefix=${exec_prefix} ;
		sbindir=${sbindir} ;
		libexecdir=${libexecdir} ;
		. /usr/pkg/etc/courier/sqwebmaild ; \
		/usr/pkg/sbin/courierlogger -pid=${PIDFILE} $LOGGEROPTS -start \
			${libexecdir}/courier/sqwebmaild"
	;;

stop)
	/usr/pkg/sbin/courierlogger -pid=${PIDFILE} -stop
	/usr/pkg/sbin/courierlogger -pid=${PIDFILE}.pcp -stop
	;;
reload)
	/usr/pkg/sbin/courierlogger -pid=${PIDFILE} -restart
	/usr/pkg/sbin/courierlogger -pid=${PIDFILE}.pcp -restart
	;;
esac
exit 0
