fix: handle empty upstream data

This commit is contained in:
Ming Di Leom 2024-10-16 09:49:48 +00:00
parent 60492c7d8d
commit f01a711836
No known key found for this signature in database
GPG Key ID: 32D3E28E96A695E8
1 changed files with 11 additions and 1 deletions

View File

@ -108,7 +108,6 @@ sed -e "s/^/||/g" -e "s/$/\$document/g" | \
sed "1i $COMMENT_UBO" | \
sed "1s/Blocklist/Blocklist (Vivaldi)/" > "../public/botnet-filter-vivaldi.txt"
## Hash comment
# awk + head is a workaround for sed prepend
COMMENT=$(printf "$COMMENT_UBO" | sed "s/^!/#/g" | awk '{printf "%s\\n", $0}' | head -c -2)
@ -145,6 +144,17 @@ done < "feodo-ip.txt"
set -x
# upstream may provide empty data
if [ ! -s "feodo-ip.txt" ]; then
printf "$COMMENT_UBO\n! END 0 entries\n" > "../public/botnet-filter.txt"
printf "$COMMENT_UBO\n! END 0 entries\n" > "../public/botnet-filter-agh.txt"
printf "$COMMENT_UBO\n! END 0 entries\n" > "../public/botnet-filter-ag.txt"
printf "$COMMENT_UBO\n! END 0 entries\n" > "../public/botnet-filter-vivaldi.txt"
printf "$COMMENT\n# END 0 entries\n" > "../public/botnet-filter-dnscrypt-blocked-ips.txt"
echo "# END 0 entries" > "../public/botnet-filter-suricata.rules"
echo "# END 0 entries" > "../public/botnet-filter-splunk.csv"
fi
sed -i "1i $COMMENT" "../public/botnet-filter-suricata.rules"
sed -i "1s/Blocklist/Suricata Ruleset/" "../public/botnet-filter-suricata.rules"