#!/bin/sh

# WARNING: some hard-coded paths.  {sigh}

. /var/news/etc/innshellvars
cd /var/news

ctlinnd throttle "Rebuilding history database"
$NEWSBIN/expire.pl < $HISTORY > $HISTORY.n
STATUS=$?
chown news $HISTORY.n
chgrp news $HISTORY.n
chmod 664 $HISTORY.n
if [ $STATUS ] ; then
        if makehistory -i -r -f history.n ; then
                chown news $HISTORY.n $HISTORY.n.pag $HISTORY.n.dir
                chgrp news $HISTORY.n $HISTORY.n.pag $HISTORY.n.dir
                chmod 664 $HISTORY.n $HISTORY.n.pag $HISTORY.n.dir
                mv history.n history
                mv history.n.pag history.pag
                mv history.n.dir history.dir
                ctlinnd go "Rebuilding history database"
                exit 0
        else
                echo "Makehistory error; old files not replaced"
                ctlinnd go "Rebuilding history database"
                exit 2
        fi
else
        echo "Problem rebuilding history file; old file not replaced"
        ctlinnd go "Rebuilding history database"
        exit 1
fi
# NOTREACHED
