Andrwe / privoxy-blocklist

Script converting AdBlock Plus rules into privoxy format.
The Unlicense
153 stars 39 forks source link

sed complain about [[:space:]], not [:space:] #9

Closed szorfein closed 2 years ago

szorfein commented 7 years ago

hi, i try debuggin your script because it seem don't work on recent version of bash...look this part. ( this is just a minimal version of your script for debuggin )

#! /bin/bash

TMPDIR="/tmp/privoxy"
URLS=  ("https://raw.githubusercontent.com/easylist/easylist/master/easyprivacy/easyprivacy_thirdparty.txt")

if [[ ! -d $TMPDIR ]] ; then
    echo "mkdir $TMPDIR"
    install -d -m700 $TMPDIR
fi

for url in ${URLS[@]}
do
    echo "Processing ${url} ...\n" || exit 0
    file=${TMPDIR}/$(basename ${url})
    actionfile=${file%\.*}.script.action
    filterfile=${file%\.*}.script.filter
    list=$(basename ${file%\.*})

    echo "Downloading ${url} ..." || exit 0
    wget -t 3 -O $file $url
    echo ".. downloading done." || exit 0

    echo "Creating actionfile for $list" || exit 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}
    echo "actionfile -> $actionfile done"

    echo "Creating filterfile for $list..." || exit 1
    echo "FILTER: ${list} Tag filter of ${list}" > "${filterfile}"

   # this bug here <This sed command doesn't work>
   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}

    echo "{ +filter{${list}} }" >> "${actionfile}"
    echo "*" >> ${actionfile}
    echo "... filterfile added ..." || exit 1

done

The error -> sed: character class syntax is [[:space:]], not [:space:]

Bernd-Osterhage commented 7 years ago

It seems that there is an escape char in front of the first ":" missing! Original part: *[:[^:]]*[^:]* Changed part: *[\:[^:]]*[^:]*

szorfein commented 7 years ago

thanks, it seem to work.

EnricoVerzegnassi commented 6 years ago

It works! Thans 👍

bastiandoetsch commented 6 years ago

Works for me, too.

mkaand commented 4 years ago

Thanks man. I recently upgraded my server from Ubuntu 16.04 to 18.04 and I start receiving errors for this script (same error) I fixed with your solution. I guess bash version changed after upgrade. That's why script failed.

Andrwe commented 2 years ago

merged into master with https://github.com/Andrwe/privoxy-blocklist/pull/14