#!/bin/sh
#
#  This script should be used as a last resort and only in times of 
#  emergency. Prior to posting it is a good idea to flush the outbound
#  queue.  This has seen use and it saved me from making major mistakes
#  more than once. Use with care...
#
# =()<. ${NEWSCONFIG-@<NEWSCONFIG>@}>()=
. ${NEWSCONFIG-/usr/lib/news/bin/config}
 
#
# CHANGE THESE VARIABLES
# newsgroup moderator login account name
#
MODERATOR=kent
NEWSGROUP="comp/sources/misc"
MAILER=/usr/ucb/Mail

PATH=$NEWSCTL/bin:$NEWSPATH ; export PATH
umask $NEWSUMASK
 
origpath="$PATH"

# lock out the Cnews batcher in case it starts up 
lock="$NEWSCTL/LOCKbatch"
ltemp="$NEWSCTL/L.$$"
echo $$ >$ltemp
trap "rm -f $ltemp ; exit 0" 0 1 2 15
if $NEWSBIN/newslock $ltemp $lock
then
        trap "rm -f $ltemp $lock ; exit 0" 0 1 2 15
else
	echo "batcher has it locked..."
        exit 0
fi

cd $NEWSARTS/out.going
 
# Determine what systems are being requested.
case $# in
        0) syses=`ls -tr | egrep -v '^[@.]'`       # oldest first
        ;;
        *) syses="$*"
        ;;
esac

#
# time to use that mop...
#

for sys in $syses
do
    tmpfl=mop.$$
    here=$NEWSARTS/out.going/$sys
    cd $here
    PATH=$here:$origpath ; export PATH

    #
    # Time to cleanup
    #

    for i in togo*
    do
        flname=CSM.$i
        grep -v $NEWSGROUP $i > $flname
        grep $NEWSGROUP $i | tee $tmpfl
        if [ -s $tmpfl ]
        then
            cat  $tmpfl | $MAILER -s "$here/$sys cleanup" $MODERATOR
        fi
        cp $flname $i
        rm $flname $tmpfl
    done
done    
