But there seems to be no reason to use a file here - just pipe the for
loop directly into awk
(or into sort -u
- that may be a better choice if you're memory-constrained, as it will perform an external merge-sort if it needs to).
The duplicated sed
pipe could be replaced with a single sed
program of two commands:
#!/bin/sh
set -eu
sources=$(mktemp)
trap 'rm "$sources"' EXIT
curl -s -o "$sources" https://raw.githubusercontent.com/T145/packages/master/net/adblock/files/adblock.sources
for key in $(jq -r 'keys[]' "$sources")
do
case $key in
gaming | osid_basic )
# Ignore these lists
;;
* )
url=$(jq -r ".$key.url" "$sources")
rule=$(jq -r ".$key.rule" "$sources")
curl -s "$url" |
case $url in
*.tar.gz) tar -xOzf - ;;
*) cat ;;
esac |
gawk --sandbox -- "$rule"
esac
done |
sed -e 's/\r//g' -e 's/^/0.0.0.0 /' | gawksort '!a[$0]++'-u