aboutsummaryrefslogtreecommitdiffstats
path: root/main/djbdns/dnscache.monthly
blob: 4e53fd6fdec6f97c1ba779a0ba0ca811e207fb4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/sh

if [ -f /etc/conf.d/dnscache ]; then
	. /etc/conf.d/dnscache
fi

if [ -z "$UPDATEHINTS" ]; then
	exit 0
fi

cd /etc/dnscache/servers
NEEDRESTART=
ZONES=`ls /etc/dnscache/servers`
for ZONEFILE in $ZONES; do
	# Convert symlinks to copies, so we can update it
	ZONE="$ZONEFILE"
	if [ -L $ZONEFILE ]; then
		DST="`readlink "$ZONEFILE"`"
		cp -f "$DST" "$ZONEFILE"
	fi

	if [ "$ZONE" == "@" ]; then
		ZONE="."
	fi

	if [ "$ZONE" != "." -o "$FORWARDONLY" = "" ]; then
		TMPF=`mktemp -t`
	
		# Refresh zone info
		dnsqr ns $ZONE | awk '/^answer: ./ { print $5 }' | sort -u | xargs dnsip > $TMPF

		grep "^$" $TMPF 1> /dev/null
		if [ $? != 0 ]; then
			cmp -s $ZONEFILE $TMPF
			if [ "$?" != 0 ]; then
				NEEDRESTART=yes
				cat $TMPF > $ZONEFILE
			fi
		fi
		rm $TMPF
	fi
done

if [ "$NEEDRESTART" ] && /etc/init.d/dnscache --quiet status; then
	/etc/init.d/dnscache --quiet restart
fi

exit 0