#! /bin/sh -e
### BEGIN INIT INFO
# Short-Description: Courier SMTP server
# Provides:          courier-mta-ssl
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
### END INIT INFO

sysconfdir="/etc/courier"
sbindir="/usr/sbin"
TCPD=${sbindir}/couriertcpd
DAEMONPROG=${sbindir}/esmtpd-ssl

test -f $DAEMONPROG || exit 0

# check for couriertcpd
if ! [ -x $TCPD ]; then
  exit 0
fi

# check for couriertls
if ! [ -x $COURIERTLS ]; then
  exit 0
fi

# check for esmtpd configuration file
if ! [ -f ${sysconfdir}/esmtpd ]; then
  exit 0
fi

# check for esmtpd-ssl configuration file
if ! [ -f ${sysconfdir}/esmtpd-ssl ]; then
  exit 0
fi

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

case "$1" in
start)
	echo -n "Starting Courier SMTP/SSL server:"
	${sbindir}/esmtpd-ssl start
	echo " done."
	;;
stop)
	echo -n "Stopping Courier SMTP/SSL server:"
   	${sbindir}/esmtpd-ssl stop
   	echo " done."
	;;
restart | force-reload)
    $0 stop
    $0 start
    ;;
*)
  echo "Usage: $0 {start|stop|restart|force-reload}" >&2
  exit 1
  ;;
esac
exit 0
