#!/bin/sh
#
#	CacheBuild
#	By: Paul Balyoz <Paul.Balyoz@nau.edu>
#	Copyright (c) 1993-1995 by Paul A. Balyoz
#

# NOTE: ADJUST PATH BEFORE INSTALLING, if needed!
# This must include the directory where "nslookup" lives.
PATH=/usr/ucb:/bin:/usr/bin:/usr/etc:/usr/local/bin:/nau/local/bin:/nau/share/bin
export PATH

# Name of file to write the new root cache into
# (macroed in by Makefile)
OUT="root.cache"

# Front part of the name of the awk script we need to run
# (macroed in by Makefile)
AWKSCR="/usr/local/etc/cachebuild.awk"

# --------------------------------------------------------------------------

# Rotate filenames of any old root.cache files in current directory

rm -f $OUT.older
if test -f $OUT.old; then
	mv $OUT.old $OUT.older
fi
if test -f $OUT; then
	mv $OUT $OUT.old
fi

# Generate comment lines at top of root.cache

echo ";" > $OUT
echo "; root.cache built by $USER@`hostname` on `date`" >> $OUT
echo "; Automatically built by cachebuild, any changes you make may go away." >> $OUT
echo ";" >> $OUT
echo "" >> $OUT

# Generate body lines of root.cache and deal with errors.

nslookup << EOF | awk -f $AWKSCR >> $OUT
set type=NS
root
.
EOF

err=$?
if test $err -ne 0; then
	echo "Call to nslookup failed."
	rm -f $OUT
fi
exit $err
