#!/bin/bash
# Copyright (C) 2004 Networks Associates Technology Inc. All rights reserved.
#
# spamassassin_jail This script starts and stops the mcafee-spamd daemon in a jail
#
# chkconfig: 2345 99 30
#
# description: mcafee-spamd is a daemon process which uses SpamAssassin to check
#              email messages for SPAM.  Here it is run in a jail and used by
#              the WebShield email proxies.
#
# Place it last in tbe boot sequence as spamassassin goes for all of the memory on the box

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0

# Source spamassassin configuration.
if [ -f /etc/sysconfig/spamassassin ] ; then
        . /etc/sysconfig/spamassassin
else
        OPTIONS="-d -c -a"
fi

# Source Webshield configuration
if [ -f $NETAWSS/.profile.vars ]; then 
 . $NETAWSS/.profile.vars 
else 
 . /var/NAIENV/.profile.vars 
fi 
PATH=$wsPATH:$PATH

# Source WebShield SpamAssassin functions
. spam-functions

# See how we were called.
case "$1" in
  start)
	# Start daemon.
	echo -n "Starting mcafee spamassassin : "
	MakeSpamJail >/dev/null 2>&1 &&
	    LC_ALL=C daemon chroot "$SPAMJAIL" mcafee-spamd $OPTIONS
	MakeRulesInfo >/dev/null 2>&1 &	# background build rules_info.xml files
	RETVAL=$?
        echo
        [ $RETVAL = 0 ] && touch /var/lock/subsys/spamassassin_jail
        ;;
  stop)
        # Stop daemons.
	echo -n "Shutting down mcafee spamassassin : "
        killproc mcafee-spamd
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && rm -f /var/lock/subsys/spamassassin_jail
        ;;
  restart)
        $0 stop
        $0 start
        ;;
  status)
	status mcafee-spamd
	;;
  *)
	echo "Usage: $0 {start|stop|restart|status}"
	exit 1
esac

exit 0
