#! /bin/sh
# $Id: sqwebmaild.rc.in,v 1.7 2005/07/05 12:37:46 mrsam Exp $
#
# Copyright 2004 Double Precision, Inc.
# See COPYING for distribution information.


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

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

. /usr/local/etc/sqwebmail/sqwebmaild

startpcp() {
	case "`cat /usr/local/etc/sqwebmail/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/local/etc/sqwebmail/sqwebmaild ; \
		/usr/local/sbin/courierlogger -pid=${PIDFILE}.pcp $LOGGEROPTS -start \
			${libexecdir}/sqwebmail/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/local/etc/sqwebmail/sqwebmaild ; \
		/usr/local/sbin/courierlogger -pid=${PIDFILE} $LOGGEROPTS -start \
			${libexecdir}/sqwebmail/sqwebmaild"
	;;

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