-
-
Save roylez/0f908eaa561036f05f2d to your computer and use it in GitHub Desktop.
Adblock script for OpenWRT
This file contains hidden or 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
# Adblock script for OpenWRT | |
# (c) 2015 by Roy Zuo | |
# | |
# This is another adblocker script for OpenWRT. Simply run this script as a | |
# daily cronjob on your OpenWRT-router. This works since OpenWRT | |
# revision 39312 [1] and does not manipulate any files in /etc/. | |
# Instead, this adds the adblock serverlist as a separate file | |
# to /tmp/. | |
# | |
# Use this file with Unbound DNS resolver. | |
# | |
# [1] See https://dev.openwrt.org/changeset/39312/ | |
# URL for latest block list | |
srcurl="http://pgl.yoyo.org/adservers/serverlist.php?hostformat=one-line&showintro=0&mimetype=plaintext" | |
# Set destination file | |
dstfile="/tmp/unbound_adblock.conf" | |
# And here comes the magic... | |
_tmpfile=$(mktemp -tu) | |
wget -O "$_tmpfile" "$srcurl" | |
if [[ "$?" -eq 0 ]]; then | |
# Write the destination file header | |
echo "#" > "$dstfile" | |
echo "# $dstfile: adblock server list for Unbound" >> "$dstfile" | |
echo "# " >> "$dstfile" | |
echo "" >> "$dstfile" | |
echo "# Downloaded from URL:" >> "$dstfile" | |
echo "# $srcurl" >> "$dstfile" | |
echo "# " >> "$dstfile" | |
echo "# Last updated: $(date)" >> "$dstfile" | |
echo "" >> "$dstfile" | |
# Add the servers to the destination file | |
for l in $(awk -F, 'END {for(i=1;i<NF;i++) {print $i}}' $_tmpfile); do | |
echo "local-data: \"$l A 127.0.0.2\"" >> "$dstfile" | |
done | |
echo "Everything fine, restarting unbound to implement new serverlist..." | |
/etc/init.d/unbound restart | |
fi | |
rm "$_tmpfile" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment