mirror of
https://github.com/shivammathur/setup-php.git
synced 2024-11-25 21:13:04 +07:00
Improve fetching brew taps
This commit is contained in:
parent
56ad5977ba
commit
40a4cb064f
@ -10,7 +10,7 @@ self_hosted_helper() {
|
|||||||
# Disable dependency extensions
|
# Disable dependency extensions
|
||||||
disable_dependency_extensions() {
|
disable_dependency_extensions() {
|
||||||
local extension=$1
|
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
|
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' ' ')"
|
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
|
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
|
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.
|
# Function to get extension name from brew formula.
|
||||||
get_extension_from_formula() {
|
get_extension_from_formula() {
|
||||||
local formula=$1
|
local formula=$1
|
||||||
@ -76,7 +49,7 @@ copy_brew_extensions() {
|
|||||||
deps="$(grep -Eo 'depends_on "shivammathur[^"]+' "$formula_file" | cut -d '/' -f 3 | tr '\n' ' ')"
|
deps="$(grep -Eo 'depends_on "shivammathur[^"]+' "$formula_file" | cut -d '/' -f 3 | tr '\n' ' ')"
|
||||||
IFS=' ' read -r -a deps <<< "$formula@$version $deps"
|
IFS=' ' read -r -a deps <<< "$formula@$version $deps"
|
||||||
for dependency in "${deps[@]}"; do
|
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"
|
[ -e "$extension_file" ] && sudo cp "$extension_file" "$ext_dir"
|
||||||
done
|
done
|
||||||
sudo find -- "$brew_prefix"/Cellar/"$formula"@"$version" -name "*.dylib" -exec cp {} "$ext_dir" \;
|
sudo find -- "$brew_prefix"/Cellar/"$formula"@"$version" -name "*.dylib" -exec cp {} "$ext_dir" \;
|
||||||
@ -93,7 +66,7 @@ add_brew_extension() {
|
|||||||
else
|
else
|
||||||
add_brew_tap "$php_tap"
|
add_brew_tap "$php_tap"
|
||||||
add_brew_tap "$ext_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
|
update_dependencies >/dev/null 2>&1
|
||||||
disable_dependency_extensions "$extension" >/dev/null 2>&1
|
disable_dependency_extensions "$extension" >/dev/null 2>&1
|
||||||
brew install -f "$ext_tap/$formula@$version" >/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 to overwrite packages.
|
||||||
patch_brew() {
|
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\?"
|
code=" keg.link\(verbose: verbose\?"
|
||||||
sudo sed -Ei '' "s/$code.*/$code, overwrite: true\)/" "$formula_installer"
|
sudo sed -Ei '' "s/$code.*/$code, overwrite: true\)/" "$formula_installer"
|
||||||
# shellcheck disable=SC2064
|
# shellcheck disable=SC2064
|
||||||
@ -280,12 +253,6 @@ version=${1:-'8.1'}
|
|||||||
ini=${2:-'production'}
|
ini=${2:-'production'}
|
||||||
src=${0%/*}/..
|
src=${0%/*}/..
|
||||||
php_formula=shivammathur/php/php@"$version"
|
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
|
scripts="$src"/scripts
|
||||||
ext_tap=shivammathur/homebrew-extensions
|
ext_tap=shivammathur/homebrew-extensions
|
||||||
php_tap=shivammathur/homebrew-php
|
php_tap=shivammathur/homebrew-php
|
||||||
@ -298,9 +265,11 @@ export HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1
|
|||||||
|
|
||||||
# shellcheck source=.
|
# shellcheck source=.
|
||||||
. "${scripts:?}"/unix.sh
|
. "${scripts:?}"/unix.sh
|
||||||
|
. "${scripts:?}"/tools/brew.sh
|
||||||
. "${scripts:?}"/tools/add_tools.sh
|
. "${scripts:?}"/tools/add_tools.sh
|
||||||
. "${scripts:?}"/extensions/source.sh
|
. "${scripts:?}"/extensions/source.sh
|
||||||
. "${scripts:?}"/extensions/add_extensions.sh
|
. "${scripts:?}"/extensions/add_extensions.sh
|
||||||
|
configure_brew
|
||||||
read_env
|
read_env
|
||||||
self_hosted_setup
|
self_hosted_setup
|
||||||
setup_php
|
setup_php
|
||||||
|
71
src/scripts/tools/brew.sh
Normal file
71
src/scripts/tools/brew.sh
Normal file
@ -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
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user