Home | News | Download | Packages | Forum | Wiki | Github

How to update a file from internet every now and then?


#1

I use this file to block ads on my computer.

https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/social/hosts

But new adservers pop up everytime and those are added to this file by the community. It’s like a game of cat and mouse. So, the host file becomes obsolete very quickly. I was wondering if there is any way for my computer to check if a newer file is present and if it does, then download and replace it with my systems /etc/hosts.

I check the file manually every now and then and restart my computer. I know that runit has some way to restart the service without rebooting but I donn’t know. So, is there a way to automate this process.


(maxice8 alter) #2

urlwatch

<<<<


#3

which service are you talking about? :neutral_face:


(Dario Niedermann) #4

For the “checking” part, I wrote a Bash script years ago when I had the same need. You might find it useful it as a starting point.


#5

I have a short script, like so:

#!/bin/sh

TMPFILE=$(mktemp /tmp/adblockXXX)

echo -n "Attempting to download adlist: "

FULLURL="https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts"

/usr/bin/wget -q -O $TMPFILE $FULLURL 2>/dev/null 1>&2

if [ $? -ne 0 ]; then
    echo 'Failed!'
    exit
fi

echo 'Done!'

if [ ! -r $TMPFILE ]; then
    echo "Can't read file."
    exit
else
    echo "Copying downloaded file into place."
    /bin/mv $TMPFILE /etc/hosts.adblock
    /bin/chmod 0644 /etc/hosts.adblock
    echo "Updating DNS server."
    /bin/sv restart dnsmasq
fi

And a runit service using snooze:

#!/bin/sh

exec /bin/snooze -w 0 /usr/local/bin/update-adblock

That should run once a week.


(John Peach) #6

This is trivial with a cronjob that uses wget -qN and a makefile that runs if a new file has been downloaded…

Here is mine for root.hints

#!/bin/bash
cd /etc/unbound
wget -qN ftp://rs.internic.net/domain/named.root
make -s
exit 0

…and the Makefile:

all: root.hints

root.hints: named.root
cp named.root root.hints
sv restart unbound