Created
October 14, 2016 22:56
-
-
Save alainwolf/b2f40654d31626703d1398b689b42276 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# /etc/cron.daily/unbound-adblock-update | |
# | |
# Download a list of known ad-server hostnames from https://pgl.yoyo.org/as/ | |
# for use in unbound recursive name server to block web ads on the local lan. | |
# See https://pgl.yoyo.org/as/ | |
# Terminate on first error | |
set -e | |
# URL to download from | |
download_url="https://pgl.yoyo.org/as/serverlist.php?hostformat=unbound&mimetype=plaintext" | |
# Unbound configuration include file | |
list_file="adservers.conf" | |
# Temporary directory to download to | |
temp_dir=`mktemp --directory` | |
# Unbound configuration directory | |
unbound_dir="/etc/unbound/unbound.conf.d" | |
# Download file | |
download_file="$temp_dir/$list_file" | |
# unbound configuration file | |
unbound_file="$unbound_dir/$list_file" | |
# Fetch the latest ad-server list, if newer from what we have | |
/usr/bin/curl --silent --remote-time --show-error --location --compressed \ | |
--time-cond $unbound_file \ | |
--output $download_file \ | |
$download_url | |
# Check if the download file exists and is not empty | |
if [ -s $download_file ]; then | |
# Replace the old file with the freshly downloaded file | |
/bin/cp --backup=numbered --update --preserve=timestamps $download_file \ | |
$unbound_file | |
# Set permissions for the unbound daemon | |
/bin/chown unbound:unbound $unbound_file | |
/bin/chmod 0640 $unbound_file | |
# Check configuration files syntax | |
/usr/sbin/unbound-checkconf | |
# Reload unbound server configuration | |
/usr/sbin/unbound-control -q reload | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment