style(sed): avoid backslash in insert option

- simpler and more readable
- https://unix.stackexchange.com/a/99351
This commit is contained in:
Ming Di Leom 2022-12-17 00:37:26 +00:00
parent 3b97af4dc2
commit 30add07aed
No known key found for this signature in database
GPG Key ID: 32D3E28E96A695E8
1 changed files with 17 additions and 17 deletions

View File

@ -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"