router/firewall-edit.sh

23 lines
545 B
Bash
Raw Permalink 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"
2022-01-31 11:40:03 -06:00
sudo -E nvim "$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!"
}