From 30add07aedf82960abe6f3cb01ea741914c28221 Mon Sep 17 00:00:00 2001 From: Ming Di Leom <2809763-curben@users.noreply.gitlab.com> Date: Sat, 17 Dec 2022 00:37:26 +0000 Subject: [PATCH] style(sed): avoid backslash in insert option - simpler and more readable - https://unix.stackexchange.com/a/99351 --- src/script.sh | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/script.sh b/src/script.sh index dbb1d8f..5702f4e 100644 --- a/src/script.sh +++ b/src/script.sh @@ -50,14 +50,14 @@ mkdir -p "../public/" cat "domains.txt" | \ sort | \ -sed '1 i\'"$COMMENT_UBO"'' > "../public/vn-badsite-filter.txt" +sed "1i $COMMENT_UBO" > "../public/vn-badsite-filter.txt" # Adguard Home cat "domains.txt" | \ sort | \ sed -e "s/^/||/g" -e "s/$/^/g" | \ -sed '1 i\'"$COMMENT_UBO"'' | \ +sed "1i $COMMENT_UBO" | \ sed "1s/Blocklist/Blocklist (AdGuard Home)/" > "../public/vn-badsite-filter-agh.txt" @@ -65,7 +65,7 @@ sed "1s/Blocklist/Blocklist (AdGuard Home)/" > "../public/vn-badsite-filter-agh. cat "domains.txt" | \ sort | \ sed -e "s/^/||/g" -e "s/$/\$all/g" | \ -sed '1 i\'"$COMMENT_UBO"'' | \ +sed "1i $COMMENT_UBO" | \ sed "1s/Blocklist/Blocklist (AdGuard)/" > "../public/vn-badsite-filter-ag.txt" @@ -73,7 +73,7 @@ sed "1s/Blocklist/Blocklist (AdGuard)/" > "../public/vn-badsite-filter-ag.txt" cat "domains.txt" | \ sort | \ sed -e "s/^/||/g" -e "s/$/\$document/g" | \ -sed '1 i\'"$COMMENT_UBO"'' | \ +sed "1i $COMMENT_UBO" | \ sed "1s/Blocklist/Blocklist (Vivaldi)/" > "../public/vn-badsite-filter-vivaldi.txt" @@ -83,13 +83,13 @@ COMMENT=$(printf "$COMMENT_UBO" | sed "s/^!/#/g" | awk '{printf "%s\\n", $0}' | cat "domains.txt" | \ sort | \ -sed '1 i\'"$COMMENT"'' > "../public/vn-badsite-filter-domains.txt" +sed "1i $COMMENT" > "../public/vn-badsite-filter-domains.txt" ## Hosts file blocklist cat "domains.txt" | \ sed "s/^/0.0.0.0 /g" | \ -sed '1 i\'"$COMMENT"'' | \ +sed "1i $COMMENT" | \ sed "1s/Domains/Hosts/" > "../public/vn-badsite-filter-hosts.txt" @@ -97,7 +97,7 @@ sed "1s/Domains/Hosts/" > "../public/vn-badsite-filter-hosts.txt" cat "domains.txt" | \ sed "s/^/address=\//g" | \ sed "s/$/\/0.0.0.0/g" | \ -sed '1 i\'"$COMMENT"'' | \ +sed "1i $COMMENT" | \ sed "1s/Blocklist/dnsmasq Blocklist/" > "../public/vn-badsite-filter-dnsmasq.conf" @@ -105,7 +105,7 @@ sed "1s/Blocklist/dnsmasq Blocklist/" > "../public/vn-badsite-filter-dnsmasq.con cat "domains.txt" | \ sed 's/^/zone "/g' | \ sed 's/$/" { type master; notify no; file "null.zone.file"; };/g' | \ -sed '1 i\'"$COMMENT"'' | \ +sed "1i $COMMENT" | \ sed "1s/Blocklist/BIND Blocklist/" > "../public/vn-badsite-filter-bind.conf" @@ -115,8 +115,8 @@ RPZ_SYNTAX="\n\$TTL 30\n@ IN SOA rpz.malware-filter.gitlab.io. hostmaster.rpz.ma cat "domains.txt" | \ sed "s/$/ CNAME ./g" | \ -sed '1 i\'"$RPZ_SYNTAX"'' | \ -sed '1 i\'"$COMMENT"'' | \ +sed "1i $RPZ_SYNTAX" | \ +sed "1i $COMMENT" | \ sed "s/^#/;/g" | \ sed "1s/Blocklist/RPZ Blocklist/" > "../public/vn-badsite-filter-rpz.conf" @@ -125,21 +125,21 @@ sed "1s/Blocklist/RPZ Blocklist/" > "../public/vn-badsite-filter-rpz.conf" cat "domains.txt" | \ sed 's/^/local-zone: "/g' | \ sed 's/$/" always_nxdomain/g' | \ -sed '1 i\'"$COMMENT"'' | \ +sed "1i $COMMENT" | \ sed "1s/Blocklist/Unbound Blocklist/" > "../public/vn-badsite-filter-unbound.conf" ## dnscrypt-proxy blocklists # name-based cat "domains.txt" | \ -sed '1 i\'"$COMMENT"'' | \ +sed "1i $COMMENT" | \ sed "1s/Domains/Names/" > "../public/vn-badsite-filter-dnscrypt-blocked-names.txt" # IPv4-based cat "domains.txt" | \ sort | \ grep -E "^([0-9]{1,3}[\.]){3}[0-9]{1,3}$" | \ -sed '1 i\'"$COMMENT"'' | \ +sed "1i $COMMENT" | \ sed "1s/Domains/IPs/" > "../public/vn-badsite-filter-dnscrypt-blocked-ips.txt" @@ -148,7 +148,7 @@ COMMENT_IE="msFilterList\n$COMMENT\n: Expires=1\n#" cat "domains.txt" | \ sed "s/^/-d /g" | \ -sed '1 i\'"$COMMENT_IE"'' | \ +sed "1i $COMMENT_IE" | \ sed "2s/Domains Blocklist/Hosts Blocklist (IE)/" > "../public/vn-badsite-filter.tpl" @@ -177,13 +177,13 @@ done < "domains.txt" set -x -sed -i '1 i\'"$COMMENT"'' "../public/vn-badsite-filter-snort2.rules" +sed -i "1i $COMMENT" "../public/vn-badsite-filter-snort2.rules" sed -i "1s/Blocklist/Snort2 Ruleset/" "../public/vn-badsite-filter-snort2.rules" -sed -i '1 i\'"$COMMENT"'' "../public/vn-badsite-filter-snort3.rules" +sed -i "1i $COMMENT" "../public/vn-badsite-filter-snort3.rules" sed -i "1s/Blocklist/Snort3 Ruleset/" "../public/vn-badsite-filter-snort3.rules" -sed -i '1 i\'"$COMMENT"'' "../public/vn-badsite-filter-suricata.rules" +sed -i "1i $COMMENT" "../public/vn-badsite-filter-suricata.rules" sed -i "1s/Blocklist/Suricata Ruleset/" "../public/vn-badsite-filter-suricata.rules"