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

# Source common library
. /etc/init.d/functions

SENDMAIL=${USRSBINDIR}/sendmail
DOMAINNAME=${BINDIR}/domainname
DOMFILE=${CONFDIR}/domain
MAILCONFDIR=${CONFDIR}/mail
MAILCONF=${MAILCONFDIR}/sendmail.cf

export PATH

case "$1" in

'start')
    skipsendmail=0
    ${KILLALL} sendmail
    #set the domain from DOMFILE
    if [ -f $DOMFILE ]; then
	${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=`${DOMAINNAME}`

    # Note that we will NOT invoke the sendmail daemon here because
    # e-mail only needs to go out, not in. Consequently, because
    # we do not want to receive any e-mails on the system 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. E-mail alerts will not be available."
	skipsendmail=1
    fi

    if [ $skipsendmail -eq 0 ]; then
	/bin/sed -e "s/^Dj\$w.*/Dj\$w\.${DOMAIN}/g" < ${MAILCONF} > ${MAILCONF}.N
	/bin/mv ${MAILCONF}.N ${MAILCONF}
	/bin/chmod 444 ${MAILCONF}

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

'stop')
    ${KILLALL} sendmail
    ;;

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

esac

