router/firewall-edit.bash

23 lines
548 B
Bash
Raw Normal View History

2021-07-09 17:21:45 -05:00
#!/usr/bin/env bash
# TODO: diff with existing before just overwriting what's here in git?
2021-07-10 14:46:26 -05:00
my_config="$(dirname "$(realpath "$0")")/nftables.conf"
2021-07-10 23:48:10 -05:00
t="/tmp/nftables.conf"
2021-07-10 14:46:26 -05:00
# we don't care about existing rules - just use ours, thanks
# sudo nft -s list ruleset >> "$f"
2023-07-17 13:09:47 -05:00
sudo -E $EDITOR "$my_config"
2021-07-10 14:46:26 -05:00
cat "$my_config"
echo "Do you want to load this config? [y/N]"
read -r l
[[ $l == "y" ]] && {
2021-07-10 23:48:10 -05:00
printf "flush ruleset\n\n" > "$t"
cat "$my_config" >> "$t"
sudo nft -f "$t"
2021-07-10 14:46:26 -05:00
sudo cp "$my_config" "/etc/nftables.conf"
2021-07-10 23:48:10 -05:00
rm "$t"
2021-07-10 14:46:26 -05:00
echo "Done loading!"
}