Files
threshold/enos/modules/aws_worker/scripts/set-up-login-shell-profile.sh
T
429247f407 [COMPLIANCE] Update Copyright Headers (#6282)
* [COMPLIANCE] Update Copyright and License Headers

* chore: make gen to generate files with copyright headers

* chore: update missed copyright headers

---------

Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
Co-authored-by: Justin Nguyen <justin.nguyen@hashicorp.com>
2026-01-28 11:05:07 -06:00

54 lines
1.2 KiB
Bash

#!/usr/bin/env bash
# Copyright IBM Corp. 2020, 2025
# SPDX-License-Identifier: BUSL-1.1
set -e
fail() {
echo "$1" 1>&2
exit 1
}
[[ -z "$BOUNDARY_INSTALL_DIR" ]] && fail "BOUNDARY_INSTALL_DIR env variable has not been set"
# Determine the profile file we should write to. We only want to affect login shells and bash will
# only read one of these in ordered of precendence.
determineProfileFile() {
if [ -f "$HOME/.bash_profile" ]; then
printf "%s/.bash_profile\n" "$HOME"
return 0
fi
if [ -f "$HOME/.bash_login" ]; then
printf "%s/.bash_login\n" "$HOME"
return 0
fi
printf "%s/.profile\n" "$HOME"
}
appendVaultProfileInformation() {
tee -a "$1" <<< "export PATH=$PATH:$BOUNDARY_INSTALL_DIR"
}
main() {
local profile_file
if ! profile_file=$(determineProfileFile); then
fail "failed to determine login shell profile file location"
fi
# If vault_cluster is used more than once, eg: autopilot or replication, this module can
# be called more than once. Short ciruit here if our profile is already set up.
if grep VAULT_ADDR < "$profile_file"; then
exit 0
fi
if ! appendVaultProfileInformation "$profile_file"; then
fail "failed to write vault configuration to login shell profile"
fi
exit 0
}
main