Improve legacy config parsing

This commit is contained in:
Jérémy Lecour 2022-04-28 18:58:11 +02:00 committed by Jérémy Lecour
parent 4c6d6941e2
commit 36d4a2e9a8
2 changed files with 5 additions and 2 deletions

View file

@ -16,6 +16,7 @@ and this project **does not adhere to [Semantic Versioning](http://semver.org/sp
* use long options in some places
* output is normalized
* source legacy config after macros but before DROP policy
* improve legacy config parsing
### Deprecated

View file

@ -214,7 +214,8 @@ source_configuration() {
exit 1
fi
if grep -e "iptables" -e "ip6tables" "${config_file}" | grep -qvE "^#"; then
# If we find something other than a blank line, a comment or a variable assignment
if grep --quiet --extended-regexp --invert-match "^\s*(#|$|\w+=)" "${config_file}"; then
# Backward compatible mode
###########################
@ -240,7 +241,8 @@ source_configuration() {
# and not interfere with the configuration step.
tmp_config_file=$(mktemp --tmpdir=/tmp minifirewall.XXX)
grep -E "^\s*[_a-zA-Z0-9]+=" "${config_file}" > "${tmp_config_file}"
# get only variable assignments
grep -E "^\s*\w+=" "${config_file}" > "${tmp_config_file}"
source_file_or_error "${tmp_config_file}"
rm -f "${tmp_config_file}"