#!/bin/sh
#
PATH=$PATH:/home/news/bin
echo ----------------------------------------------------------------
umask 2
WORK=/home/news/suck
SCRIPT=$WORK/suck/suck.sh
SUCK=$WORK/suck/suck
TMP=/home/news/suck/tmp
RNEWS=/home/news/bin/rnews
# Server list has matching port list in $*.
SERVERLIST="This.News.Source That.News.Source"
set -- 119 119	# matched against SERVERLIST.
cd $WORK
# Lock ourselves down.
chmod -x $SCRIPT
# Go get a pile of news.
for server in $SERVERLIST
do
  # go get 'em.
  port=$1
  BATCH=$WORK/In.$server$$
  time $SUCK $server -N $port -bi $BATCH -dt $TMP -dm $TMP -dd . -p .$server -c -H
  if [ -f $BATCH ]
  then
    cat $BATCH | xargs ls -l | awk '{ print $5 " " $9 }' | while read sz fn ; do echo "#! rnews" "$sz" ; cat "$fn" ; done | $RNEWS -v
    rm -f $BATCH
    ( cd $TMP ; find . -type f -name \*.$server | xargs rm -f )
  fi
  # Next host.
  shift # port selection, to go with host.
done
# Unlock.
chmod +x $SCRIPT
exit 0
