Skip to content

Commit

Permalink
🐛 Ensure brew is available on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
alrra committed Sep 5, 2023
1 parent d56fbf9 commit 41db4e1
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 10 deletions.
42 changes: 38 additions & 4 deletions src/os/installs/macos/homebrew.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,40 @@ cd "$(dirname "${BASH_SOURCE[0]}")" \

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

get_homebrew_git_config_file_path() {
add_to_path() {

# Check if `brew` is available.

if command -v brew &> /dev/null; then
return
fi

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

# If not, add it to the PATH.

HARDWARE="$(uname -m)"
prefix=""

if [ "$HARDWARE" == "arm64" ]; then
prefix="/opt/homebrew"
elif [ "$HARDWARE" == "x86_64" ]; then
prefix="/usr/local"
else
print_error "Homebrew is only supported on Intel and ARM processors!"
fi

PATH="$prefix/bin:$PATH"

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

# Inform the user about the availability of `brew`.

command -v brew &> /dev/null
print_result $? "Add to PATH"
}

get_git_config_file_path() {

local path=""

Expand All @@ -22,7 +55,7 @@ get_homebrew_git_config_file_path() {

}

install_homebrew() {
install() {

if ! cmd_exists "brew"; then
ask_for_sudo
Expand All @@ -42,7 +75,7 @@ opt_out_of_analytics() {

# Try to get the path of the `Homebrew` git config file.

path="$(get_homebrew_git_config_file_path)" \
path="$(get_git_config_file_path)" \
|| return 1

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Expand Down Expand Up @@ -75,7 +108,8 @@ main() {

print_in_purple "\n Homebrew\n\n"

install_homebrew
install
add_to_path
opt_out_of_analytics

update
Expand Down
22 changes: 16 additions & 6 deletions src/shell/macos/bash_init
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,23 @@

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

# If needed, add Homebrew to the PATH.
# Set up Homebrew.

if ! command -v brew &> /dev/null && \
[[ -f /opt/homebrew/bin/brew ]] && \
[[ $(sysctl -n machdep.cpu.brand_string) == Apple\ M* ]]; then
eval "$(/opt/homebrew/bin/brew shellenv)"
fi
set_homebrew() {
HARDWARE="$(uname -m)"
prefix=""

if [ "$HARDWARE" == "arm64" ]; then
prefix="/opt/homebrew"
elif [ "$HARDWARE" == "x86_64" ]; then
prefix="/usr/local"
fi

eval "$($prefix/bin/brew shellenv)"
}

set_homebrew
unset -f set_homebrew

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Expand Down

0 comments on commit 41db4e1

Please sign in to comment.