From ec441aefef3f70a42426ab421ada8284bd43977b Mon Sep 17 00:00:00 2001 From: Brooke Kuhlmann Date: Mon, 22 Feb 2021 19:49:58 -0700 Subject: [PATCH] Added environment configuration for scripts Necessary to ensure machines are properly configured for running these scripts on either Apple Silicon or Intel based machines. --- bin/run | 2 ++ lib/utilities.sh | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/bin/run b/bin/run index db12913..9bb1fa4 100755 --- a/bin/run +++ b/bin/run @@ -23,6 +23,8 @@ else exit 1 fi +configure_environment + while true; do if [[ $# == 0 ]]; then printf "\nUsage: run OPTION\n" diff --git a/lib/utilities.sh b/lib/utilities.sh index 8797702..31d76b4 100644 --- a/lib/utilities.sh +++ b/lib/utilities.sh @@ -101,3 +101,18 @@ get_install_root() { esac } export -f get_install_root + +# Configures shell for new machines and ensures PATH is properly configured for running scripts. +# Parameters: None. +configure_environment() { + if [[ ! -s "$HOME/.bash_profile" ]]; then + printf "%s\n" "if [ -f ~/.bashrc ]; then . ~/.bashrc; fi" > "$HOME/.bash_profile" + fi + + if [[ ! -s "$HOME/.bashrc" ]]; then + printf "%s\n" 'export PATH="/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"' > "$HOME/.bashrc" + fi + + export PATH="/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/opt/homebrew/sbin:/usr/local/sbin:/usr/sbin:/sbin:$PATH" +} +export -f configure_environment