Tags
Tags
This script downloads, converts and installs AdblockPlus lists into Privoxy.
Tracker for bugs and feature requests:
Bugtracker: privoxy-blocklist.sh
The PKGBUILD for this script can be found here:
http://aur.archlinux.org/packages.php?ID=43861
And the package can be installed from my repository.
It installs the script to '/usr/sbin/' and also a cronjob to '/etc/cron.weekly/'.
Warranty
Dependencies:
Version history:
0.2:
There was a change of the filenames needed.
So to ensure that privoxy is working properly you have to remove all .action and .filter files BUT user.*, match-all.* and default.* in the configuration directory of your privoxy and in the config.
0.1:
| Id | Status | Severity | Version | Description | Resolution |
| 0 | Implemented | Feature Request | 0.2 | Extract configuration of the script to be more suitable for packaging. | implemented in git |
| 1 | Approved | Major Bug | 0.2 | Implement domain based filter. | for 0.3 |
| 2 | Closed | Feature Request | 0.2 | Support /usr/local for install prefix. | You can copy the script to any place you want. |
| 3 | Approved | Feature Request | 0.2 | Support customizable names for action and filter file, i.e. adblock.filter adblock.action | for unknown (maybe 0.3) |
| 4 | Fixed | Major Bug | 0.2 | The dutch adblock list does not work, the script says that it is not a valid blocklist. URL: http://sites.google.com/site/dutchadblockfilters/AdBlock_Dutch_hide.txt | fixed in git |
| 5 | Fixed | Minor Bug | 0.2 | The russian adblock list does not work: http://ruadlist.googlecode.com/svn/trunk/advblock.txt The error shows: The list recieved from http://ruadlist.googlecode.com/svn/trunk/advblock.txt isn't an AdblockPlus list. Skipped | fixed in git |
| 7 | Closed | Major Bug | 0.2 | ./privoxy-blocklist.sh: 33: Syntax error: "(" unexpected Hmm, weird... This looks correct to me. | Can't reproduce this. |
| 8 | Approved | Minor Bug | 0.2 | Finnish list doesn't work (http://www.wiltteri.net/wiltteri.txt). "The list recieved from http://www.wiltteri.net/wiltteri.txt isn't an AdblockPlus list. Skipped" | fixed in git |
| 9 | Denied | Feature Request | 0.2 | Please state clearly that this script is absolutely useless on anything else than Arch Linux. On any generic Linux version of Bash like in Ubuntu it is one big pile of errors. | I tested the script on Debian 6.0.3, Ubuntu 11.10 and Fedora 15. As long as the dependencies were provided all worked without problems. If you have any problems please provide more information in your next bug report like error messages, output of the script run using -v 2 and which versions of software you are using. |
| 10 | Reproducing | Major Bug | git | The .filter files aren't actually used by privoxy. echo "{ +filter{${list}} }" >> ${actionfile} echo "*" >> ${actionfile} Should be: echo "{ +filter{${list}} }" >> ${actionfile} echo "/" >> ${actionfile} But unfortunately, that slows privoxy down to a crawl. The filter thing needs to be re-thought I guess... | |
| 11 | Fixed | Minor Bug | 0.2 | Concerning my earlier reported bug #7: Apologies, my bad. I've tried to run the script with sh, but that gives the reported error. It should be run with bash. | Good to know, I'll add a check for bash environment |
| 12 | New | Feature Request | 0.2 | I tried this in a Windows installation, using Cygwin. Thought you'd be interested in my notes. Had to disable the root user check, and run Cygwin as elevated to administrator Had to surround each ${CONFDIR} with double quotes (for spaces in paths ("Program Files (x86)")) Had to change each "config" to "config.txt" | |
| 13 | New | Major Bug | 0.2 | A lot of the patterns are wrong. Privoxy divides them into domain part (before first slash) and path part (after first slash). Domain part uses a simple globbing, not full regex, meaning ".example.com" will never match, because it's looking for that backslash as a literal. Also, a lot of the patterns seem to have "[/&:?=_].*" instead of "/" dividing the domain part and path part. How it interprets the resulting mess is anyone's guess. |
The development version of this script can be found on github.com
#!/bin/bash # ###################################################################### # # Author: Andrwe Lord Weber # Mail: lord-weber-andrwe<at>renona-studios<dot>org # Version: 0.2 # URL: http://andrwe.dyndns.org/doku.php/blog/scripting/bash/privoxy-blocklist # ################## # # Sumary: # This script downloads, converts and installs # AdblockPlus lists into Privoxy # ###################################################################### ###################################################################### # # TODO: # - implement: # domain-based filter # ###################################################################### ###################################################################### # # script variables and functions # ###################################################################### # array of URL for AdblockPlus lists URLS=("https://easylist-downloads.adblockplus.org/easylistgermany.txt" "http://adblockplus.mozdev.org/easylist/easylist.txt") # privoxy config dir (default: /etc/privoxy/) CONFDIR=/etc/privoxy # directory for temporary files TMPDIR=/tmp/privoxy-blocklist TMPNAME=$(basename ${0}) ###################################################################### # # No changes needed after this line. # ###################################################################### function usage() { echo "${TMPNAME} is a script to convert AdBlockPlus-lists into Privoxy-lists and install them." echo " " echo "Options:" echo " -h: Show this help." echo " -q: Don't give any output." echo " -v 1: Enable verbosity 1. Show a little bit more output." echo " -v 2: Enable verbosity 2. Show a lot more output." echo " -v 3: Enable verbosity 3. Show all possible output and don't delete temporary files.(For debugging only!!)" echo " -r: Remove all lists build by this script." } [ ${UID} -ne 0 ] && echo -e "Root privileges needed. Exit.\n\n" && usage && exit 1 # check whether an instance is already running [ -e ${TMPDIR}/${TMPNAME}.lock ] && echo "An Instance of ${TMPNAME} is already running. Exit" && exit DBG=0 function debug() { [ ${DBG} -ge ${2} ] && echo -e "${1}" } function main() { cpoptions="" [ ${DBG} -gt 0 ] && cpoptions="-v" for url in ${URLS[@]} do debug "Processing ${url} ...\n" 0 file=${TMPDIR}/$(basename ${url}) actionfile=${file%\.*}.script.action filterfile=${file%\.*}.script.filter list=$(basename ${file%\.*}) # download list debug "Downloading ${url} ..." 0 wget -t 3 --no-check-certificate -O ${file} ${url} >${TMPDIR}/wget-${url//\//#}.log 2>&1 debug "$(cat ${TMPDIR}/wget-${url//\//#}.log)" 2 debug ".. downloading done." 0 [ "$(grep -E '^\[Adblock.*\]$' ${file})" == "" ] && echo "The list recieved from ${url} isn't an AdblockPlus list. Skipped" && continue # convert AdblockPlus list to Privoxy list # blacklist of urls debug "Creating actionfile for ${list} ..." 1 echo -e "{ +block{${list}} }" > ${actionfile} sed '/^!.*/d;1,1 d;/^@@.*/d;/\$.*/d;/#/d;s/\./\\./g;s/\?/\\?/g;s/\*/.*/g;s/(/\\(/g;s/)/\\)/g;s/\[/\\[/g;s/\]/\\]/g;s/\^/[\/\&:\?=_]/g;s/^||/\./g;s/^|/^/g;s/|$/\$/g;/|/d' ${file} >> ${actionfile} debug "... creating filterfile for ${list} ..." 1 echo "FILTER: ${list} Tag filter of ${list}" > ${filterfile} # set filter for html elements sed '/^#/!d;s/^##//g;s/^#\(.*\)\[.*\]\[.*\]*/s|<([a-zA-Z0-9]+)\\s+.*id=.?\1.*>.*<\/\\1>||g/g;s/^#\(.*\)/s|<([a-zA-Z0-9]+)\\s+.*id=.?\1.*>.*<\/\\1>||g/g;s/^\.\(.*\)/s|<([a-zA-Z0-9]+)\\s+.*class=.?\1.*>.*<\/\\1>||g/g;s/^a\[\(.*\)\]/s|<a.*\1.*>.*<\/a>||g/g;s/^\([a-zA-Z0-9]*\)\.\(.*\)\[.*\]\[.*\]*/s|<\1.*class=.?\2.*>.*<\/\1>||g/g;s/^\([a-zA-Z0-9]*\)#\(.*\):.*[:[^:]]*[^:]*/s|<\1.*id=.?\2.*>.*<\/\1>||g/g;s/^\([a-zA-Z0-9]*\)#\(.*\)/s|<\1.*id=.?\2.*>.*<\/\1>||g/g;s/^\[\([a-zA-Z]*\).=\(.*\)\]/s|\1^=\2>||g/g;s/\^/[\/\&:\?=_]/g;s/\.\([a-zA-Z0-9]\)/\\.\1/g' ${file} >> ${filterfile} debug "... filterfile created - adding filterfile to actionfile ..." 1 echo "{ +filter{${list}} }" >> ${actionfile} echo "*" >> ${actionfile} debug "... filterfile added ..." 1 debug "... creating and adding whitlist for urls ..." 1 # whitelist of urls echo "{ -block }" >> ${actionfile} sed '/^@@.*/!d;s/^@@//g;/\$.*/d;/#/d;s/\./\\./g;s/\?/\\?/g;s/\*/.*/g;s/(/\\(/g;s/)/\\)/g;s/\[/\\[/g;s/\]/\\]/g;s/\^/[\/\&:\?=_]/g;s/^||/\./g;s/^|/^/g;s/|$/\$/g;/|/d' ${file} >> ${actionfile} debug "... created and added whitelist - creating and adding image handler ..." 1 # whitelist of image urls echo "{ -block +handle-as-image }" >> ${actionfile} sed '/^@@.*/!d;s/^@@//g;/\$.*image.*/!d;s/\$.*image.*//g;/#/d;s/\./\\./g;s/\?/\\?/g;s/\*/.*/g;s/(/\\(/g;s/)/\\)/g;s/\[/\\[/g;s/\]/\\]/g;s/\^/[\/\&:\?=_]/g;s/^||/\./g;s/^|/^/g;s/|$/\$/g;/|/d' ${file} >> ${actionfile} debug "... created and added image handler ..." 1 debug "... created actionfile for ${list}." 1 # install Privoxy actionsfile cp ${cpoptions} ${actionfile} ${CONFDIR} if [ "$(grep $(basename ${actionfile}) ${CONFDIR}/config)" == "" ] then debug "\nModifying ${CONFDIR}/config ..." 0 sed "s/^actionsfile user\.action/actionsfile $(basename ${actionfile})\nactionsfile user.action/" ${CONFDIR}/config > ${TMPDIR}/config debug "... modification done.\n" 0 debug "Installing new config ..." 0 cp ${cpoptions} ${TMPDIR}/config ${CONFDIR} debug "... installation done\n" 0 fi # install Privoxy filterfile cp ${cpoptions} ${filterfile} ${CONFDIR} if [ "$(grep $(basename ${filterfile}) ${CONFDIR}/config)" == "" ] then debug "\nModifying ${CONFDIR}/config ..." 0 sed "s/^\(#*\)filterfile user\.filter/filterfile $(basename ${filterfile})\n\1filterfile user.filter/" ${CONFDIR}/config > ${TMPDIR}/config debug "... modification done.\n" 0 debug "Installing new config ..." 0 cp ${cpoptions} ${TMPDIR}/config ${CONFDIR} debug "... installation done\n" 0 fi debug "... ${url} installed successfully.\n" 0 done } # create temporary directory and lock file mkdir -p ${TMPDIR} touch ${TMPDIR}/${TMPNAME}.lock # set command to be run on exit [ ${DBG} -le 2 ] && trap "rm -fr ${TMPDIR};exit" INT TERM EXIT # loop for options while getopts ":hrqv:" opt do case "${opt}" in "h") usage exit 0 ;; "v") DBG="${OPTARG}" ;; "q") DBG=-1 ;; "r") echo "Do you really want to remove all build lists?(y/N)" read choice [ "${choice}" != "y" ] && exit 0 rm -rf ${CONFDIR}/*.script.{action,filter} && \ sed '/^actionsfile .*\.script\.action$/d;/^filterfile .*\.script\.filter$/d' -i ${CONFDIR}/config && \ echo "Lists removed." && exit 0 echo -e "An error occured while removing the lists.\nPlease have a look into ${CONFDIR} whether there are .script.* files and search for *.script.* in ${CONFDIR}/config." exit 1 ;; ":") echo "${TMPNAME}: -${OPTARG} requires an argument" >&2 exit 1 ;; esac done debug "URL-List: ${URLS}\nPrivoxy-Configdir: ${CONFDIR}\nTemporary directory: ${TMPDIR}" 2 main # restore default exit command trap - INT TERM EXIT [ ${DBG} -lt 2 ] && rm -r ${TMPDIR} [ ${DBG} -eq 2 ] && rm -vr ${TMPDIR} exit 0
@Sebastian:
Could you please explain the problems you have here:
Bugtracker: privoxy-blocklist.sh
Feature request, pls:
Support /usr/local for install prefix.
Support customizable names for action and filter file, i.e.
adblock.filter adblock.action
@cb:
I don't understand what do you mean by supporting /usr/local for install prefix.
You just can copy the script to any place you want and start it.
The only path which is set in the script using a variable is the config directory of privoxy (/etc/privoxy)
Hi Andrwe,
Awesome script! I can finally remove loads of ads while surfing with the iPad.
Is the script still maintained currently? Been a while since the last update. I'm really looking forward to domain based filters, meaning the loads of ||example.com^$third-party filters currently in easylist.
@Casper: Hi Casper,
Yes the script is still maintained.
In the last few month and unfortunately for the next few I'm very busy with my work.
But I'm definitly trying to update the script this year.
So please be a little more patient.
Andrwe: Thanks for the great script. It's perfect for blocking ads on mobile devices.
I use a third party list to disable social media buttons. Is there any way to modify the script to allow import of a list from a source such as: https://monzta.maltekraus.de/adblock_social.txt
G'day All
There seem too be an issue with the Size of ya filter per say, a filter can't be more than 4000-4990 characters in size, per filter, any thing more and privoxy will ignore the rest, ya might wish to breakup the extra large filter too a smaller, more manageable size filter's.
P.S I have well over 900 ad-Tracker filter's and each filter can hold as much as 4500 characters each, which run's extremely well and blocking rates are in the high numbers. If ya want sample of a filter let me know!
Cheers
@Wes: hi,
you just have to add this source to the URLS-array like this:
URLS=("https://easylist-downloads.adblockplus.org/easylistgermany.txt" "http://adblockplus.mozdev.org/easylist/easylist.txt" "https://monzta.maltekraus.de/adblock_social.txt")
Regarding bug 9: On Ubuntu 11.04, bash version 4.2.8(1), lines 210, 211 and 212 in the current git version are missing && after the ... part, error is privoxy-blocklist.sh: line 210: syntax error near unexpected token `echo' privoxy-blocklist.sh: line 210: `-z "${PRIVOXY_CONF}" echo „\$PRIVOXY_CONF isn't set please either provice a valid initscript config or set it in ${SCRIPTCONF} .“ >&2 && exit 1'
After changing -z "${PRIVOXY_CONF}" echo … to -z "${PRIVOXY_CONF}" && echo … the script works. It is probably not a bad idea to use a more conservative syntax if possible.
Thank You for a great script!
The last comment is missing square brackets, but I'm certain You understand the problem.
Hy. I use privoxy on a router with openwrt. when i execute your script i get this error message.
root@OpenWrt /opt# bash blocklist.sh Processing https://easylist-downloads.adblockplus.org/easylistgermany.txt …
Downloading https://easylist-downloads.adblockplus.org/easylistgermany.txt … .. downloading done. grep: /opt/privoxy-blocklist/easylistgermany.txt: No such file or directory The list recieved from https://easylist-downloads.adblockplus.org/easylistgermany.txt isn't an AdblockPlus list. Skipped Processing http://adblockplus.mozdev.org/easylist/easylist.txt …
Downloading http://adblockplus.mozdev.org/easylist/easylist.txt … Segmentation fault .. downloading done. grep: /opt/privoxy-blocklist/easylist.txt: No such file or directory The list recieved from http://adblockplus.mozdev.org/easylist/easylist.txt isn't an AdblockPlus list. Skipped root@OpenWrt /opt#
What could this be?
@14:
Hi,
is there enough space on /opt/ for the lists?
Can you please provide the output of bash blocklist.sh -v 2 ?
It be best if you provide the output using something like pastebin.org because it can be a lot of text.
Andrwe Lord Weber
Hi,
I'm glad I found this script, but I got the error below. It says that the list downloaded from easylist-downloads.adblockplus.org are not AdblockPlus lists and that there are no such files or directory.
Also, I would like to use Privoxy with some porn site's BlackList for my home network such as the ones used with squidguard (http://www.squidguard.org/blacklists.html). Can they be simply added to the script after the URLS-array? As mentionned to wes (message 8). The script will probably not unzip files, is that right?
Thank you
Generated Error Message *
Processing https://easylist-downloads.adblockplus.org/easylistgermany.txt …
Downloading https://easylist-downloads.adblockplus.org/easylistgermany.txt … .. downloading done. grep: /tmp/privoxy-blocklist/easylistgermany.txt: No such file or directory The list recieved from https://easylist-downloads.adblockplus.org/easylistgermany.txt isn't an AdblockPlus list. Skipped Processing http://adblockplus.mozdev.org/easylist/easylist.txt …
Downloading http://adblockplus.mozdev.org/easylist/easylist.txt … .. downloading done. grep: /tmp/privoxy-blocklist/easylist.txt: No such file or directory The list recieved from http://adblockplus.mozdev.org/easylist/easylist.txt isn't an AdblockPlus list. Skipped
Following my previous message, here is the privoxy-blocklist.sh -v2 output.
-v2 output *
URL-List: https://easylist-downloads.adblockplus.org/easylistgermany.txt Privoxy-Configdir: /usr/local/etc/privoxy Temporary directory: /tmp/privoxy-blocklist Processing https://easylist-downloads.adblockplus.org/easylistgermany.txt …
Downloading https://easylist-downloads.adblockplus.org/easylistgermany.txt … /Users/lorenzo/Desktop/privoxy-blocklist.sh: line 86: wget: command not found .. downloading done. grep: /tmp/privoxy-blocklist/easylistgermany.txt: No such file or directory The list recieved from https://easylist-downloads.adblockplus.org/easylistgermany.txt isn't an AdblockPlus list. Skipped Processing http://adblockplus.mozdev.org/easylist/easylist.txt …
Downloading http://adblockplus.mozdev.org/easylist/easylist.txt … /Users/lorenzo/Desktop/privoxy-blocklist.sh: line 86: wget: command not found .. downloading done. grep: /tmp/privoxy-blocklist/easylist.txt: No such file or directory The list recieved from http://adblockplus.mozdev.org/easylist/easylist.txt isn't an AdblockPlus list. Skipped /tmp/privoxy-blocklist/privoxy-blocklist.sh.lock /tmp/privoxy-blocklist/wget-http:##adblockplus.mozdev.org#easylist#easylist.txt.log /tmp/privoxy-blocklist/wget-https:##easylist-downloads.adblockplus.org#easylistgermany.txt.log /tmp/privoxy-blocklist mbp-i5:~ lorenzo$
So sorry, I just noticed that I was missing the wget dependency. Installation ran successfully but now my browser (well, privoxy) is refusing any connexion.
After running the script, the new .action line in the config file is not writen properly. It ends up as: „actionsfile easylist.script.actionnactionsfile user.action“ and „filterfile easylist.script.filternfilterfile user.filter“.
Privoxy doesn't accept connexions anymore until reinstal.
config actionsfile match-all.action # Actions that are applied to all sites and maybe overruled later on. actionsfile default.action # Main actions file actionsfile easylist.script.actionnactionsfile user.action # User customizations
filterfile default.filter filterfile easylist.script.filternfilterfile user.filter # User customizations
Sorry for multiple post.
Well this made me angry. Thanks. What Lorenzo describes above is correct.
What Lorenzo doesn't perhaps make crystal clear is that because the script is seemingly crappily coded to not work („actionsfile easylist.script.actionnactionsfile“ etc) and it is not clear how to change „config“ TO make it work that you should *steer clear of this stupid thing altogether* or face having to reinstall privoxy all over again because even deleting the silly error changes (i.e. „easylist.script.filternfilterfile“) that this wrong script adds doesn't seem to fix what ever it broke
@Lebowski
The script do work , I could fix the problem by upgrading the dependencies.
I now have bash 4.2.24(2), wget 1.13.4, sed 4.2.1 and the script works correctly.
./privoxy-blocklist.sh: 33: Syntax error: “(“ unexpected Hmm, weird… This looks correct to me.
Still actual?
Try „bash privoxy-blacklist.sh“ instead of „sh privoxy-blacklist.sh“
Can you read more about the actions manual from http://www.privoxy.org/user-manual/actions-file.html, and then modify your script to deal with the domain and path correctly.
About that “./privoxy-blocklist.sh: 33: Syntax error: “(“ unexpected Hmm, weird… This looks correct to me.“
I've encountered that on the ksh of my OpenBSD setup. There are two things to be taken into account:
1. Change the path to bash from /bin/bash to wherever bash is located (/usr/local/bin/bash in my case)
2. Run the script usind bash or the full path to the bash executable.
Boom it works. Even on OpenBSD, which sure isn't Arch Linux :D
Hello,
I've the same problem. About that “./privoxy-blocklist.sh: 33: Syntax error: “(“ My server is on Debian Squeeze Do you have an idea for this problem ? Cordialy Guillaume
Hello,
I don't think this script works anymore.