Thanks, lonelycoder for putting this together.
I've made some changes to the advanced version of /jffs/scripts/update-hosts.sh so I thought I'd share them.
This lets you easily add or remove block lists by commenting or uncommenting them. Also, it merges in your blacklist with the rest of the blocked sites and ensures uniqueness.
Code:
#!/bin/sh
# set directory
dir=/tmp/mnt/sda1/hosts
### Sources with 0.0.0.0(uncomment desired blocklists)
#SOURCESA="$SOURCESA http://winhelp2002.mvps.org/hosts.txt"
#SOURCESA="$SOURCESA http://someonewhocares.org/hosts/zero/hosts"
SOURCESA="$SOURCESA http://pgl.yoyo.org/adservers/serverlist.php?hostformat=hosts&showintro=0&startdate[day]=&startdate[month]=&startdate[year]=&mimetype=plaintext&useip=0.0.0.0"
### Sources with 127.0.0.1(uncomment desired blocklists)
# MalwareDomainList.com Hosts List
SOURCESB="$SOURCESB http://www.malwaredomainlist.com/hostslist/hosts.txt"
# hpHosts - Ad and Tracking servers only
SOURCESB="$SOURCESB http://hosts-file.net/ad_servers.txt"
# AdAway default blocklist
# Blocking mobile ad providers and some analytics providers
SOURCESB="$SOURCESB http://adaway.org/hosts.txt"
### OPTIONAL: I keep my whitelist and black list on an external site so I can edit them from anywhere without having to go into router settings again
#wget -O- http://url_to_my/whitelist.txt > $dir/whitelist
#wget -O- http://url_to_my/blacklist.txt > $dir/blacklist
# get hosts files and combine and sort, write unique list to temp file
wget -O- $SOURCESA | grep -w ^0.0.0.0 | sed s/0.0.0.0/0.0.0.0/g |sed $'s/\r$//' | sort -u > $dir/temp
# get hosts files combine and convert 127.0.0.1 to 0.0.0.0 and add unique list to temp
wget -O- $SOURCESB | grep -w ^127.0.0.1 | sed s/127.0.0.1/0.0.0.0/g | sed $'s/\r$//' | sort -u >> $dir/temp
# Get personal blacklist and combine with the others
cat $dir/blacklist | sed $'s/\r$//' >> $dir/temp
# Be sure entire blocklist is free of double whitespace and unique
cat $dir/temp | sed 's/ */\ /g' | sort -u > $dir/tempblack
# remove whitelisted entries in tempblack and write final file, remove temp and tempblack files
cat $dir/whitelist | sed $'s/\r$//' | sort -u | grep -vf - $dir/tempblack > $dir/hosts.blocked
#remove temp files
rm $dir/temp
rm $dir/tempblack
#restart dnsmasq to apply changes
sleep 1
service restart_dnsmasq
If you use this method, you can remove the line about your blacklist in /jffs/configs/dnsmasq.conf.add.
It should now look like:
Code:
# AdBlocking
address=/0.0.0.0/0.0.0.0
ptr-record=0.0.0.0.in-addr.arpa,0.0.0.0
addn-hosts=/tmp/mnt/sda1/hosts/hosts.blocked
Cheers