From c34fd15a51e6a453f6a0932c9be5fa973c82dc83 Mon Sep 17 00:00:00 2001 From: Aaron Fiore Date: Fri, 19 Jul 2024 16:29:02 -0700 Subject: [PATCH] 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 --- client/src/docker/lib/internal/lib_gen.bash | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/client/src/docker/lib/internal/lib_gen.bash b/client/src/docker/lib/internal/lib_gen.bash index ec865d3..7005d07 100644 --- a/client/src/docker/lib/internal/lib_gen.bash +++ b/client/src/docker/lib/internal/lib_gen.bash @@ -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