From 38432014c7cb69cb19472f59a002d82657c7e3b5 Mon Sep 17 00:00:00 2001 From: Mike Wallio Date: Fri, 21 Mar 2025 16:12:34 -0400 Subject: [PATCH 1/2] Update to use `.zshenv` over `.zshrc` `.zshenv` is sourced by all zsh shells (interactive/non-interactive/login). Where `.zshrc` is only sourced by interactive shells. To prevent users from having to be aware of auth wrappers, using `.zshenv` will help reduce friction for users. --- src/artifacts-helper/install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/artifacts-helper/install.sh b/src/artifacts-helper/install.sh index d460f94..05ac10c 100755 --- a/src/artifacts-helper/install.sh +++ b/src/artifacts-helper/install.sh @@ -118,9 +118,9 @@ fi if [ "${COMMA_SEP_TARGET_FILES}" = "DEFAULT" ]; then if [ "${INSTALL_WITH_SUDO}" = "true" ]; then - COMMA_SEP_TARGET_FILES="~/.bashrc,~/.zshrc" + COMMA_SEP_TARGET_FILES="~/.bashrc,~/.zshenv" else - COMMA_SEP_TARGET_FILES="/etc/bash.bashrc,/etc/zsh/zshrc" + COMMA_SEP_TARGET_FILES="/etc/bash.bashrc,/etc/zsh/zshenv" fi fi From 2dc2f33b361d8a6f6f3d2e7818f8328da0cbc03a Mon Sep 17 00:00:00 2001 From: Mike Wallio Date: Fri, 21 Mar 2025 22:44:35 -0400 Subject: [PATCH 2/2] Add BASH_ENV to zsh and bash BASH_ENV is a variable used for identifying a script that should be sourced before launch bash scripts --- src/artifacts-helper/install.sh | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/artifacts-helper/install.sh b/src/artifacts-helper/install.sh index 05ac10c..84dc190 100755 --- a/src/artifacts-helper/install.sh +++ b/src/artifacts-helper/install.sh @@ -118,9 +118,19 @@ fi if [ "${COMMA_SEP_TARGET_FILES}" = "DEFAULT" ]; then if [ "${INSTALL_WITH_SUDO}" = "true" ]; then - COMMA_SEP_TARGET_FILES="~/.bashrc,~/.zshenv" + # Scripts to add auth wrapping functions to. .zshenv is always sourced by zsh, but for bash + # .bashrc is only sourced in interactive shells, and BASH_ENV is only sourced in bash scripts. + COMMA_SEP_TARGET_FILES="~/.bashrc,~/.zshenv,~/.bashenv" + # BASH_ENV is only sourced when running a bash script, without this, scripts will not + # call the auth function wrappers. + BASH_ENV_FILE="~/.bashenv" + # We'll need to update the .bashrc and .zshrc to have the BASH_ENV variable set so that + # bash scripts ran from zsh/bash source the BASH_ENV_FILE + COMMA_SEP_RC_FILES="~/.bashrc,~/.zshenv" else - COMMA_SEP_TARGET_FILES="/etc/bash.bashrc,/etc/zsh/zshenv" + COMMA_SEP_TARGET_FILES="/etc/bash.bashrc,/etc/zsh/zshenv,/etc/bash.bashenv" + BASH_ENV_FILE="/etc/bash.bashenv" + COMMA_SEP_RC_FILES="/etc/bash.bashrc,/etc/zsh/zshenv" fi fi @@ -138,6 +148,18 @@ for ALIAS in "${ALIASES_ARR[@]}"; do done done +IFS=',' read -r -a RC_FILES_ARR <<< "$COMMA_SEP_RC_FILES" + +# Register a BASH_ENV variable in zshrc and bashrc so that when we run bash +# scripts they will source the $BASH_ENV_FILE and get the auth function wrappers +for RC_FILE in "${RC_FILES_ARR[@]}"; do + if [ "${INSTALL_WITH_SUDO}" = "true" ]; then + sudo -u ${_REMOTE_USER} bash -c "echo 'export BASH_ENV=\"$BASH_ENV_FILE\"' >> $RC_FILE" + else + echo "export BASH_ENV=\"$BASH_ENV_FILE\"" >> $RC_FILE || true + fi +done + if [ "${INSTALL_WITH_SUDO}" = "true" ]; then sudo -u ${_REMOTE_USER} bash -c "/tmp/install-provider.sh ${USENET6}" fi