#!/sbin/sh
#
# Copyright (c) 1992, 1995, 1997 - 2000 by Sun Microsystems, Inc.
# All rights reserved.
#
#ident	"@(#)sendmail	1.16	00/09/06 SMI"

ERRMSG1='WARNING: /var/mail is NFS-mounted without setting actimeo=0,'
ERRMSG2='this can cause mailbox locking and access problems.'

case "$1" in 
'start')
	if [ -f /usr/lib/sendmail -a -f /etc/mail/sendmail.cf ]; then
		if [ ! -d /var/spool/mqueue ]; then
			/usr/bin/mkdir -m 0750 /var/spool/mqueue
			/usr/bin/chown root:bin /var/spool/mqueue
		fi
		MODE="-bd"
		if [ -f /etc/default/sendmail ]; then
			. /etc/default/sendmail
		fi
		#
		# * MODE should be "-bd" or null (MODE= or MODE="") or
		#   left alone.  Anything else and you're on your own.
		# * QUEUEINTERVAL should be set to some legal value;
		#   a sanity check is done below.
		# * OPTIONS is a catch-all; set with care.
		#
		if [ -z "$QUEUEINTERVAL" ]; then
			QUEUEINTERVAL="15m"
		fi
		case $QUEUEINTERVAL in
			*s | *m | *h | *d | *w) ;;
			*)  QUEUEINTERVAL="15m" ;;
		esac
		if [ $QUEUEINTERVAL -le 0 ]; then
			QUEUEINTERVAL="15m"
		fi
		/usr/lib/sendmail $MODE -q$QUEUEINTERVAL $OPTIONS &
		#
		# ETRN_HOSTS should be of the form
		# "s1:c1.1,c1.2        s2:c2.1 s3:c3.1,c3.2,c3.3"
		# i.e., white-space separated groups of server:client where
		# client can be one or more comma-separated names; N.B. that
		# the :client part is optional; see etrn(1M) for details.
		# server is the name of the server to prod; a mail queue run
		# is requested for each client name.  This is comparable to
		# running "/usr/lib/sendmail -qRclient" on the host server.
		#
		# See RFC 1985 for more information.
		#
		for i in $ETRN_HOSTS; do
			SERVER=`echo $i | /usr/bin/sed -e 's/:.*$//'`
			CLIENTS=`echo $i | /usr/bin/sed -n -e 's/,/ /g' \
			    -e '/:/s/^.*://p'`
			/usr/sbin/etrn $SERVER $CLIENTS >/dev/null 2>&1 &
		done
	fi	

	if /usr/bin/nawk 'BEGIN{s = 1}
	    $2 == "/var/mail" && $3 == "nfs" && $4 !~ /actimeo=0/ &&
	    $4 !~ /noac/{s = 0} END{exit s}' /etc/mnttab; then

		/usr/bin/logger -p mail.crit "$ERRMSG1"
		/usr/bin/logger -p mail.crit "$ERRMSG2"
	fi
	;;

'stop')
	/usr/bin/pkill -x -u 0 sendmail
	;;

*)
	echo "Usage: $0 { start | stop }"
	exit 1
	;;
esac
exit 0
