#!/bin/sh
set -e
cd /var/spool/sn

EXPIRETIME=7d
test -f /etc/news/sn/debian-config && . /etc/news/sn/debian-config

for f in *
do
    case $f in
	=*)
	    # =junk or such junk
	    ;;
        \*)
            # empty spool dir
            ;;
        lost+found)
            # A whole mountpoint for news. Groovy. Ignore it.
            ;;
	*)
	    if [ -f "$f/.expire" ]
	    then
		/usr/sbin/snexpire "$f"
	    else
		if echo $EXPIRETIME | egrep '^[0-9]+[hdwmy]$' > /dev/null
		then
		    /usr/sbin/snexpire -$EXPIRETIME $f
		else
		    echo "EXPIRETIME is not set correctly. See /etc/news/sn/debian-config" >&2
		fi
	    fi
	    ;;
    esac
done

if [ "$RUNFROM" = cron ]; then
    /usr/sbin/snget >/dev/null 2>&1 &
fi
