#!/bin/csh -f

#@(#)News with uqwk in SOUP file v. 2.0 Sep 1994. josdb@xs4all.nl (Jos den Bekker)

set workdir=/tmp/uqwk.$$
set polldir=~/poll
set date=`date +%d%m`
set nonomatch

if ( -d $workdir ) then
  echo ""
  echo "          Error! Working-directory $workdir already exists."
  echo ""
  exit 1
else
  mkdir $workdir
  if ( $status != 0 ) then
    echo ""
    echo "          Error! Unable to create working-directory $workdir"
    echo ""
    exit 1
  else
    cd $workdir
  endif
endif

if ( -e ~/.newsrc ) then
  cp ~/.newsrc ~/.newsrc.prev
  cp ~/.newsrc $workdir
else
  echo ""
  echo "           WARNING! File .newsrc does not exist."
  echo "           News cannot be collected."
  echo ""
  cd
  rm -rf $workdir
  exit 1
endif

uqwk -m +n +x +L -H$workdir -B0 >/dev/null
if ( $status != 0 ) then
  echo ""
  echo "           WARNING! An error occurred while collecting news"
  echo "           File .newsrc will be unchanged."
  echo ""
  cd
  rm -rf $workdir
  exit 1
endif

zip -mbqj /tmp news$date AREAS *.MSG
if ( $status != 0 ) then
  echo ""
  echo "        An error occured while zipping your files."
  echo "        News-output of uqwk in $workdir"
  echo ""
  echo "        Attention! File .newsrc will be changed."
  echo "        Old record in .newsrc.prev"
  echo ""
  cp $workdir/.newsrc $home
  exit 1
endif

if ( -e $polldir/news*.zip.* ) rm $polldir/news*.zip.*

if ( -e $polldir/news$date.zip ) mv $polldir/news$date.zip $polldir/news$date.zip.$$

mv news$date.zip $polldir
if ( $status != 0 ) then
  echo ""
  echo "        File news$date.zip could not be moved to $polldir"
  echo "        File is in $workdir"
  echo ""
  echo "        Attention! File .newsrc will be changed."
  echo "        Old record in .newsrc.prev"
  echo ""
  cp $workdir/.newsrc $home
  exit 1
endif

cp $workdir/.newsrc $home
cd
rm -rf $workdir
