#!/bin/sh

# Get the list in a format which we can feed to dnsmasq, replace the localhost IP with the routers IP
wget -O - "http://pgl.yoyo.org/adservers/serverlist.php?hostformat=hosts&showintro=0&mimetype=plaintext" | sed -e 's/127.0.0.1/192.168.1.1/g' > /tmp/adblock.hosts

if [ -f "/tmp/adblock.hosts" ]
then
        # We got a list, so move it to the permanent storage
	mv /tmp/adblock.hosts /jffs/adblock.hosts
else
        # There was an error -> end the program
	echo "Error building the ad list, please try again."
	exit
fi

# Tell dnsmasq to re-read the config, including the just updated list
killall -1 dnsmasq