refactor: drop sed '~' syntax

- use grep to exclude '#' comment, instead of using sed '~' line traversal
- busybox sed doesn't support '~'
This commit is contained in:
curben 2020-04-19 08:25:58 +01:00
parent 2d2aa96aad
commit 7227b68ee7
No known key found for this signature in database
GPG Key ID: 5D9DB57A25D34EE3
2 changed files with 18 additions and 8 deletions

View File

@ -8,7 +8,7 @@ deploy_job:
stage: deploy_stage
before_script:
- 'which ssh-agent || (apk update && apk add curl openssh-client git grep sed)'
- 'which ssh-agent || (apk update && apk add curl openssh-client git grep)'
script:
- sh script.sh
@ -61,7 +61,7 @@ failed_job:
stage: failed_stage
before_script:
- 'which ssh-agent || (apk update && apk add curl openssh-client git grep sed)'
- 'which ssh-agent || (apk update && apk add curl openssh-client git grep)'
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
- echo "$GH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null

View File

@ -125,26 +125,36 @@ sed "1s/Malicious/Online Malicious/" > "../urlhaus-filter-domains-online.txt"
## Hosts file blocklist
cat "../urlhaus-filter-domains.txt" | \
# Exclude comment with #
grep -vE "^#" | \
# Remove IPv4 address
grep -vE "([0-9]{1,3}[\.]){3}[0-9]{1,3}" | \
sed "6~1s/^/0.0.0.0 /g" | \
sed "s/^/0.0.0.0 /g" | \
# Re-insert comment
sed '1 i\'"$COMMENT"'' | \
sed "1s/Domains/Hosts/" > "../urlhaus-filter-hosts.txt"
cat "../urlhaus-filter-domains-online.txt" | \
grep -vE "^#" | \
grep -vE "([0-9]{1,3}[\.]){3}[0-9]{1,3}" | \
sed "6~1s/^/0.0.0.0 /g" | \
sed "s/^/0.0.0.0 /g" | \
sed '1 i\'"$COMMENT"'' | \
sed "1s/Domains/Hosts/" > "../urlhaus-filter-hosts-online.txt"
## Dnsmasq-compatible blocklist
cat "../urlhaus-filter-hosts.txt" | \
sed "6~1s/^0.0.0.0 /address=\//g" | \
sed "6~1s/$/\/0.0.0.0/g" | \
grep -vE "^#" | \
sed "s/^0.0.0.0 /address=\//g" | \
sed "s/$/\/0.0.0.0/g" | \
sed '1 i\'"$COMMENT"'' | \
sed "1s/Blocklist/dnsmasq Blocklist/" > "../urlhaus-filter-dnsmasq.conf"
cat "../urlhaus-filter-hosts-online.txt" | \
sed "6~1s/^0.0.0.0 /address=\//g" | \
sed "6~1s/$/\/0.0.0.0/g" | \
grep -vE "^#" | \
sed "s/^0.0.0.0 /address=\//g" | \
sed "s/$/\/0.0.0.0/g" | \
sed '1 i\'"$COMMENT"'' | \
sed "1s/Blocklist/dnsmasq Blocklist/" > "../urlhaus-filter-dnsmasq-online.conf"
cd ../ && rm -rf "tmp/"