#! /bin/sh
#
# Copyright 1998 - 2005 S. Varshavchik.  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="/usr"
exec_prefix="/usr"
sysconfdir="/etc/courier"
sbindir="/usr/bin"
bindir="/usr/bin"
libexecdir="/usr/lib"

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)
	/usr/bin/courierlogger -pid=$PIDFILE -stop
	exit 0
	;;
restart)
	/usr/bin/courierlogger -pid=$PIDFILE -restart
	exit 0
	;;
*)
	exit 0
	;;
esac

cd /usr

if test "$TLS_CACHEFILE" != ""
then
	rm -f "$TLS_CACHEFILE"
	touch "$TLS_CACHEFILE"
	chown courier "$TLS_CACHEFILE"
	chgrp courier  "$TLS_CACHEFILE"
	chmod 600  "$TLS_CACHEFILE"
fi

/usr/sbin/env -i /bin/sh -c " set -a; \
		prefix=/usr ; \
		exec_prefix=/usr ; \
		sbindir=/usr/bin ; \
		bindir=/usr/bin ; \
		libexecdir=/usr/lib ; \
		. /etc/courier/pop3d ; \
		. /etc/courier/pop3d-ssl ; \
	PROXY_HOSTNAME=$PROXY_HOSTNAME ; \
	/usr/sbin/mkdir -p `dirname $PIDFILE` ; \
	/usr/bin/courierlogger -pid=$PIDFILE -start $LOGGEROPTS \
	/usr/bin/couriertcpd -address=$ADDRESS \
		-maxprocs=$MAXDAEMONS -maxperip=$MAXPERIP \
		$TCPDOPTS \
		$PORT /usr/lib/courier/courierpop3login \
			/usr/lib/courier/courierpop3d ${MAILDIRPATH}"
