diff --git a/src/scripts/darwin.sh b/src/scripts/darwin.sh index 9289b1bf..c2caf8f7 100644 --- a/src/scripts/darwin.sh +++ b/src/scripts/darwin.sh @@ -10,7 +10,7 @@ self_hosted_helper() { # Disable dependency extensions disable_dependency_extensions() { local extension=$1 - formula_file="$tap_dir/$ext_tap/Formula/$extension@${version:?}.rb" + formula_file="${tap_dir:?}/$ext_tap/Formula/$extension@${version:?}.rb" if [ -e "$formula_file" ]; then IFS=" " read -r -a dependency_extensions <<< "$(grep -Eo "shivammathur.*@" "$formula_file" | xargs -I {} -n 1 basename '{}' | cut -d '@' -f 1 | tr '\n' ' ')" for dependency_extension in "${dependency_extensions[@]}"; do @@ -33,33 +33,6 @@ disable_extension_helper() { echo '' | sudo tee /tmp/extdisabled/"$version"/"$extension" >/dev/null 2>&1 } -# Function to fetch a brew tap. -fetch_brew_tap() { - tap=$1 - tap_user=$(dirname "$tap") - tap_name=$(basename "$tap") - mkdir -p "$tap_dir/$tap_user" - get -s -n "" "https://github.com/$tap/archive/master.tar.gz" | sudo tar -xzf - -C "$tap_dir/$tap_user" - if [ -d "$tap_dir/$tap_user/$tap_name-master" ]; then - sudo mv "$tap_dir/$tap_user/$tap_name-master" "$tap_dir/$tap_user/$tap_name" - fi -} - -# Function to add a brew tap. -add_brew_tap() { - tap=$1 - if ! [ -d "$tap_dir/$tap" ]; then - if [ "${runner:?}" = "self-hosted" ]; then - brew tap "$tap" >/dev/null 2>&1 - else - fetch_brew_tap "$tap" >/dev/null 2>&1 - if ! [ -d "$tap_dir/$tap" ]; then - brew tap "$tap" >/dev/null 2>&1 - fi - fi - fi -} - # Function to get extension name from brew formula. get_extension_from_formula() { local formula=$1 @@ -76,7 +49,7 @@ copy_brew_extensions() { deps="$(grep -Eo 'depends_on "shivammathur[^"]+' "$formula_file" | cut -d '/' -f 3 | tr '\n' ' ')" IFS=' ' read -r -a deps <<< "$formula@$version $deps" for dependency in "${deps[@]}"; do - extension_file="$brew_prefix/opt/$dependency/$(get_extension_from_formula "${dependency%@*}").so" + extension_file="${brew_prefix:?}/opt/$dependency/$(get_extension_from_formula "${dependency%@*}").so" [ -e "$extension_file" ] && sudo cp "$extension_file" "$ext_dir" done sudo find -- "$brew_prefix"/Cellar/"$formula"@"$version" -name "*.dylib" -exec cp {} "$ext_dir" \; @@ -93,7 +66,7 @@ add_brew_extension() { else add_brew_tap "$php_tap" add_brew_tap "$ext_tap" - sudo mv "$tap_dir"/"$ext_tap"/.github/deps/"$formula"/* "$core_repo/Formula/" 2>/dev/null || true + sudo mv "$tap_dir"/"$ext_tap"/.github/deps/"$formula"/* "${core_repo:?}/Formula/" 2>/dev/null || true update_dependencies >/dev/null 2>&1 disable_dependency_extensions "$extension" >/dev/null 2>&1 brew install -f "$ext_tap/$formula@$version" >/dev/null 2>&1 @@ -142,7 +115,7 @@ link_libraries() { # Patch brew to overwrite packages. patch_brew() { - formula_installer="$brew_repo"/Library/Homebrew/formula_installer.rb + formula_installer="${brew_repo:?}"/Library/Homebrew/formula_installer.rb code=" keg.link\(verbose: verbose\?" sudo sed -Ei '' "s/$code.*/$code, overwrite: true\)/" "$formula_installer" # shellcheck disable=SC2064 @@ -280,12 +253,6 @@ version=${1:-'8.1'} ini=${2:-'production'} src=${0%/*}/.. php_formula=shivammathur/php/php@"$version" -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 scripts="$src"/scripts ext_tap=shivammathur/homebrew-extensions php_tap=shivammathur/homebrew-php @@ -298,9 +265,11 @@ export HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1 # shellcheck source=. . "${scripts:?}"/unix.sh +. "${scripts:?}"/tools/brew.sh . "${scripts:?}"/tools/add_tools.sh . "${scripts:?}"/extensions/source.sh . "${scripts:?}"/extensions/add_extensions.sh +configure_brew read_env self_hosted_setup setup_php diff --git a/src/scripts/tools/brew.sh b/src/scripts/tools/brew.sh new file mode 100644 index 00000000..11ac8be7 --- /dev/null +++ b/src/scripts/tools/brew.sh @@ -0,0 +1,71 @@ +# 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 + tap_user=$(dirname "$tap") + tap_name=$(basename "$tap") + mkdir -p "$tap_dir/$tap_user" + branch="$(get -s -n "" "https://api.github.com/repos/$tap" | grep default_branch | cut -d: -f 2 | grep -Eo '[^\", ]+' | tr -d '\n')" + get -s -n "" "https://github.com/$tap/archive/$branch.tar.gz" | sudo tar -xzf - -C "$tap_dir/$tap_user" + sudo mv "$tap_dir/$tap_user/$tap_name-$branch" "$tap_dir/$tap_user/$tap_name" +} + +# Function to add a brew tap. +add_brew_tap() { + tap=$1 + if ! [ -d "$tap_dir/$tap" ]; then + if [ "${runner:?}" = "self-hosted" ]; then + brew tap "$tap" >/dev/null 2>&1 + else + fetch_brew_tap "$tap" >/dev/null 2>&1 + if ! [ -d "$tap_dir/$tap" ]; then + brew tap "$tap" >/dev/null 2>&1 + fi + fi + fi +} + +# 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 +}