#!/bin/sh
#
#    Copyright (c) 1996-2000 Brocade Communications Systems, Inc.
#    All rights reserved.
#
#    Initialization script to start/stop sendmail
#
# 

CONFIG=/etc
CHECK=/sbin/chkconfig
SENDMAIL=/usr/sbin/sendmail
DOMFILE=/etc/domain
export PATH=/bin:/usr/bin:/sbin

if $CHECK verbose ; then
ECHO='echo -e'
else
ECHO=:
fi

case "$1" in

'start')
skipsendmail=0
/usr/bin/killall -q sendmail
#set the domain from DOMFILE
if [ -f $DOMFILE ]; then
	/bin/domainname `/bin/cat $DOMFILE` 
	if [ $? -ne 0 ]; then
	   echo "Could not set domain name from $DOMFILE"
	fi
fi
#put the current domain name in the sendmail configuration file
domain=`/bin/domainname`

# Note that we will not invoke sendmail daemon here because Email Alerts
# only need to go out. WE donot want to receive any emails on switch
# so for sending sendmail daemon is not required. Only sendmail binary
# will be used send out emails in synchronous mode.
# 
if [ "$domain" = "" ]; then
$ECHO "Domain name is null. Email alerts will not be available."
skipsendmail=1
fi

if [ $skipsendmail -eq 0 ]; then
/bin/cat $CONFIG/mail/sendmail.cf | /bin/sed -e "s/^Dj\$w.*/Dj\$w\.${domain}/g" > $CONFIG/mail/sendmail.cf.new
/bin/mv $CONFIG/mail/sendmail.cf.new $CONFIG/mail/sendmail.cf
/bin/chmod 444 $CONFIG/mail/sendmail.cf

if [ ! -f /tmp/spool/mqueue ]; then
	/bin/mkdir -p /tmp/spool/mqueue
	/bin/chmod 755 /tmp/spool/mqueue
fi

fi



;;

'stop')
/usr/bin/killall -q sendmail
;;

*)
echo "usage: $0 {start |stop}"
;;

esac

