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


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

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

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

. /usr/pkg/etc/courier/pop3d-ssl
. /usr/pkg/etc/courier/pop3d

case $1 in
start)
	if test "$TLS_CACHEFILE" != ""
	then
		rm -f "$TLS_CACHEFILE"
		touch "$TLS_CACHEFILE"
		chown courier "$TLS_CACHEFILE"
		chgrp mail  "$TLS_CACHEFILE"
		chmod 600  "$TLS_CACHEFILE"
	fi

	/usr/bin/env -i /bin/sh -c " set -a ;
		prefix=/usr/pkg ;
		exec_prefix=/usr/pkg ;
		bindir=${exec_prefix}/bin ;
		libexecdir=/usr/pkg/libexec/courier ;
		sbindir=${exec_prefix}/sbin ;
		. /usr/pkg/etc/courier/pop3d-ssl ; \
		. /usr/pkg/etc/courier/pop3d ; \
		PROXY_HOSTNAME=$PROXY_HOSTNAME ; \
		TLS_PROTOCOL=$TLS_STARTTLS_PROTOCOL ; \
		./install-sh -c -d `dirname $PIDFILE` ; \
		/usr/pkg/sbin/courierlogger -pid=$PIDFILE -start $LOGGEROPTS \
		${exec_prefix}/sbin/couriertcpd -address=$ADDRESS \
			-maxprocs=$MAXDAEMONS -maxperip=$MAXPERIP \
			$TCPDOPTS \
			$PORT /usr/pkg/libexec/courier/courierpop3login \
				/usr/pkg/libexec/courier/courierpop3d ${MAILDIRPATH}"
	;;
stop)
	/usr/pkg/sbin/courierlogger -pid=$PIDFILE -stop
	;;
esac
exit 0
