Created
February 25, 2014 04:13
-
-
Save raidzero/9202581 to your computer and use it in GitHub Desktop.
Script to update transmission blocklists using a list of blocklists from iblocklist.com
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
:<<END_DOC | |
blocklist updater - for transmission | |
Written by raidzero for linux | |
BLOCKLIST_HOME is the directory where transmission keeps its blocklists | |
END_DOC | |
BLOCKLIST_HOME=~/.config/transmission/blocklists | |
# blocklist URLS go here: | |
cat << END_LIST > /tmp/blocklists | |
http://list.iblocklist.com/?list=bt_level1&fileformat=p2p&archiveformat=gz | |
http://list.iblocklist.com/?list=bt_level2&fileformat=p2p&archiveformat=gz | |
http://list.iblocklist.com/?list=bt_level3&fileformat=p2p&archiveformat=gz | |
http://list.iblocklist.com/?list=bt_edu&fileformat=p2p&archiveformat=gz | |
http://list.iblocklist.com/?list=bt_templist&fileformat=p2p&archiveformat=gz | |
http://list.iblocklist.com/?list=bt_hijacked&fileformat=p2p&archiveformat=gz | |
http://list.iblocklist.com/?list=ijfqtofzixtwayqovmxn&fileformat=p2p&archiveformat=gz | |
http://list.iblocklist.com/?list=ecqbsykllnadihkdirsh&fileformat=p2p&archiveformat=gz | |
http://list.iblocklist.com/?list=jcjfaxgyyshvdbceroxf&fileformat=p2p&archiveformat=gz | |
http://list.iblocklist.com/?list=lljggjrpmefcwqknpalp&fileformat=p2p&archiveformat=gz | |
http://list.iblocklist.com/?list=pfefqteoxlfzopecdtyw&fileformat=p2p&archiveformat=gz | |
http://list.iblocklist.com/?list=tbnuqfclfkemqivekikv&fileformat=p2p&archiveformat=gz | |
http://list.iblocklist.com/?list=ewqglwibdgjttwttrinl&fileformat=p2p&archiveformat=gz | |
END_LIST | |
#check for transmission in the process list | |
RUNNING=`ps -ef | grep "transmission-gtk" | grep -v grep | wc -l` | |
if [ $RUNNING -ge 1 ]; then | |
#kill it gracefully | |
killall transmission-gtk | |
[ $? -eq 0 ] && KILLED=1 | |
fi | |
cd $BLOCKLIST_HOME | |
rm -rf $BLOCKLIST_HOME/* | |
echo "Removed existing blocklists." | |
NUMBER=1 | |
echo -n "Downloading blocklist " | |
while read URL; do | |
echo -n "$NUMBER..." | |
wget -q $URL | |
if [ $? -ne 0 ]; then | |
echo "$NUMBER FAILED!" | |
fi | |
let NUMBER=$NUMBER+1 | |
done < /tmp/blocklists | |
echo " Done!" | |
NUMBER=1 | |
echo -n "Unpacking blockist " | |
for file in `find . -type f`; do | |
echo -n "$NUMBER..." | |
mv $file $file.gz | |
gunzip $file.gz | |
sed -i '/\#.*$/d;/^$/d' $file #remove comment and blank lines, so transmission doesnt yell about invalid lines | |
let NUMBER=$NUMBER+1 | |
done | |
echo " Done!" | |
#rename the existing files, so transmission can pick them up | |
NUMBER=1 | |
for file in `find . -type f -name "index.html?*"`; do | |
mv $file $NUMBER-blocklist | |
let NUMBER=$NUMBER+1 | |
done | |
#count and display the number of addresses in all of the blocklists | |
AMOUNT=`cat $BLOCKLIST_HOME/* | wc -l | sed ':a;s/\B[0-9]\{3\}\>/,&/;ta'` | |
echo "Blocked $AMOUNT bad addresses." | |
#be sure to restart the process if we killed it | |
if [ -n "$KILLED" ]; then | |
transmission-gtk & | |
fi | |
#clean up | |
rm /tmp/blocklists |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment