#!/bin/csh -f

unlimit

setenv KRBTKFILE /tmp/tkt_lopip_nightly
set PPDIR=/afs/sipb.mit.edu/project/periodic-postings
set POSTER="/usr/spool/faq_server/bin/post_faq.pl -quiet 1 -sigfile none"
set D=${PPDIR}/data/
#set ARCH=sun4os
set RCSDIR=/usr/local/bin/
set MAKEDEBUG=
set DEBUG=
set path = (${RCSDIR} /usr/athena/bin /etc /usr/etc /bin $path)

# setenv because used by mail_policy.pl

setenv NADIR $PPDIR/news.answers

# setenv because used by make-header.pl

setenv PPNEWS $PPDIR/data/periodic-posting-news
# we need this to because you can't use ':h' with environment
# variables in csh (a bug which is fixed in tcsh)
set ppnews = $PPNEWS

set today = `date`

if ("$today" =~ Sun*) then
	mail news-answers-request@MIT.Edu <<EOF
To: news-answers-request@MIT.Edu
Subject: Automatic weekly reminder: FAQ archive needs to be cleaned up

This message is an automatic weekly reminder that the periodic FAQ
archive cleanup on rtfm.mit.edu needs to be performed.  This message
should remain in the *.answers queue until the cleanup is performed,
and the moderator who does the cleanup should lock this message while
doing it.  Don't forget that packing the *.answers, faq-maintainers
and faq-maintainers-announce mail archives is also part of the regular
cleanup.
EOF
endif

/usr/local/bin/ksrvtgt rcmd `/bin/hostname` -l 1275
chown jik ${KRBTKFILE}
/bin/athena/aklog sipb.mit.edu

$NADIR/mail_policy.pl

cd $PPDIR/src
make $MAKEDEBUG all install > /dev/null || goto done
set DIFFTIME=`awk '/^periodic-postings\/diff/ {print $3}' ${D}faq.config` \
	|| goto done
${RCSDIR}rcs -l -q $ppnews || goto done
su jik -c "/bin/athena/aklog sipb.mit.edu; $POSTER $DEBUG -config ${D}faq.config; /bin/athena/unlog" || goto done
/bin/athena/aklog sipb.mit.edu
set NEWDIFFTIME=`awk '/^periodic-postings\/diff/ {print $3}' ${D}faq.config` \
	|| goto done
if ("$DIFFTIME" != "$NEWDIFFTIME") then
	chmod +w $ppnews || goto done
	cp /dev/null $ppnews || goto done
	(cd ${ppnews:h}; \
         ${RCSDIR}ci -u -q -m"Automatic clearing of posted news" $PPNEWS) || goto done
	make diff-base > /dev/null || goto done
endif

done:

/bin/athena/unlog
/usr/athena/bin/kdestroy >&/dev/null || cp /dev/null ${KRBTKFILE}
