client: lib_gen: fix environment reader/resetter

- Fixes default env generation if current env exists
    * was not unsetting all previously exported env
- Adds debug output
This commit is contained in:
2024-07-19 16:29:02 -07:00
parent af533460ec
commit c34fd15a51

View File

@@ -269,11 +269,22 @@ function lib_gen::__set_client_globals()
function lib_gen::__read_env()
{
local _file="$1"
# Get environment
local _env=()
while read _line; do
_env+=("$_line")
done < <(printenv | grep -Eo "^DOCKER_FINANCE[^=]+")
# Reset environment
unset "$(printenv | grep -Eo "^DOCKER_FINANCE[^=]+")"
for _line in "${_env[@]}"; do
lib_utils::print_debug "Unsetting $_line"
unset "$_line"
done
# Set, if a script that generates env
if [[ "$(head -n1 $1)" =~ (bin|env|sh|bash) ]]; then
if [[ "$(head -n1 $_file)" =~ (bin|env|sh|bash) ]]; then
# shellcheck source=/dev/null
source "$global_repo_env_file"
return $?
@@ -291,7 +302,7 @@ function lib_gen::__read_env()
export "${_line?}" # SC2163
lib_utils::print_debug "$_line"
fi
done <"$1"
done <"$_file"
}
#
@@ -353,7 +364,10 @@ function lib_gen::__gen_client()
|| lib_utils::die_fatal
# Get/Set with repository defaults
lib_utils::print_debug "Reading $global_repo_env_file"
lib_gen::__read_env "$global_repo_env_file"
lib_utils::print_debug "Writing $global_env_file"
lib_gen::__write_env "$global_env_file"
fi
fi