From fd0107154e6b8bec2acee3de8b34c23956bcbe2f Mon Sep 17 00:00:00 2001 From: Christoph Date: Sun, 24 Oct 2021 13:07:29 +0200 Subject: [PATCH] Make script check_postfwd.sh compartible with Debian 11 (bullseye). --- check_postfwd.sh | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/check_postfwd.sh b/check_postfwd.sh index 4b290f0..f0da371 100755 --- a/check_postfwd.sh +++ b/check_postfwd.sh @@ -73,6 +73,41 @@ trim() { echo -n "$var" } +trim_double_quotes() { + local var="$*" + var="${var#"${var%%[!\"]*}"}" # remove leading whitespace characters + var="${var%"${var##*[!\"]}"}" # remove trailing whitespace characters + echo -n "$var" +} + +read_env_from_file() { + + _file="$*" + + while read _ENV _REST ; do + + _ENV="$(trim $_ENV)" + + if [[ "$_ENV" =~ .{2,}=.+ ]]; then + _key="${_ENV%=*}" + _val="${_ENV##*=}" + + + # - Remove leading / trailling double quotes + # - _val="${_val%\"}" + # - _val="${_val#\"}" + # - + _val="$(trim_double_quotes $_val)" + + if [[ -n "$(trim $_key)" ]] && [[ -n "$(trim $_val)" ]] ; then + export $_ENV + fi + fi + + done < "$_file" + +} + #--------------------------------------- #----------------------------- @@ -145,9 +180,12 @@ if [[ -n "$SYSTEMD_SERVICE" ]] ; then check_string_ps="$(trim $(cat "$_systemd_service_file" | grep ExecStart | grep -o -E "ExecStart\s*=\s*[^[:space:]]+" | cut -d "=" -f2))" fi else - check_string_ps="$(trim $(cat "$SYSV_INIT_SCRIPT" | grep DAEMON | grep -o -E "DAEMON\s*=\s*[^[:space:]]+" | cut -d "=" -f2))" -fi + read_env_from_file $SYSV_INIT_SCRIPT + + _check_string_ps="$(trim $(cat "$SYSV_INIT_SCRIPT" | grep DAEMON | grep -o -E "DAEMON\s*=\s*[^[:space:]]+" | cut -d "=" -f2))" + check_string_ps="$(eval echo "$_check_string_ps")" +fi #---------------------------------------