tlhackque / BlockCountries

iptables manager for IP blocking by country
Other
32 stars 6 forks source link

Update your script not only the IP database #12

Closed wikrie closed 1 year ago

wikrie commented 8 years ago

I use a small script for updating your BlockCountries, may it would be possible to include this into Blockcountries, or if you like add it to your Repo.

https://gist.github.com/wikrie/433b13be91c6a31391ee163c14a90295

br wikrie

tlhackque commented 8 years ago

Thanks for the suggestion.

Auto update is an interesting idea. Not everyone would want to do it, but perhaps as an option.

However, your script is not safe. You aren't checking for errors from any of the commands.

And you are taking code from the head of master - which may be unstable.

You also don't run bcinstall to see if the dependencies have changed. And your script could change BlockCountries while cron is running it.

To do it right, you need to at least pull the latest released version, which I guess could use a tag. Note that downloading a release also lets you get a .tar.gz. You can find this with:

curl -s -k https://api.github.com/repos/tlhackque/BlockCountries/tags | grep -P '^\s+"name":' | head -n 1
and do a download something like:
if LATEST=`curl -s -L https://api.github.com/repos/tlhackque/BlockCountries/tags | grep -P '\s+"name":' | head -n 1 | sed -e's/^ *"name": "\(.*\)",/\1/'` ; then  echo "Latest release is $LATEST" && curl -s -L https://api.github.com/repos/tlhackque/BlockCountries/tarball/$LATEST -o BlockCountries.tar.gz && echo "Downloaded" $LATEST as BlockCountries.tar.gz ; fi

(zipball_url if you really want a .zip file). github has a limit on how frequently you can use its api.

A simpler approach would be to keep a local repository and do a git pull, which will download and update only what's changed. Then you can make /etc/init.d/BlockCountries be a symlink to your local repository's BlockCountries.

I'll consider developing a robust auto-update mechanism for a future release.

wikrie commented 7 years ago

thanks for your time and I hope the update feature will be there sometimes ... btw thanks for your tool at all.