PACK=/usr/pack/djbdns-1.04-to
PATH=$PACK/sun4m-sun-solaris2.6/bin:/usr/bin:$PATH
export PATH
CACHEDIR=/var/djbdnscache   # where should dnscache run
ACCEPT="129.132 172.16"     # accept queries from these nets
# our local dns servers
SERVERS="129.132.98.12 129.132.250.220 129.132.250.2"

# they know all about the following address ranges
DOMAINS="ethz.ch 16.172.in-addr.arpa 132.129.in-addr.arpa"

if [ ! -d $PACK/sun4m-sun-solaris2.6/bin ]; then
  echo can not find djbdns ... not starting dnscache
  exit 1
fi


case "$1" in
  start)        echo "Starting dnscache."
                if [ ! -d $CACHEDIR ]; then
                    echo "Setting up dnscache"
                    cp $PACK/template/dnsroots.global /etc
		    HOST=`cat /etc/nodename`
		    HOSTIP=`getent hosts $HOST | awk '{print $1}'`
                    dnscache-conf daemon daemon $CACHEDIR $HOSTIP
                    # allow queries from these IP ranges
                    for x in $ACCEPT; do
                        touch $CACHEDIR/root/ip/$x
                    done
                    for x in $DOMAINS; do
                        for s in $SERVERS; do
                              echo $s >>$CACHEDIR/root/servers/$x
                        done
                    done                    
                fi                     
                ( cd $CACHEDIR 
                  exec ./run &
                  echo $! > $CACHEDIR/dnscache.pid ) | \
                ( cd $CACHEDIR/log 
                  exec ./run & )
                
  ;;
  stop)         if [ -f $CACHEDIR/dnscache.pid ]; then
                   echo "Shutting down dnscache."
                   kill `cat $CACHEDIR/dnscache.pid`
                   rm -f $CACHEDIR/dnscache.pid
                else
                   echo "dnscache not running"
                fi
  ;;
  *)            echo "Usage: $0 {start|stop}"
    exit 1
esac
exit 0
