#! /bin/sh
# mkhistory - rebuild history file and friends

# =()<. ${NEWSCONFIG-@<NEWSCONFIG>@}>()=
. ${NEWSCONFIG-/usr/lib/news/bin/config}

PATH=$NEWSCTL/bin:$NEWSBIN/expire:$NEWSBIN:$NEWSPATH ; export PATH
umask $NEWSUMASK

lock="$NEWSCTL/LOCK"		# modify name as appropriate
ltemp="$NEWSCTL/L.$$"
echo $$ >$ltemp
trap "rm -f $ltemp ; exit 0" 0 1 2 15
while true
do
	if newslock $ltemp $lock
	then
		trap "rm -f $ltemp $lock ; exit 0" 0 1 2 15
		break
	fi
	sleep 30
done

cd $NEWSARTS
find `ls | egrep -v '\.'` -type f -name '[0-9]*' -print | histinfo | sort |
	awk -f $NEWSBIN/expire/histdups | histslash >$NEWSCTL/history.n

cd $NEWSCTL
if egrep '^<swill@trash>	' history.n >/dev/null
then
	echo "$0: <swill@trash> found in history.n -- aborting" >&2
	exit 1
fi
mkdbm <history.n
mv history history.o &&		# install new ASCII history file
mv history.n history &&
rm -f history.pag &&		# and related dbm files
rm -f history.dir &&
mv hist.pag history.pag && mv hist.dir history.dir
