#!/bin/sh

echo 'Create a whitelist file, maybe you want to permit some adds in the near future:'
cat > /tmp/good <<EOF
www.allowthiswebsite.com
www.profitshare.ro
EOF
echo $'Whitelist file /tmp/good successfully created!\n'

# online advertising sources (you can add more if you want)
s1=http://winhelp2002.mvps.org/hosts.txt
s2=http://jamesisbored.com/iphone/content/hosts.php

echo 'Update blacklist file:'
(wget -O - $s1 ; wget -O - $s2) |grep .0.0. |grep -Fvf /tmp/good |sed -e '2,$s/127.0.0.1/0.0.0.0/g' -e 's/[[:space:]]*#.*$//' > /etc/dnsmasq/hosts/blkhosts
chmod 777 /etc/dnsmasq/hosts/blkhosts
echo $'Blacklist file /etc/dnsmasq/hosts/blkhosts successfully updated!\n'

# add this info line to /var/log/messages
logger 'DOWNLOADED ADBLOCK HOSTS FILE(s)'

echo 'Reload dnsmasq to read the new blacklist file:'
killall -1 dnsmasq
echo 'Dnsmasq successfully reloaded!'
