Created
July 18, 2023 19:22
-
-
Save aucampia/1a7b8b1f717b3ef3118677d52014d53f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -euo pipefail | |
OLD_FILE="$(mktemp iptables-save-old.XXXXXXXXXX)" | |
NEW_FILE="$(mktemp iptables-edit-new.XXXXXXXXXX)" | |
cleanup() { | |
for file in "${OLD_FILE}" "${NEW_FILE}" | |
do | |
if [[ -e "${file}" ]] | |
then | |
rm -v "${file}" | |
fi | |
done | |
} | |
# trap cleanup EXIT | |
iptables-save -f "${OLD_FILE}" | |
cp -v "${OLD_FILE}" "${NEW_FILE}" | |
"${EDITOR:-vim}" "${NEW_FILE}" | |
if ! diff -u "${OLD_FILE}" "${NEW_FILE}" | |
then | |
iptables-apply "${NEW_FILE}" | |
else | |
1>&2 echo "No changes made." | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment