1
0
Fork 0
knowledge-base/KB/Linux/Server/ArchLinux/unbound/scripts/unbound_update_adservers

54 lines
1.2 KiB
Text
Raw Normal View History

2022-09-04 12:54:22 +00:00
#!/bin/bash
# config
hostname=$(hostname)
2022-09-04 13:16:19 +00:00
mail_from="alias@domain.tld";
mail_to="alias@domain.tld";
2022-09-04 12:54:22 +00:00
mail_enabled="true"
# helper
send_error() {
local CONTENTS=$1;
# if enabled, send mail on error
if [ $mail_enabled == 'true' ]; then
SUBJECT="[$hostname] Failed to update unbound adservers";
echo "${CONTENTS}" | mailx -Ssendwait -s "${SUBJECT}" $mail_to;
fi
echo "${CONTENTS}";
}
# main
bURL="https://raw.githubusercontent.com/oznu/dns-zone-blacklist/master/unbound/unbound-nxdomain.blacklist"
blacklist="$(curl -s -L --fail "$bURL")"
sha256="$(curl -s -L --fail "${bURL}.checksum")"
test -n "$blacklist"
res=$?;
if [ $res != 0 ]; then
send_error "Cannot download blacklist.";
exit 1;
fi
test -n "$sha256"
res=$?;
if [ $res != 0 ]; then
send_error "Cannot download checksum.";
exit 1;
fi
d_sha256="$(echo -n "$blacklist" | sha256sum)"
test "${d_sha256#$sha256}" != "$d_sha256"
res=$?;
if [ $res != 0 ]; then
send_error "Checksum doesn't match the downloaded file";
exit 1;
fi
echo "$blacklist" > /etc/unbound/adservers
res=$?;
if [ $res != 0 ]; then
send_error "Cannot apply file";
exit 1;
fi