#!/bin/csh -f
# this script runs the TechInfo WAIS index program from cron
# revised 2/24/93 - wade

# this is where the pips.web file can be located
set PIPS_WEB = "/mit/ti_data/admin/pips.web"

# this is where the working index files are stored .inv and .dct
set WORKING = "/afs/net.mit.edu/project/wais/autumn/techinfo/search_engine"

# this is where the binaries are
set WAIS_INDEXER = "/afs/net.mit.edu/project/wais/autumn/techinfo/search_engine/@sys/waisindex"

# mailing list
set MAIL = "wade@mit.edu, thorne@mit.edu"

# local log file
set LOCAL_LOG = "/tmp/wais_index_log"

/bin/rm -f $LOCAL_LOG

setenv KRBTKFILE /tmp/wais_tkt

# get a tgt to write file to afs volumn
/var/ti/local/krbtgp -s -keyfile /etc/ti_serve_key ti_serve

# get tokens
/bin/athena/aklog -c net.mit.edu

# make sure ti_data is attached so it can find the pips.web file
attach ti_data

/bin/rm -f ${WORKING}/INDEXLOG
date > $LOCAL_LOG
date
/bin/echo "Starting the indexer...." >> $LOCAL_LOG
$WAIS_INDEXER -d ${WORKING}/temp -stdin -mem 1 < $PIPS_WEB >& ${WORKING}/INDEXLOG

/bin/echo "Finished build." >> $LOCAL_LOG
date >> $LOCAL_LOG
date

# perform error checking
set EXIT = 0

if (! -r ${WORKING}/temp.inv ) then
        /bin/echo "Cannot access .inv file" >> load.log
        set EXIT = 1
endif

if (! -r ${WORKING}/temp.dct ) then
        /bin/echo "Cannot access .dct file" >> load.log
        set EXIT = 1
endif

# check status and send mail if the program terminated early.
set BYTES=`ls -l ${WORKING}/temp.inv | awk '{print $4}'`
if !(${BYTES}) then
        /bin/echo "*** Problems with build. Check temp.inv." >> $LOCAL_LOG
	set EXIT = 1
endif

# check status and send mail if the program terminated early.
set BYTES=`ls -l ${WORKING}/temp.dct | awk '{print $4}'`
if !(${BYTES}) then
        /bin/echo "*** Problems with build. Check temp.dct" >> $LOCAL_LOG
	set EXIT = 1
endif

if ($EXIT == 0) then
	/bin/mv -f ${WORKING}/temp.inv ${WORKING}/techinfo.inv
	/bin/mv -f ${WORKING}/temp.dct ${WORKING}/techinfo.dct
else
	/bin/echo "*** Process terminated ***" >> $LOCAL_LOG
	date >> $LOCAL_LOG
	/usr/ucb/mail -s "Wais index log" $MAIL < $LOCAL_LOG
endif

# remove tickets
kdestroy

