It requires the p7zip package to be installed (doesn't seem to work with the p7zip-full)
here it is. Copy into a text editor, and save it. Remember to make it executable.
Code: Select all
#! /bin/sh
# This is script to download the latest p2p blocklist from peerguardian. It will then uncompress it, ready for deluge to import.
# SCRIPT REQUIRES THE FOLLOWING: 7zip to be installed (on Ubuntu use synaptic to get it)
# ---------------------------------------------------------Variables-----------------------------------------------------------------------------------
# This is where we want to dump the blocklist to.
dlfold=
# dlfold should be something like /home/{user}/blocklist/ or wherever.
# listurl is the location of the peerguardian p2p. The p2p.php file seems to link to this, but i do not know if the file gets updated, I am assuming so.
# Shouldn't need changing.
listurl=http://lists1.phoenixlabs.org.nyud.net:8080/level1.7z
# ----------------------------------------------------------End of user configurable variables----------------------------------------------------------
attempt=1
backup=$dlfold/backup
fail=0
ts=$(date)
# ------------------------------------------------------------------------------------------------------------------------------------------------------
# checking download folder exists
if [ -d $dlfold ]; then
echo Download Directory Already Exists, Using it.
else
mkdir -p $dlfold
echo Download Directory Created.
fi
# creating backups just in case file download fails.
if [ -d $backup ]; then
echo Backup Directory Present, Starting backup
else
mkdir -p $backup
echo Backup Directory Created.
fi
cd $backup
# remove old backups
echo "Clearing old backups"
rm level1* >/dev/null
# create new backups
echo "Creating new backups"
cd $dlfold
cp level1* $backup/
sleep 2
# Clear old download files.
echo "Clearing Old Blocklist"
rm level1* >/dev/null
# Now getting blocklist file and extracting.
echo "DOWNLOADING NEW BLOCKLIST..."
echo
while [ $attempt -ne 3 ]; do
wget --timeout=10 $listurl
if [ $? = 0 ]; then
7zr e level1.7z
if [ $? -ne 0 ]; then
attempt=$(( attempt + 1 ))
echo "Extraction Error. Will redownload and try again"
sleep 10
fail=1
else
attempt=3
fail=0
rm *.7z >/dev/null
fi
else
echo "Error while downloading the list, will wait 10 seconds and try again"
sleep 10
attempt=$(( attempt + 1 ))
fail=1
fi
done
#restore backups if update fails
if [ $fail = 1 ]; then
rm level1* >/dev/null
cp $backup/level1* $dlfold/
if [ $? = 0 ]; then
echo "UPDATE FAILED. BACKUPS RESTORED"
else
echo "No Backups To Restore"
fi
fi
if [ $fail = 1 ]; then
echo "Update Failed at $ts" >update.log
else
echo "Update Success at $ts" >update.log
fi
When i used the script it sometimes failed to get the file, so i added the timeout to wget, and it'll also only try three times.
If you want to schedule this to run, i downloaded gnome-schedule from the ubuntu repo, and told it to run it every week. I dunno if it has run it though.
To get deluge to import the blocklist simply add the URL in the blocklist importer, something like this
Code: Select all
file:///{where you put the dlfold variable to}/level1.txt
I may recreate this to simply write to the blocklist file directly, i'll have to see if that's a better idea.