More nerd stuff

Since I have way to much on my hands, I wrote a simple little bash script for updating an ip blocklist for all you bittorrent users out there. Not that I use bittorrent for anything illegal. I only download Linux ISOs. A lot. Really.

Script follows below, you pirating bastards.


# Change these variables as necessary
APPS="wget p7zip"

# Function that check for required programs
check_apps() {
for app in $APPS; do
if ! eval which $app &> /dev/null; then
echo "This script needs $app!"
echo "Install it and run the script again."
exit -1

# Make sure needed applications are installed

# Enter directory where blocklist should be saved

# Count number of backups
for file in $(ls -1); do
(( count += 1))

# Try to fetch updated blocklist. If success, backup old and unpack new.
# If number of backups exceed the maximum number you want to have, delete
# the oldest one.
if wget ${BLOCKLISTURL}; then
echo "Creating backup of old list"
if [ $count -gt $MAXNUMBACKUPS ]; then
rm $(ls -ltr | head -2 | grep -v total | awk '{print $8}')
mv level1.txt "level1.old.$(date +%F)"
echo "Unpacking new list"
p7zip -d level1.7z
echo "List updated"
echo "Could not update list"

I’ve only used this on my Gentoo Linux system, but I suppose it should work on any Linux or *BSD system with some minor modifications. Oh, and a good idea is to add a cron job that updates your blocklist every once in a while.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: