#! @SHELL@
#
# Copyright 1998 - 2005 Double Precision, Inc.  See COPYING for
# distribution information.
#
# Sample script to start Courier's pop3 daemon.
#
# This script should work for most systems.  Authenticate via the PAM library,
# /etc/shadow, or fallback to /etc/passwd
#
# You must run this as root, and as a daemon process.
#

prefix="@prefix@"
exec_prefix="@exec_prefix@"
sysconfdir="@sysconfdir@"
sbindir="@sbindir@"
bindir="@bindir@"
libexecdir="@libexecdir@"

if test ! -f ${sysconfdir}/pop3d
then
	echo "${sysconfdir}/pop3d does not exist, forgot make install-configure?"
	exit 1
fi

if test ! -f ${sysconfdir}/pop3d-ssl
then
	echo "${sysconfdir}/pop3d-ssl does not exist, forgot make install-configure?"
	exit 1
fi

. ${sysconfdir}/pop3d-ssl
. ${sysconfdir}/pop3d

export PATH
export SHELL

case "$1" in
start)
	;;
stop)
	@courierlogger@ -pid=$PIDFILE -stop
	exit 0
	;;
restart)
	@courierlogger@ -pid=$PIDFILE -restart
	exit 0
	;;
*)
	exit 0
	;;
esac

cd @prefix@

@SETENV@ -i @SHELL@ -c " set -a; \
		prefix=@prefix@ ; \
		exec_prefix=@exec_prefix@ ; \
		sbindir=@sbindir@ ; \
		bindir=@bindir@ ; \
		libexecdir=@libexecdir@ ; \
		. @sysconfdir@/pop3d ; \
		. @sysconfdir@/pop3d-ssl ; \
	TLS_PROTOCOL=$TLS_STARTTLS_PROTOCOL ; \
	PROXY_HOSTNAME=$PROXY_HOSTNAME ; \
	@courierlogger@ -pid=$PIDFILE -start $LOGGEROPTS \
	@sbindir@/couriertcpd -address=$ADDRESS \
		-maxprocs=$MAXDAEMONS -maxperip=$MAXPERIP \
		$TCPDOPTS \
		$PORT @libexecdir@/courier/courierpop3login \
			@libexecdir@/courier/courierpop3d ${MAILDIRPATH}"
