From 0e319d471e148a855df6bffce25d9f3eeba1b960 Mon Sep 17 00:00:00 2001 From: Paul Brown <67805647+pb-dod@users.noreply.github.com> Date: Fri, 6 Oct 2023 15:21:25 -0500 Subject: [PATCH] CLOUD-2295: handle mac defaulting to bash_profile in core.shell (#67) @includedevan ran into an issue with the augment.sh script not running for new terminal windows while he was setting up a new mac while using bash as the default shell. I tested this myself with `chsh -s /bin/bash` and Mac definitely uses only `.bash_profile` only for new terminal windows. This PR makes a change to the `core.shell` step that sources the `augment.sh` script in bash_profile instead if you don't have a .bashrc yet. --------- Co-authored-by: Paul Brown --- VERSION | 2 +- formula/ih-core.rb | 2 +- lib/core/shell/step.sh | 41 ++++++++++++++++++++++++++++------------- 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/VERSION b/VERSION index 9dd1793..a52e041 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.1.34 +0.1.35 diff --git a/formula/ih-core.rb b/formula/ih-core.rb index 3bbd22f..0a853a4 100644 --- a/formula/ih-core.rb +++ b/formula/ih-core.rb @@ -1,5 +1,5 @@ class IhCore < Formula - VERSION="0.1.34" + VERSION="0.1.35" desc "Brew formula for installing core tools used at Included Health engineering." homepage "https://github.com/ConsultingMD/homebrew-ih-public" license "CC BY-NC-ND 4.0" diff --git a/lib/core/shell/step.sh b/lib/core/shell/step.sh index 8c1a682..724c59f 100644 --- a/lib/core/shell/step.sh +++ b/lib/core/shell/step.sh @@ -16,6 +16,7 @@ function ih::setup::core.shell::help() { function ih::setup::core.shell::test() { ih::log::debug "Checking for shell augment files and variables..." + if ! ih::setup::core.shell::private::validate-profile; then ih::log::debug "Profile is not valid" return 1 @@ -37,6 +38,13 @@ function ih::setup::core.shell::test() { return 1 fi + if [[ -f ~/.bash_profile ]]; then + if ! grep -q "source ~/.bashrc" ~/.bash_profile; then + ih::log::debug ".bashrc not sourced from .bash_profile" + return 1 + fi + fi + if ! grep -q -e "augment.sh" ~/.zshrc; then ih::log::debug "Augment not sourced in .zshrc" return 1 @@ -86,7 +94,7 @@ function ih::setup::core.shell::install() { echo "Configuring shells to source IH shell configs" - ih::setup::core.shell::private::configure-bashrc + ih::setup::core.shell::private::configure-bash ih::setup::core.shell::private::configure-zshrc echo "" @@ -102,27 +110,34 @@ BOOTSTRAP_SOURCE_LINE=' . "$HOME/.ih/augment.sh" ' -# Create bashrc if it doesn't exist, if it does, append standard template -function ih::setup::core.shell::private::configure-bashrc() { - if [[ ! -e "${HOME}/.bashrc" ]]; then - echo "Creating new ~/.bashrc file" - touch "${HOME}/.bashrc" +function ih::setup::core.shell::private::configure-bash() { + + # If ~/.bashrc doesn't exist, create it + if [[ ! -e ~/.bashrc ]]; then + echo "Creating new ~/.bashrc" + touch ~/.bashrc + fi + + # Check if .bash_profile exists and if it doesn't already source .bashrc, then add it + if [[ ! -e ~/.bash_profile || ! $(grep -q "source ~/.bashrc" ~/.bash_profile) ]]; then + echo "Ensuring .bash_profile sources .bashrc..." + echo "[[ -r ~/.bashrc ]] && source ~/.bashrc" >> ~/.bash_profile fi + # shellcheck disable=SC2016 - if grep -qF -E '^[^#]+\.ih/augment.sh' "${HOME}/.bashrc"; then - echo "Included Health shell augmentation already sourced in .bashrc" + if grep -qF -E '^[^#]+\.ih/augment.sh' ~/.bashrc; then + echo "Included Health shell augmentation already sourced in ~/.bashrc" else - echo "Appending Included Health config to .bashrc" + echo "Appending Included Health config to ~/.bashrc" # shellcheck disable=SC2016 - echo "$BOOTSTRAP_SOURCE_LINE" >>"${HOME}/.bashrc" + echo "$BOOTSTRAP_SOURCE_LINE" >> ~/.bashrc - echo "Updated .bashrc to include this line at the end: + echo "Updated ~/.bashrc to include this line at the end: $BOOTSTRAP_SOURCE_LINE -If you want to source IH scripts earlier, adjust your .bashrc" +If you want to source IH scripts earlier, adjust your ~/.bashrc" fi - } # Create zshrc if it doesn't exist, if it does, append standard template