#ident	"@(#)mail:common/cmd/mail/smtpd/smtpinit	1.12"

if [ ! -d /usr/bin ]
then			# /usr not mounted
	exit
fi

if [ -z "$LC_ALL" -a -z "$LC_MESSAGES" ]
then
	if [ -z "$LANG" ]
	then
		LNG=`defadm locale LANG 2>/dev/null`
		if [ "$?" != 0 ]
		then LANG=C
		else eval $LNG
		fi
	fi
	export LANG
fi
LABEL="UX:$0"
CAT=uxrc

mldmode > /dev/null 2>&1
if [ "$?" = "0" ]
then			# Enhanced Security running
	exit
fi

case "$1" in
'start')
	pid=
	if [ -z "$_AUTOBOOT" ]
	then
		set -- `/sbin/ps -e | /usr/bin/egrep ' smtpd$'`
		[ $? -eq 0 ] && pid=$1
	fi
	if [ -z "$pid" ]
	then
		/usr/lib/mail/surrcmd/createSurr
		if [ -x /usr/lib/mail/surrcmd/smtpd ]
		then
			rm -f /etc/mail/smtpd.pid
			exec /usr/lib/mail/surrcmd/smtpd
		fi
	fi
	;;
'stop')
	if [ -z "$_AUTOKILL" -a -f /etc/mail/smtpd.pid ]
	then
		read pid < /etc/mail/smtpd.pid
		kill -9 $pid
	fi
	exec rm -f /etc/mail/smtpd.pid
	;;
*)
	USAGE="$0 { start | stop }"
	pfmt -l $LABEL -s action -g $CAT:4 "Usage: %s\n" "$USAGE"
	;;
esac
