Ajouter 'unbound/update-root-dns.sh'

This commit is contained in:
virtubox 2018-05-03 00:53:03 +00:00
parent 4918f366f0
commit fc547bc22c
1 changed files with 46 additions and 0 deletions

View File

@ -0,0 +1,46 @@
#!/bin/sh
TmpName=$(mktemp)
TmpDiff=$(mktemp)
TmpErr=$(mktemp)
REPORT_EMAIL="admin"
URL="https://www.internic.net/domain/named.cache"
wget -nv $URL -O $TmpName 2> $TmpErr
# On intercepte toute erreur
# et on stoppe le script dans ce cas
# On continue sinon
if [ "$?" -ne 0 ];then
printf "\nScript was stopped at this point. A manual action may be required.\n" >> $TmpErr
mail -s "[DNS - $(uname -n)] Root hints file download failed" $REPORT_EMAIL < $TmpErr
rm $TmpErr
rm $TmpDiff
rm $TmpName
exit 0
else
rm $TmpErr
shaTMP=$(sha512sum $TmpName | awk '{print $1}')
shaHINTS=$(sha512sum /var/lib/unbound/root.hints | awk '{print $1}')
if [ $shaTMP = $shaHINTS ]; then
# Si le fichier récupéré est identique à celui
# utilisé par Unbound, on fait... rien
rm $TmpName
exit 0
else
printf "A new root hints file was spotted on InterNIC server.\nFile downloaded and old root.hints file replaced.\nHere is the diff:\n\n" > $Tmp$
diff $TmpName /var/lib/unbound/root.hints >> $TmpDiff
printf "\n\n" >> $TmpDiff
mv -f $TmpName /var/lib/unbound/root.hints
chown unbound: /var/lib/unbound/root.hints
chmod 644 /var/lib/unbound/root.hints
sleep 5
service unbound restart
printf "Unbound status is $(service unbound status | grep Active | awk '{print $2 " " $3}')\n" >> $TmpDiff
mail -s "[DNS - $(uname -n)] Update in Root Hints" $REPORT_EMAIL < $TmpDiff
rm $TmpDiff
fi
fi
exit 0