summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlookshe <github@lookshe.org>2019-03-16 13:20:01 +0100
committerlookshe <github@lookshe.org>2019-03-16 13:20:01 +0100
commitc9e52a5d16939c054eab947a3b66e9124e33773b (patch)
treebe3de051219dfc82cfdc4b6f9ab15198e1ba64f6
parentbfbd9ded98aae2995f60270e6c4a36cf47435c96 (diff)
use awk a bit smarter
-rwxr-xr-xbuildAdBlocklist.sh19
-rwxr-xr-xretrieveAdBlocklists.sh5
2 files changed, 15 insertions, 9 deletions
diff --git a/buildAdBlocklist.sh b/buildAdBlocklist.sh
index 510b821..45c9386 100755
--- a/buildAdBlocklist.sh
+++ b/buildAdBlocklist.sh
@@ -1,6 +1,13 @@
-#°/bin/bash
-ADLISTDIR=adlists
-for adfile in $(ls $ADLISTDIR); do
- grep -v '^#' < $ADLISTDIR/$adfile | grep -v '^$' | awk '{if (0 < match($0, "\t") || 0 < index($0, " ")) {split($0,b," "); print b[2]} else print $0}' | grep -v '^localhost$' | grep -v '^local$' | grep -v '^localhost.localdomain$' | grep -v '^ip6-localnet$' | grep -v '^ip6-localhost$' | grep -v '^$' | while read blockedAddress; do echo "127.0.0.1 $blockedAddress"; done >> block.list
-done
-
+#!/bin/bash
+awk -F'[\t ]+' '{
+ if (!match($0, /^\s*(#|$)/)) {
+ if (NF>=2 && length($2)) {
+ host=$2
+ } else {
+ host=$1
+ }
+ if (!match(host, /^(localhost|local|localhost.localdomain|ip6-localnet|ip6-localhost$)$/)) {
+ print "127.0.0.1 " host
+ }
+ }
+}' adlists/* > block.list
diff --git a/retrieveAdBlocklists.sh b/retrieveAdBlocklists.sh
index 480ee48..38643c0 100755
--- a/retrieveAdBlocklists.sh
+++ b/retrieveAdBlocklists.sh
@@ -1,4 +1,3 @@
#!/bin/bash
-while read p; do
- echo "$p" | awk '{split($0,a,"|"); system("curl -s " a[2] " > adlists/"a[1])}'
-done < adfilelist.txt
+rm -rf adlists/*
+awk -F'|' '{system("wget -q -O adlists/" $1 " " $2)}' adfilelist.txt