Skip to content

Commit

Permalink
CLOUD-2295: handle mac defaulting to bash_profile in core.shell (#67)
Browse files Browse the repository at this point in the history
@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 <[email protected]>
  • Loading branch information
pb-dod and Paul Brown authored Oct 6, 2023
1 parent 72c1ae4 commit 0e319d4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.34
0.1.35
2 changes: 1 addition & 1 deletion formula/ih-core.rb
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
41 changes: 28 additions & 13 deletions lib/core/shell/step.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 ""
Expand All @@ -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
Expand Down

0 comments on commit 0e319d4

Please sign in to comment.