setup-php/src/scripts/darwin.sh

154 lines
5.4 KiB
Bash
Raw Normal View History

2020-05-27 17:53:52 +07:00
# Function to setup environment for self-hosted runners.
2020-11-08 14:36:21 +07:00
self_hosted_helper() {
if ! command -v brew >/dev/null; then
2020-07-26 17:18:19 +07:00
step_log "Setup Brew"
2020-11-11 03:53:45 +07:00
get -q -e "/tmp/install.sh" "https://raw.githubusercontent.com/Homebrew/install/master/install.sh" && /tmp/install.sh >/dev/null 2>&1
2020-11-08 14:36:21 +07:00
add_log "${tick:?}" "Brew" "Installed Homebrew"
2020-05-27 17:53:52 +07:00
fi
}
# Function to remove extensions.
2020-01-30 13:33:30 +07:00
remove_extension() {
extension=$1
2020-05-07 04:57:00 +07:00
if check_extension "$extension"; then
2020-11-25 06:33:02 +07:00
sudo sed -Ei '' "/=(.*\/)?\"?$extension/d" "${ini_file:?}"
2020-11-08 14:36:21 +07:00
sudo rm -rf "${scan_dir:?}"/*"$extension"* "${ext_dir:?}"/"$extension".so >/dev/null 2>&1
(! check_extension "$extension" && add_log "${tick:?}" ":$extension" "Removed") ||
add_log "${cross:?}" ":$extension" "Could not remove $extension on PHP ${semver:?}"
2020-05-07 04:57:00 +07:00
else
2020-11-08 14:36:21 +07:00
add_log "${tick:?}" ":$extension" "Could not find $extension on PHP $semver"
2020-05-07 04:57:00 +07:00
fi
2020-01-30 13:33:30 +07:00
}
2020-05-27 17:53:52 +07:00
# Function to install a specific version of PECL extension.
2020-02-23 20:30:40 +07:00
add_pecl_extension() {
extension=$1
pecl_version=$2
prefix=$3
2020-11-08 14:36:21 +07:00
enable_extension "$extension" "$prefix"
if [[ $pecl_version =~ .*(alpha|beta|rc|snapshot|preview).* ]]; then
2020-07-14 15:42:50 +07:00
pecl_version=$(get_pecl_version "$extension" "$pecl_version")
fi
2020-02-23 20:30:40 +07:00
ext_version=$(php -r "echo phpversion('$extension');")
if [ "$ext_version" = "$pecl_version" ]; then
2020-11-08 14:36:21 +07:00
add_log "${tick:?}" "$extension" "Enabled"
2020-02-23 20:30:40 +07:00
else
2020-05-07 04:57:00 +07:00
remove_extension "$extension" >/dev/null 2>&1
2020-07-26 17:18:19 +07:00
pecl_install "$extension-$pecl_version"
add_extension_log "$extension-$pecl_version" "Installed and enabled"
2020-02-23 20:30:40 +07:00
fi
}
2020-06-19 05:39:13 +07:00
# Function to install a php extension from shivammathur/extensions tap.
add_brew_extension() {
extension=$1
2020-11-08 14:36:21 +07:00
prefix=$2
enable_extension "$extension" "$prefix"
if check_extension "$extension"; then
add_log "${tick:?}" "$extension" "Enabled"
else
if ! brew tap | grep -q shivammathur/extensions; then
brew tap --shallow shivammathur/extensions >/dev/null 2>&1
fi
tap_dir="$(brew --prefix)/Homebrew/Library/Taps"
sudo mv "$tap_dir"/shivammathur/homebrew-extensions/.github/deps/"$extension"/* "$tap_dir/homebrew/homebrew-core/Formula/" 2>/dev/null || true
2020-11-08 14:36:21 +07:00
brew install "$extension@$version" >/dev/null 2>&1
sudo cp "$(brew --prefix)/opt/$extension@$version/$extension.so" "$ext_dir"
add_extension_log "$extension" "Installed and enabled"
2020-06-19 05:39:13 +07:00
fi
}
2020-02-23 20:30:40 +07:00
# Function to setup extensions
add_extension() {
extension=$1
2020-11-08 14:36:21 +07:00
prefix=$2
enable_extension "$extension" "$prefix"
if check_extension "$extension"; then
add_log "${tick:?}" "$extension" "Enabled"
2020-02-23 11:14:33 +07:00
else
2020-11-08 14:36:21 +07:00
[[ "$version" =~ 5.[4-5] ]] && [ "$extension" = "imagick" ] && brew install pkg-config imagemagick >/dev/null 2>&1
pecl_install "$extension" >/dev/null 2>&1 &&
if [[ "$version" =~ ${old_versions:?} ]]; then echo "$prefix=$ext_dir/$extension.so" >>"$ini_file"; fi
add_extension_log "$extension" "Installed and enabled"
fi
2019-12-27 08:26:49 +07:00
}
2020-09-28 12:28:02 +07:00
# Function to handle request to add phpize and php-config.
add_devtools() {
tool=$1
2020-11-08 14:36:21 +07:00
add_log "${tick:?}" "$tool" "Added $tool $semver"
2020-01-30 13:33:30 +07:00
}
2020-05-27 17:53:52 +07:00
# Function to handle request to add PECL.
2019-12-27 08:26:49 +07:00
add_pecl() {
2020-09-28 12:28:02 +07:00
pecl_version=$(get_tool_version "pecl" "version")
2020-11-08 14:36:21 +07:00
add_log "${tick:?}" "PECL" "Found PECL $pecl_version"
2019-12-27 08:26:49 +07:00
}
# Function to update dependencies.
update_dependencies() {
2020-11-08 14:36:21 +07:00
if [[ "$version" =~ ${nightly_versions:?} ]] && [ "${runner:?}" != "self-hosted" ]; then
tap_dir="$(brew --prefix)/Homebrew/Library/Taps"
while read -r formula; do
2020-11-11 03:53:45 +07:00
get -q -n "$tap_dir/homebrew/homebrew-core/Formula/$formula.rb" "https://raw.githubusercontent.com/Homebrew/homebrew-core/master/Formula/$formula.rb" &
2020-11-08 14:36:21 +07:00
to_wait+=($!)
done <"$tap_dir/shivammathur/homebrew-php/.github/deps/${ImageOS:?}_${ImageVersion:?}"
wait "${to_wait[@]}"
fi
}
2020-11-08 14:36:21 +07:00
# Function to setup PHP 5.6 and newer using Homebrew.
add_php() {
2020-02-21 09:28:19 +07:00
action=$1
2020-11-08 14:36:21 +07:00
if ! brew tap | grep -q shivammathur/php; then
brew tap --shallow shivammathur/php
fi
update_dependencies
if brew list php@"$version" 2>/dev/null | grep -q "Error" && [ "$action" != "upgrade" ]; then
brew unlink php@"$version"
else
brew "$action" shivammathur/php/php@"$version"
fi
2020-04-23 17:55:29 +07:00
brew link --force --overwrite php@"$version"
2020-02-21 09:28:19 +07:00
}
2020-11-08 14:36:21 +07:00
# Function to Setup PHP
setup_php() {
step_log "Setup PHP"
existing_version=$(php-config --version 2>/dev/null | cut -c 1-3)
if [[ "$version" =~ ${old_versions:?} ]]; then
2020-11-11 03:53:45 +07:00
run_script "php5-darwin" "${version/./}" >/dev/null 2>&1
2020-11-08 14:36:21 +07:00
status="Installed"
elif [ "$existing_version" != "$version" ]; then
add_php "install" >/dev/null 2>&1
status="Installed"
elif [ "$existing_version" = "$version" ] && [ "${update:?}" = "true" ]; then
add_php "upgrade" >/dev/null 2>&1
status="Updated to"
else
status="Found"
fi
ini_file=$(php -d "date.timezone=UTC" --ini | grep "Loaded Configuration" | sed -e "s|.*:s*||" | sed "s/ //g")
sudo chmod 777 "$ini_file" "${tool_path_dir:?}"
echo -e "date.timezone=UTC\nmemory_limit=-1" >>"$ini_file"
ext_dir=$(php -i | grep -Ei "extension_dir => /" | sed -e "s|.*=> s*||")
scan_dir=$(php --ini | grep additional | sed -e "s|.*: s*||")
sudo mkdir -m 777 -p "$ext_dir" "$HOME/.composer"
semver=$(php -v | head -n 1 | cut -f 2 -d ' ')
if [[ ! "$version" =~ $old_versions ]]; then configure_pecl >/dev/null 2>&1; fi
sudo cp "$dist"/../src/configs/*.json "$RUNNER_TOOL_CACHE/"
add_log "$tick" "PHP" "$status PHP $semver"
}
# Variables
version=$1
2020-10-05 07:45:50 +07:00
dist=$2
2020-11-08 14:36:21 +07:00
export HOMEBREW_NO_INSTALL_CLEANUP=1
export HOMEBREW_NO_AUTO_UPDATE=1
2020-11-08 14:36:21 +07:00
# shellcheck source=.
. "${dist}"/../src/scripts/common.sh
2020-05-27 17:53:52 +07:00
read_env
2020-11-08 14:36:21 +07:00
self_hosted_setup
setup_php