#! /bin/sh
##  extracted from news.daily.  Renumber each group.  This avoids
#  the long outage currently caused when "ctlinnd renumber ''" is done.

##  =()<. @<_PATH_SHELLVARS>@>()=
. /usr/local/news/lib/innshellvars

renice 10 $$ >/dev/null 2>&1
if ctlinnd mode | grep 'Server running' >/dev/null ; then
    while read GROUP hi lo flag ; do
	d=`echo ${GROUP}|tr . /`
	if [ -d ${SPOOL}/${d} ] ; then
#		Look for the lowest numbered article
		a=''
		for a in `ls -f ${SPOOL}/${d} | grep '^[0-9]*$' | sort -n | head -100`
		do
			if [ -z "$a" -o -f ${SPOOL}/${d}/$a ] ; then
				break
			fi
		done
		if [ -z "$a" ] ; then
#			empty newsgrup
			continue
		fi
		if [ $a -eq $lo ] ; then
#			already renumbered
			continue
		fi
		until ctlinnd -s -t 90 setlow ${GROUP} $a
		do
		    echo -n "retrying ${GROUP} "
		    sleep 10
		done
	fi
    done <${ACTIVE}
else
    echo 'can not renumber unless server is running'
fi
