Fix sudo in the darwin installer (#10128)

This commit is contained in:
Théophane Hufschmitt 2024-03-06 22:36:37 +01:00 committed by GitHub
parent 67f95755d6
commit 686405ef41
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -69,16 +69,17 @@ readonly PROXY_ENVIRONMENT_VARIABLES=(
NO_PROXY
)
SUDO_EXTRA_ENVIRONMENT_VARIABLES=()
SUDO_KEPT_ENVIRONMENT_VARIABLES=""
setup_sudo_extra_environment_variables() {
local i=${#SUDO_EXTRA_ENVIRONMENT_VARIABLES[@]}
for variable in "${PROXY_ENVIRONMENT_VARIABLES[@]}"; do
if [ "x${!variable:-}" != "x" ]; then
SUDO_EXTRA_ENVIRONMENT_VARIABLES[i]="$variable=${!variable}"
i=$((i + 1))
SUDO_KEPT_ENVIRONMENT_VARIABLES="$SUDO_KEPT_ENVIRONMENT_VARIABLES,$variable"
fi
done
# Required by the darwin installer
export SUDO_KEPT_ENVIRONMENT_VARIABLES
}
setup_sudo_extra_environment_variables
@ -386,7 +387,7 @@ _sudo() {
if is_root; then
env "$@"
else
sudo "${SUDO_EXTRA_ENVIRONMENT_VARIABLES[@]}" "$@"
sudo --preserve-env="$SUDO_KEPT_ENVIRONMENT_VARIABLES" "$@"
fi
}