Make script check_postfwd.sh compartible with Debian 11 (bullseye).

This commit is contained in:
Christoph 2021-10-24 13:07:29 +02:00
parent f6d6ee1769
commit fd0107154e

View File

@ -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
#---------------------------------------