Files
cloudron-box/src/scripts/setblocklist.sh

29 lines
773 B
Bash
Raw Normal View History

2020-08-31 18:22:33 -07:00
#!/bin/bash
set -eu -o pipefail
if [[ ${EUID} -ne 0 ]]; then
echo "This script should be run as root." > /dev/stderr
exit 1
fi
if [[ $# == 1 && "$1" == "--check" ]]; then
echo "OK"
exit 0
fi
2021-04-14 21:24:37 -07:00
[[ "${BOX_ENV}" == "test" ]] && exit
2020-08-31 18:22:33 -07:00
ipset flush cloudron_blocklist
user_firewall_json="/home/yellowtent/platformdata/firewall/blocklist.txt"
2020-08-31 18:22:33 -07:00
if [[ -f "${user_firewall_json}" ]]; then
# without the -n block, any last line without a new line won't be read it!
while read -r line || [[ -n "$line" ]]; do
[[ -z "${line}" ]] && continue # ignore empty lines
[[ "$line" =~ ^#.*$ ]] && continue # ignore lines starting with #
2020-09-14 13:53:58 -07:00
ipset add -! cloudron_blocklist "${line}" # the -! ignore duplicates
done < "${user_firewall_json}"
2020-08-31 18:22:33 -07:00
fi