vpn-policy-routing: custom user scripts improvements

Signed-off-by: Stan Grishin <stangri@melmac.net>
This commit is contained in:
Stan Grishin
2021-02-24 19:44:10 +00:00
parent 7d9d8616cf
commit 7d26130b33
3 changed files with 30 additions and 19 deletions
@@ -4,8 +4,16 @@
TARGET_IPSET='wan'
TARGET_URL="https://ip-ranges.amazonaws.com/ip-ranges.json"
TARGET_FNAME="/var/tmp_aws_ip_ranges"
TARGET_FNAME="/var/vpn-policy-routing_tmp_aws_ip_ranges"
curl "$TARGET_URL" 2>/dev/null | grep "ip_prefix" | sed 's/^.*\"ip_prefix\": \"//; s/\",//' > "$TARGET_FNAME"
awk -v ipset="$TARGET_IPSET" '{print "add " ipset " " $1}' "$TARGET_FNAME" | ipset restore -!
_ret=1
if [ ! -s "$TARGET_FNAME" ]; then
curl "$TARGET_URL" 2>/dev/null | grep "ip_prefix" | sed 's/^.*\"ip_prefix\": \"//; s/\",//' > "$TARGET_FNAME"
fi
if [ -s "$TARGET_FNAME" ]; then
awk -v ipset="$TARGET_IPSET" '{print "add " ipset " " $1}' "$TARGET_FNAME" | ipset restore -! && _ret=0
fi
rm -f "$TARGET_FNAME"
return $_ret