#Message-Id: <199304292351.AA06468@rainbow.cse.nau.edu>
#From: root@rainbow.cse.nau.edu (System Administrator)
#Date: Thu, 29 Apr 1993 16:51:57 MST
#To: vixie
#Subject: Re: send me your tools
#
#Here's a little tool I wrote for Bind, you can include it in the
#"contrib" area of 4.9.X if you want.  It builds a new root cache file
#for you, by querying any root name server it can still talk to.
#Sorta nice for automation, like for sites that don't have a full-time
#network administrator.
#
#I haven't tried it out under Bind 4.9, just 4.8.3.
#You might give it a go -- hopefully no modifications will be necessary.
#Below is the "shar" archive.  No man-page, just a complete README.
#
#                                                -- paul balyoz
#

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  README Makefile cachebuild.SH cachebuild.awk
# Wrapped by root@rainbow on Sun Apr 18 20:42:47 1993
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'README' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'README'\"
else
echo shar: Extracting \"'README'\" \(2963 characters\)
sed "s/^X//" >'README' <<'END_OF_FILE'
X
X			CACHE BUILD PROGRAM
X
XDESCRIPTION:
X
XThis utility will build the latest root domain server cache for your
XBIND nameserver data base, by running nslookup to query one of the known
Xroot domain servers, and passing the output through an awk script to
Xgenerate the file.  Simple, really.
X
XOf course, your name server's current root.cache must have at least
XONE working root domain server and its address, or you can't get to
Xa root server to ask about other root servers.  (But then, you'd know
Xit by now, your nameserver wouldn't be working!)  This will build a more
Xup-to-date root.cache than the one that comes with the BIND distribution.
X
XRun cachebuild every month or two to keep your nameserver up to date.
XYou can run it from cron if you're brave.
X
XCachebuild should NOT be run on root name servers themselves --
Xthose sites are much too important to trust automated software!
XCachebuild is intended to be used by normal Internet sites.
X
XHOW IT WORKS:
X
XThe file "root.cache" is created in your currently directory when
Xcachebuild is run.  Don't worry though, if there's an existing file
Xby that name it will be moved to "root.cache.old" (and similarly,
Xan existing file by that name is moved to "root.cache.older").
X
XThere's no guarantee that the output from this program is correct;
Xafter you generate a new root.cache file, examine it carefully and
Xcompare it with your old one.  Keep your old root.cache files around,
Xjust in case!
X
XThe only challenge is adjusting the awk script to work with the version
Xof BIND that you happen to have installed.  The awk script included
Xworks with nslookup from BIND version 4.8.3 and from SunOS 4.1.3.
XYou can modify it as needed.
X
XINSTALLATION:
X
X1.  Edit the Makefile to make any modifications for your local site.
X2.  Type "make" to build the shell script cachebuild.
X3.  Type "make install" to install the program and awk script.
X4.  Move into a safe place (cd /tmp) and try running cachebuild.
X    If you use the C-shell, you may need to type "rehash" first.
X    Cachebuild should create the file root.cache in your current
X    directory.  Examine it.
X5.  If all is OK, you can safely run it in your name-server directory
X    or just copy the new root.cache over there.
X    If not, fix it, "make clean" and try again.
X
XERROR MESSAGES:
X
XIf it succeeds, cachebuild will return the usual exit status of 0.
XThe only error message cachebuild generates is:
X
X		Call to nslookup failed.
X
Xwhich means that nslookup exited with a non-zero status value
X(indicating an error of some sort).  Error messages from nslookup
Xthat are sent to stderr will come out on stderr from cachebuild, too.
X
XCOMPLAINTS DEPT:
X
XYea, I know, I should rewrite it in perl.  ENOTIME.
X
X--
XPaul Balyoz, Senior Systems Programmer  pab@rainbow.cse.nau.edu
XNorthern Arizona University             root@naucse.cse.nau.edu
XPO Box 15600, Flagstaff AZ 86011        {pab,root}@sunset.cse.nau.edu
XNICname: PB1                            ...arizona!naucse!root
END_OF_FILE
if test 2963 -ne `wc -c <'README'`; then
    echo shar: \"'README'\" unpacked with wrong size!
fi
# end of 'README'
fi
if test -f 'Makefile' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Makefile'\"
else
echo shar: Extracting \"'Makefile'\" \(713 characters\)
sed "s/^X//" >'Makefile' <<'END_OF_FILE'
X#
X# Makefile for the CACHE BUILD package.
X#
X
X# where to put the main executable shell script
XBIN=/usr/com/bin
X
X# where to put the awk script  (note: change this in cachebuild, too!)
XLIB=/usr/com/lib
X
X# name of root.cache type output file
XCACHEFILE=root.cache
X
X# Note: fix PATH variable in cachebuild.SH script before building.
X
X
Xall:	cachebuild
X
Xcachebuild:	cachebuild.SH
X	echo "s,CBAWKPATH,$(LIB)/cachebuild.awk,g" > fix.sed
X	echo "s,CACHEFILE,$(CACHEFILE),g" >> fix.sed
X	sed -f fix.sed < cachebuild.SH > cachebuild
X	rm -f fix.sed
X	chmod 755 cachebuild
X
Xinstall:	all
X	install -c -m 755 -o bin -g bin cachebuild $(BIN)
X	install -c -m 644 -o bin -g bin cachebuild.awk $(LIB)
X
Xclean:
X	-rm -f cachebuild root.cache*
END_OF_FILE
if test 713 -ne `wc -c <'Makefile'`; then
    echo shar: \"'Makefile'\" unpacked with wrong size!
fi
# end of 'Makefile'
fi
if test -f 'cachebuild.SH' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'cachebuild.SH'\"
else
echo shar: Extracting \"'cachebuild.SH'\" \(913 characters\)
sed "s/^X//" >'cachebuild.SH' <<'END_OF_FILE'
X#!/bin/sh
X#		ROOT CACHE PROGRAM
X#	By Paul Balyoz <pab@rainbow.cse.nau.edu>  03/15/91
X#
X
X# Name of file to write the new root cache into
XOUT="CACHEFILE"
X
X# Front part of the name of the awk script we need to run
XAWKSCR="CBAWKPATH"
X
X# This must include the directory where "nslookup" lives
XPATH=/usr/ucb:/bin:/usr/bin:/usr/etc:/usr/local/bin:/usr/com/bin
Xexport PATH
X
X# --------------------------------------------------------------------------
X
Xrm -f $OUT.older
Xif test -f $OUT.old; then
X	mv $OUT.old $OUT.older
Xfi
Xif test -f $OUT; then
X	mv $OUT $OUT.old
Xfi
X
Xecho ";" > $OUT
Xecho "; root.cache built by $USER@`hostname` on `date`" >> $OUT
Xecho "; Automatically built by cachebuild, any changes you make may go away." >> $OUT
Xecho ";" >> $OUT
Xecho "" >> $OUT
X
Xnslookup << EOF | awk -f $AWKSCR >> $OUT
Xset type=NS
Xroot
X.
XEOF
X
Xerr=$?
Xif test $err -ne 0; then
X	echo "Call to nslookup failed."
X	rm -f $OUT
Xfi
Xexit $err
END_OF_FILE
if test 913 -ne `wc -c <'cachebuild.SH'`; then
    echo shar: \"'cachebuild.SH'\" unpacked with wrong size!
fi
chmod +x 'cachebuild.SH'
# end of 'cachebuild.SH'
fi
if test -f 'cachebuild.awk' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'cachebuild.awk'\"
else
echo shar: Extracting \"'cachebuild.awk'\" \(1328 characters\)
sed "s/^X//" >'cachebuild.awk' <<'END_OF_FILE'
X#
X# cachebuild.awk
X# Awk script for cachebuild, already designed to parse:
X#	nslookup output from pure BIND 4.8.3,
X#	nslookup that comes with SunOS 4.1.3.
X#
X
X# Process NS RRs.  These give the names of the root domain servers.
X
X$2=="nameserver" && $3=="=" {
X	roothost[$4] = 1;
X}
X
X# Process A RRs.  These map domain server names to addresses.
X# Accumulate these into a space-delimited string; we will break them apart later.
X# Note that there may be more than one A RR per root server.
X
X($2=="inet" || $2=="internet") && $3=="address" && $4=="=" {
X	if (roothost[$1] == 1)
X		hostaddr[$1] = hostaddr[$1] " " $5;
X}
X
X# Now that we parsed all the records, let's print the rest of the root cache.
X# We break the multiple address strings apart with the "split" function.
X
XEND {
X	print ";"
X	print "; Initial cache data for root domain servers."
X	print ";"
X	print ""
X	printf (".");
X	for (i in roothost) {
X		print "			99999999	IN	NS	" i ".";
X	}
X	print ""
X	print ";"
X	print "; Prep the cache (hotwire the addresses).  Order does not matter."
X	print ";"
X	print ""
X	for (i in hostaddr) {
X		ips = hostaddr[i];
X		n = split (ips, hstuff, " ");
X		for (j=1; j<=n; j++) {
X			printf ("%s.", i);
X			l = length (i ".");
X			if (l < 8) printf ("	");
X			if (l < 16) printf ("	");
X			if (l < 24) printf ("	");
X			print "99999999	IN	A	" hstuff[j];
X		}
X	}
X}
END_OF_FILE
if test 1328 -ne `wc -c <'cachebuild.awk'`; then
    echo shar: \"'cachebuild.awk'\" unpacked with wrong size!
fi
# end of 'cachebuild.awk'
fi
echo shar: End of shell archive.
exit 0
