#!/bin/sh
#
# Leafnode cron job. To be run daily.
# By Joey Hess <joeyh@master.debian.org>
# with bugs by Mark Brown <broonie@debian.org>

# Get configuration
. /etc/news/leafnode/debian-config

# Do the cd so that it doesn't matter if we cannot read /root.
cd /

# Expire old news.
# Ignores the messages texpire generates to stdout about which articles it
# expires. If you'd rather get that info mailed to you, remove the >/dev/null
if [ -x /usr/sbin/texpire ]; then
   su news -c "/usr/sbin/texpire" >/dev/null
fi

# Run touch_newsgroups if the user wants it and we can
if [ -x /usr/bin/touch_newsgroup -a -f /etc/news/leafnode/touch_groups ]; then
   if /usr/bin/perl -MNet::NNTP < /dev/null 2>/dev/null ; then
      su news -c "/usr/bin/touch_newsgroup -f /etc/news/leafnode/touch_groups"
   else
      cat << EOF
      You have requested that touch_newsgroup be run to mark the groups 
      listed in /etc/news/leafnode/touch_groups as read.  This requires
      that both perl and the Net::NNTP module (part of libnet-perl) are
      avalible, which does not appear to be the case:

EOF
      /usr/bin/perl -MNet::NNTP < /dev/null
   fi
fi

# Move failed postings back into outgoing queue.  This works around a
# buglet when posting to multiple servers.
if [ "" != "`ls /var/spool/news/failed.postings/`" ]; then
   mv /var/spool/news/failed.postings/* /var/spool/news/out.going
fi

# Get new news.
if [ "$NETWORK" = "permanent" -a -x /usr/sbin/fetchnews ]; then
   su news -c "/usr/sbin/fetchnews"
fi
