Skip to content

Instantly share code, notes, and snippets.

@jkstill
Created February 21, 2024 00:44
Show Gist options
  • Save jkstill/f731aa7eed90be2a9cda0d1bf47170ee to your computer and use it in GitHub Desktop.
Save jkstill/f731aa7eed90be2a9cda0d1bf47170ee to your computer and use it in GitHub Desktop.
custom ad block hosts file for dnsmasq
#!/usr/bin/env bash
set -eu
echo
echo Pulling latest Steven Black hosts file
echo
# curl and openssl built
# openssl /usr/local/ssl
# curl /usr/local/bin
# this is because the system curl does not support TLS 1.2
TLS_CURL='LD_LIBRARY_PATH=/usr/local/ssl/lib /usr/local/bin/curl '
adblockFile=/etc/hosts.StevenBlack.adblock
hostsFile=hosts.yourdomain.com
eval "$TLS_CURL" https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts > "$adblockFile"
fileSize=$(wc -l "$adblockFile" | awk '{ print $1 }' )
[ "$fileSize" -lt 50000 ] && {
echo
echo the adblock file "$adblockFile" is too small at "$fileSize" lines
echo
exit 1
}
echo
echo checking out "$hostsFile"
echo
cd /etc
co -f -l "$hostsFile"
echo
echo Appending adblock addresses to hosts.jks.com
echo
grep '^0.0.0.0' "$adblockFile" | grep -v -f /etc/hosts.yourdomain.com.exclude >> "$hostsFile"
echo
echo Restarting DNSMasq
echo
service dnsmasq restart
echo
echo all done
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment