Skip to content

Setup BASH_ENV and zshenv #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions src/artifacts-helper/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,19 @@ fi

if [ "${COMMA_SEP_TARGET_FILES}" = "DEFAULT" ]; then
if [ "${INSTALL_WITH_SUDO}" = "true" ]; then
COMMA_SEP_TARGET_FILES="~/.bashrc,~/.zshrc"
# 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/zshrc"
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

Expand All @@ -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
Expand Down