#!/bin/sh
# $Id: rebuild-wrapper,v 1.3 2001/05/31 19:12:05 zacheiss Exp $

# This script was originally written by jhawk, adapted by yak for
# whichlocker release 3.
#
# Note: this script should be run in a PAG of its own (it will clobber
# tokens).

DATAROOT=/mit/outland/share/whichlocker
LOCKERLIST=${DATAROOT}/locker-list
DATABASE=${DATAROOT}/program-database
KRBTKFILE=/tmp/tkt_root.$$ export KRBTKFILE
KRBTGP=/usr/local/bin/krbtgp
MAILTO=yak@mit.edu
PATH=/bin export PATH
OUT=/tmp/whichlocker-build-out.$$

exec 5>&1 6>&2 >$OUT 2>&1

$KRBTGP -s -lifetime 60 -keyfile /usr/local/etc/srvtab daemon.`hostname -s`
/bin/athena/aklog -cell athena.mit.edu sipb.mit.edu
/usr/athena/bin/kdestroy >/dev/null 2>&1		# HOKEY!
/bin/athena/attach -q outland

# stdout has status messages, stderr has errors
/usr/local/bin/whichlocker <$LOCKERLIST --build --db=${DATABASE}.new >/dev/null

test $? -eq 0 && mv -f ${DATABASE}.new $DATABASE

/bin/athena/unlog

exec 1>&5 2>&6
test -s $OUT && /usr/bin/Mail -s 'whichlocker build output' yak@mit.edu <$OUT 

rm -f $OUT

exit 0
