#!/bin/sh

ROOTFILE=./db.root

echo '@l_prefix@' | egrep '^@l_' | egrep 'prefix@$' >/dev/null
if [ $? -eq 0 ]; then
    DIG='dig'
else
    DIG='@l_prefix@/bin/dig'
fi

date=`date '+%Y-%m-%d'`
cat >$ROOTFILE <<EOT
;;
;;  db.root -- Internet Root Nameservers
;;  DO NOT EDIT, IT WAS AUTOMATICALLY CREATED ON $date BY db.root.sh!
;;

EOT
for i in A B C D E F G H I J K L M; do
    ${DIG} @$i.ROOT-SERVERS.NET . NS >$ROOTFILE.raw && break
done
[ -f $ROOTFILE.raw ] || exit 1
awk <$ROOTFILE.raw '
  /IN[ 	]NS/ { printf("%-20s 99999999  IN  NS  %s\n", $1, $NF); }
  /IN[ 	]A/  { printf("%-20s 99999999  IN  A   %s\n", $1, $NF); }
' |\
egrep -v '^;' |\
sort >>$ROOTFILE
echo "" >>$ROOTFILE
rm $ROOTFILE.raw

