#!/bin/sh
# WARNING: This file was auto-generated. Do not edit!
dnsip="/usr/bin/dnsip"
dnsqr="/usr/bin/dnsqr"
sysconfdir=/etc/indimail
servicedir=/service
svc="/usr/bin/svc"
mv=$(which mv)
cp=$(which cp)

if [ ! -f $svc ] ; then
	echo "could not find $svc" 1>&2
	exit 1
fi
if [ -f $sysconfdir/dnsroots.global ] ; then
	$mv $sysconfdir/dnsroots.global $sysconfdir/dnsroots.global.old
	if [ $? -ne 0 ] ; then
		exit 1
	fi
fi
${dnsip} $( ${dnsqr} ns . | awk '/answer:/ { print $5; }' | sort ) \
  > $sysconfdir/dnsroots.global
if [ $? -ne 0 ] ; then
	exit 1
fi
if [ -f $sysconfdir/dnsroots.local ] ; then
  /bin/cat $sysconfdir/dnsroots.local $sysconfdir/dnsroots.global > $servicedir/dnscache/root/servers/@
else
  $cp $sysconfdir/dnsroots.global $servicedir/dnscache/root/servers/@
fi
if [ $? -ne 0 ] ; then
	exit 1
fi
exec ${svc} -du $servicedir/dnscache
