From 71b0e09dbce081ad89f67e8521d8377862a33b59 Mon Sep 17 00:00:00 2001 From: Shivam Mathur Date: Mon, 10 Oct 2022 16:24:35 +0530 Subject: [PATCH] Improve brew support on Linux --- src/scripts/darwin.sh | 9 ------ src/scripts/tools/brew.sh | 58 +++++++++++++++++++++++---------------- 2 files changed, 35 insertions(+), 32 deletions(-) diff --git a/src/scripts/darwin.sh b/src/scripts/darwin.sh index 4a1f38bc..1625d72b 100644 --- a/src/scripts/darwin.sh +++ b/src/scripts/darwin.sh @@ -1,12 +1,3 @@ -# Function to setup environment for self-hosted runners. -self_hosted_helper() { - if ! command -v brew >/dev/null; then - step_log "Setup Brew" - get -q -e "/tmp/install.sh" "https://raw.githubusercontent.com/Homebrew/install/master/install.sh" && /tmp/install.sh >/dev/null 2>&1 - add_log "${tick:?}" "Brew" "Installed Homebrew" - fi -} - # Disable dependency extensions disable_dependency_extensions() { local extension=$1 diff --git a/src/scripts/tools/brew.sh b/src/scripts/tools/brew.sh index 11ac8be7..8d88c0fb 100644 --- a/src/scripts/tools/brew.sh +++ b/src/scripts/tools/brew.sh @@ -1,26 +1,3 @@ -# Function to configure brew constants. -configure_brew() { - brew_path="$(command -v brew)" - brew_path_dir="$(dirname "$brew_path")" - brew_prefix="$brew_path_dir"/.. - brew_repo="$brew_path_dir/$(dirname "$(readlink "$brew_path")")"/.. - tap_dir="$brew_repo"/Library/Taps - core_repo="$tap_dir"/homebrew/homebrew-core - - export HOMEBREW_CHANGE_ARCH_TO_ARM=1 - export HOMEBREW_DEVELOPER=1 - export HOMEBREW_NO_AUTO_UPDATE=1 - export HOMEBREW_NO_ENV_HINTS=1 - export HOMEBREW_NO_INSTALL_CLEANUP=1 - export HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1 - export brew_path - export brew_path_dir - export brew_prefix - export brew_repo - export tap_dir - export core_repo -} - # Function to fetch a brew tap. fetch_brew_tap() { tap=$1 @@ -47,9 +24,44 @@ add_brew_tap() { fi } +# Function to get brew prefix. +get_brew_prefix() { + if [ "$(uname -s)" = "Linux" ]; then + echo /home/linuxbrew/.linuxbrew + else + if [ "$(uname -m)" = "arm64" ]; then + echo /opt/homebrew + else + echo /usr/local + fi + fi +} + +# Function to add brew's bin directories to the PATH. +add_brew_bins_to_path() { + local brew_prefix=${1:-$(get_brew_prefix)} + add_path "$brew_prefix"/bin + add_path "$brew_prefix"/sbin +} + +# Function to add brew. +add_brew() { + brew_prefix="$(get_brew_prefix)" + if ! [ -d "$brew_prefix"/bin ]; then + step_log "Setup Brew" + get -s "" "/tmp/install.sh" "https://raw.githubusercontent.com/Homebrew/install/master/install.sh" | bash -s >/dev/null 2>&1 + add_log "${tick:?}" "Brew" "Installed Homebrew" + fi + add_brew_bins_to_path "$brew_prefix" +} + # Function to configure brew constants. configure_brew() { brew_path="$(command -v brew)" + if [ -z "$brew_path" ]; then + add_brew + brew_path="$(command -v brew)" + fi brew_path_dir="$(dirname "$brew_path")" brew_prefix="$brew_path_dir"/.. brew_repo="$brew_path_dir/$(dirname "$(readlink "$brew_path")")"/..