I guess this forum doesn't allow edits after some undefined period of time, or not that I can find - brilliant, absolutely brilliant. ::)
I made a few changes to the adblock update script, got rid of the ugly sort/uniq operators, lots of local logging junk (now logs via syslog to /tmp/resolver.log properly) and no longer requires the assistance of a php script to restart dnsmasq.
#!/usr/local/bin/bash
REDIR_TO='10.254.254.254'
ADBLOCK_URL='http://pgl.yoyo.org/adservers/serverlist.php?hostformat=dnsmasq&showintro=0&mimetype=plaintext'
CONF_DNSMASQ='/usr/local/etc/dnsmasq.conf'
CONF_DNSMASQ_DIR='/usr/local/etc/dnsmasq.d'
CONF_ADBLOCK='/usr/local/etc/dnsmasq.d/adblock.conf'
CONF_ADBLOCK_TEMP='/tmp/adblock.conf'
CONF_ADBLOCK_BACKUP='/tmp/adblock.conf.orig'
LOCAL_DEBUG=false
daemonlog () {
logger -p daemon.info -i -t dnsmasq $1
$LOCAL_DEBUG && echo $1
}
restart_dnsmasq () {
echo '' | php -q
}
if [ ! -d $CONF_DNSMASQ_DIR ]; then
daemonlog "Initializing ad blocking configuration, mounting filesystem read-write"
/etc/rc.conf_mount_rw
mkdir -p $CONF_DNSMASQ_DIR
if [ ! -r $CONF_DNSMASQ ]; then
daemonlog "Creating dnsmasq configuration"
echo "conf-dir=$CONF_DNSMASQ_DIR" > $CONF_DNSMASQ
else
daemonlog "dnsmasq configuration exists, adding configuration directory"
echo "conf-dir=$CONF_DNSMASQ_DIR" >> $CONF_DNSMASQ
fi
daemonlog "Initializing ad blocking repository, mounting filesystem read-only"
touch $CONF_ADBLOCK
/etc/rc.conf_mount_ro
fi
daemonlog "Fetching ad blocking list from $ADBLOCK_URL"
/usr/bin/fetch -qo - $ADBLOCK_URL | /usr/bin/sed "s/127\.0\.0\.1/$REDIR_TO/" > $CONF_ADBLOCK_TEMP
daemonlog "Analyzing for changes"
if ! /usr/bin/cmp -s "$CONF_ADBLOCK_TEMP" "$CONF_ADBLOCK"; then
daemonlog "Changes detected, mounting filesystem read-write"
/etc/rc.conf_mount_rw
daemonlog "Updating $CONF_ADBLOCK with latest entries"
cp $CONF_ADBLOCK $CONF_ADBLOCK_BACKUP
cp $CONF_ADBLOCK_TEMP $CONF_ADBLOCK
daemonlog "Restarting dnsmasq"
restart_dnsmasq
if ! pgrep -q dnsmasq; then
daemonlog "dnsmasq failed to restart, reverting to previous ad blocking configuration"
cp $CONF_ADBLOCK_BACKUP $CONF_ADBLOCK
restart_dnsmasq
fi
daemonlog "Update completed. Re-mounting filesystem read-only"
/etc/rc.conf_mount_ro
else
daemonlog "No ad blocking updates required"
fi