#!/bin/sh
#
if [ "$#" -ne 1 ] ; then
    echo Usage: rpost.sh ServerName
    exit 1
fi
SERVER="$1"
#
PATH=$PATH:/home/news/bin
umask 2
WORK=/home/news/suck
SCRIPT=$WORK/suck/rpost.sh
RPOST=$WORK/suck/rpost
FILTER=$WORK/suck/filter
FILTERFILE=$WORK/tmp/.filter
OUTGOING=/home/news/spool/outgoing
ARTICLES=/home/news/spool/articles
#
# Should we bother?
if [ ! -s $OUTGOING/$SERVER -a ! -s $OUTGOING/$SERVER.rpost ]
then
    exit 0
fi
echo ----------------------------------------------------------------
cd $WORK
#
# Lock ourselves down.
chmod -x $SCRIPT
#
# Prep batch.
mv $OUTGOING/$SERVER $OUTGOING/$SERVER.hold
ctlinnd -s flush $SERVER
cat $OUTGOING/$SERVER.hold | while read smtoken x
do
    sm -i $smtoken | sed -e 's;: ;/;'
done >> $OUTGOING/$SERVER.rpost
rm -f $OUTGOING/$SERVER.hold
#
# Shovel bits.
$RPOST $SERVER -b $OUTGOING/$SERVER.rpost -d -p $ARTICLES -f $FILTER '$$'o=$FILTERFILE '$$'i $FILTERFILE
#
# Unlock.
chmod +x $SCRIPT
exit 0
