#! /bin/sh
#
#		pwcheck - start Cyrus pwcheck
#
#		Written by Michael-John Turner <mj@debian.org>
#
#		Based on work:
#		Written by Miquel van Smoorenburg <miquels@cistron.nl>.
#		Modified for Debian GNU/Linux
#		by Ian Murdock <imurdock@gnu.ai.mit.edu>.
#
# Version:	@(#)skeleton  1.8  03-Mar-1998  miquels@cistron.nl
#
# This file was automatically customized by dh-make on Tue, 23 Nov 1999 11:26:47 +0200

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/pwcheck
NAME=pwcheck
DESC="Cyrus pwcheck daemon"

test -f $DAEMON || exit 0

set -e

# Now we need to check where /usr/sbin/pwcheck points
PWCHECK_DEST=`ls -lL /usr/sbin/pwcheck`
PWCHECK_STANDARD=`ls -l /usr/sbin/pwcheck_standard | sed "s/_.*//g"`
PWCHECK_PAM=`ls -l /usr/sbin/pwcheck_pam | sed "s/_.*//g"`

if [ "$PWCHECK_DEST" = "$PWCHECK_STANDARD" ]; then
		PWCHECK="STANDARD"
		DESC="Cyrus standard pwcheck daemon"
	else
		PWCHECK="PAM"
		DESC="Cyrus PAM pwcheck daemon"
fi


case "$1" in
  start)
	echo -n "Starting $DESC: "
	if [ "$PWCHECK" = "STANDARD" ]; then
			start-stop-daemon --start --quiet --background --chuid cyrus --exec $DAEMON
		else
			start-stop-daemon --start --quiet --background --exec $DAEMON
	fi
	echo "$NAME."
	;;
  stop)
	echo -n "Stopping $DESC: "
	start-stop-daemon --stop --quiet --name $NAME --exec $DAEMON
	echo "$NAME."
	;;
  #reload)
	#
	#	If the daemon can reload its config files on the fly
	#	for example by sending it SIGHUP, do it here.
	#
	#	If the daemon responds to changes in its config file
	#	directly anyway, make this a do-nothing entry.
	#
	# echo "Reloading $DESC configuration files."
	# start-stop-daemon --stop --signal 1 --quiet --pidfile \
	#	/var/run/$NAME.pid --exec $DAEMON
  #;;
  restart|force-reload)
	echo -n "Restarting $DESC: "
	start-stop-daemon --stop --quiet --name $NAME --exec $DAEMON
	sleep 1
	if [ "$PWCHECK" = "STANDARD" ]; then
			start-stop-daemon --start --quiet --background --chuid cyrus --exec $DAEMON
		else
			start-stop-daemon --start --quiet --background --exec $DAEMON
	fi
	echo "$NAME."
	;;
  *)
	N=/etc/init.d/$NAME
	echo "Usage: $N {start|stop|restart|force-reload}" >&2
	exit 1
	;;
esac

exit 0
