#!/bin/sh
#
#  Run the mailer in master mode, checking for mail to send to the world.
#  By running this script in stead of running "mbcico -r1" from cron
#  directly you prevent unnecessary entries in the logfile from "mbcico".
#  This version also lets only one mbcico run the outbound sessions.
#
#  26-Aug-1999 MB.

if [ -z "$MBSE_ROOT" ]
then
     export MBSE_ROOT=`cat /etc/passwd | grep mbse: | awk -F ':' '{ print $6}'`
fi

# Check for "mail to transmit"
if [ ! -f $MBSE_ROOT/sema/scanout ]
then
    exit 0
fi

# Check if "mailer is already running"
if [ -f $MBSE_ROOT/sema/mbcico ]
then
    exit 0
fi

# Check if "bbs is closed or down"
if [ -f $MBSE_ROOT/sema/bbsclosed ]
then
    exit 1
fi

# Check for UPS alarm, if so don't call any systems.
if [ -f $MBSE_ROOT/sema/upsalarm ]; then
    exit 0
fi

# Lock the mailer and send the mail.
touch $MBSE_ROOT/sema/mbcico
$MBSE_ROOT/bin/mbcico -r1
rm -f $MBSE_ROOT/sema/mbcico

