2020-05-27 17:53:52 +07:00
|
|
|
# Function to log start of a operation.
|
2019-10-17 03:11:13 +07:00
|
|
|
step_log() {
|
|
|
|
message=$1
|
|
|
|
printf "\n\033[90;1m==> \033[0m\033[37;1m%s\033[0m\n" "$message"
|
|
|
|
}
|
|
|
|
|
2020-05-27 17:53:52 +07:00
|
|
|
# Function to log result of a operation.
|
2019-10-17 03:11:13 +07:00
|
|
|
add_log() {
|
|
|
|
mark=$1
|
|
|
|
subject=$2
|
|
|
|
message=$3
|
|
|
|
if [ "$mark" = "$tick" ]; then
|
|
|
|
printf "\033[32;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s\033[0m\n" "$mark" "$subject" "$message"
|
|
|
|
else
|
|
|
|
printf "\033[31;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s\033[0m\n" "$mark" "$subject" "$message"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-05-27 17:53:52 +07:00
|
|
|
# Function to read env inputs.
|
|
|
|
read_env() {
|
|
|
|
[[ -z "${update}" ]] && update='false' && UPDATE='false' || update="${update}"
|
|
|
|
[ "$update" = false ] && [[ -n ${UPDATE} ]] && update="${UPDATE}"
|
|
|
|
[[ -z "${runner}" ]] && runner='github' && RUNNER='github' || runner="${runner}"
|
|
|
|
[ "$runner" = false ] && [[ -n ${RUNNER} ]] && runner="${RUNNER}"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Function to setup environment for self-hosted runners.
|
|
|
|
self_hosted_setup() {
|
|
|
|
if [[ $(command -v brew) == "" ]]; then
|
|
|
|
step_log "Setup Brew"
|
2020-07-23 07:17:11 +07:00
|
|
|
curl "${curl_opts[@]}" https://raw.githubusercontent.com/Homebrew/install/master/install.sh | bash -s >/dev/null 2>&1
|
2020-05-27 17:53:52 +07:00
|
|
|
add_log "$tick" "Brew" "Installed Homebrew"
|
|
|
|
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
|
|
|
|
sudo sed -i '' "/$extension/d" "$ini_file"
|
|
|
|
sudo rm -rf "$scan_dir"/*"$extension"* >/dev/null 2>&1
|
|
|
|
sudo rm -rf "$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"
|
|
|
|
else
|
|
|
|
add_log "$tick" ":$extension" "Could not find $extension on PHP $semver"
|
|
|
|
fi
|
2020-01-30 13:33:30 +07:00
|
|
|
}
|
|
|
|
|
2020-05-27 17:53:52 +07:00
|
|
|
# Function to test if extension is loaded.
|
2020-02-23 20:30:40 +07:00
|
|
|
check_extension() {
|
2019-10-11 06:11:25 +07:00
|
|
|
extension=$1
|
2020-03-16 08:23:58 +07:00
|
|
|
if [ "$extension" != "mysql" ]; then
|
|
|
|
php -m | grep -i -q -w "$extension"
|
|
|
|
else
|
|
|
|
php -m | grep -i -q "$extension"
|
|
|
|
fi
|
2019-12-20 19:59:05 +07:00
|
|
|
}
|
|
|
|
|
2020-05-27 17:53:52 +07:00
|
|
|
# Fuction to get the PECL version.
|
2020-01-30 13:33:30 +07:00
|
|
|
get_pecl_version() {
|
2020-01-26 02:34:09 +07:00
|
|
|
extension=$1
|
2020-07-14 15:42:50 +07:00
|
|
|
stability="$(echo "$2" | grep -m 1 -Eio "(alpha|beta|rc|snapshot)")"
|
2020-01-30 13:33:30 +07:00
|
|
|
pecl_rest='https://pecl.php.net/rest/r/'
|
2020-07-23 07:17:11 +07:00
|
|
|
response=$(curl "${curl_opts[@]}" "$pecl_rest$extension"/allreleases.xml)
|
2020-07-14 15:42:50 +07:00
|
|
|
pecl_version=$(echo "$response" | grep -m 1 -Eio "(\d*\.\d*\.\d*$stability\d*)")
|
2020-01-30 13:33:30 +07:00
|
|
|
if [ ! "$pecl_version" ]; then
|
|
|
|
pecl_version=$(echo "$response" | grep -m 1 -Eo "(\d*\.\d*\.\d*)")
|
|
|
|
fi
|
|
|
|
echo "$pecl_version"
|
2020-01-26 02:34:09 +07:00
|
|
|
}
|
|
|
|
|
2020-07-25 13:57:51 +07:00
|
|
|
# Function to install PECL extensions and accept default options
|
|
|
|
pecl_install() {
|
|
|
|
local extension=$1
|
|
|
|
yes '' | sudo pecl install -f "$extension" >/dev/null 2>&1
|
|
|
|
}
|
|
|
|
|
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-07-14 15:42:50 +07:00
|
|
|
if [[ $pecl_version =~ .*(alpha|beta|rc|snapshot).* ]]; then
|
|
|
|
pecl_version=$(get_pecl_version "$extension" "$pecl_version")
|
|
|
|
fi
|
2020-02-23 20:30:40 +07:00
|
|
|
if ! check_extension "$extension" && [ -e "$ext_dir/$extension.so" ]; then
|
|
|
|
echo "$prefix=$ext_dir/$extension.so" >>"$ini_file"
|
|
|
|
fi
|
|
|
|
ext_version=$(php -r "echo phpversion('$extension');")
|
|
|
|
if [ "$ext_version" = "$pecl_version" ]; then
|
|
|
|
add_log "$tick" "$extension" "Enabled"
|
|
|
|
else
|
2020-05-07 04:57:00 +07:00
|
|
|
remove_extension "$extension" >/dev/null 2>&1
|
2020-02-23 20:30:40 +07:00
|
|
|
(
|
2020-07-25 13:57:51 +07:00
|
|
|
pecl_install "$extension-$pecl_version" &&
|
2020-02-23 20:30:40 +07:00
|
|
|
check_extension "$extension" &&
|
|
|
|
add_log "$tick" "$extension" "Installed and enabled"
|
|
|
|
) || add_log "$cross" "$extension" "Could not install $extension-$pecl_version on PHP $semver"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-06-19 05:39:13 +07:00
|
|
|
# Function to install a php extension from shivammathur/extensions tap.
|
|
|
|
add_brew_extension() {
|
|
|
|
extension=$1
|
|
|
|
if ! brew tap | grep shivammathur/extensions; then
|
|
|
|
brew tap --shallow shivammathur/extensions
|
|
|
|
fi
|
|
|
|
brew install "$extension@$version"
|
|
|
|
sudo cp "$(brew --prefix)/opt/$extension@$version/$extension.so" "$ext_dir"
|
|
|
|
}
|
|
|
|
|
2020-02-23 20:30:40 +07:00
|
|
|
# Function to setup extensions
|
|
|
|
add_extension() {
|
|
|
|
extension=$1
|
|
|
|
install_command=$2
|
|
|
|
prefix=$3
|
|
|
|
if ! check_extension "$extension" && [ -e "$ext_dir/$extension.so" ]; then
|
|
|
|
echo "$prefix=$ext_dir/$extension.so" >>"$ini_file" && add_log "$tick" "$extension" "Enabled"
|
|
|
|
elif check_extension "$extension"; then
|
|
|
|
add_log "$tick" "$extension" "Enabled"
|
|
|
|
elif ! check_extension "$extension"; then
|
2020-03-06 08:46:46 +07:00
|
|
|
eval "$install_command" >/dev/null 2>&1 &&
|
|
|
|
if [[ "$version" =~ $old_versions ]]; then echo "$prefix=$ext_dir/$extension.so" >>"$ini_file"; fi
|
|
|
|
(check_extension "$extension" && add_log "$tick" "$extension" "Installed and enabled") ||
|
|
|
|
add_log "$cross" "$extension" "Could not install $extension on PHP $semver"
|
2020-02-23 20:30:40 +07:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-05-27 17:53:52 +07:00
|
|
|
# Function to setup pre-release extensions using PECL.
|
2020-01-30 13:33:30 +07:00
|
|
|
add_unstable_extension() {
|
2019-12-24 00:49:38 +07:00
|
|
|
extension=$1
|
2020-01-30 13:33:30 +07:00
|
|
|
stability=$2
|
|
|
|
prefix=$3
|
|
|
|
pecl_version=$(get_pecl_version "$extension" "$stability")
|
2020-02-23 20:30:40 +07:00
|
|
|
add_pecl_extension "$extension" "$pecl_version" "$prefix"
|
2019-12-24 00:49:38 +07:00
|
|
|
}
|
|
|
|
|
2020-07-07 18:06:32 +07:00
|
|
|
# Function to configure composer
|
|
|
|
configure_composer() {
|
|
|
|
tool_path=$1
|
|
|
|
sudo ln -sf "$tool_path" "$tool_path.phar"
|
|
|
|
php -r "try {\$p=new Phar('$tool_path.phar', 0);exit(0);} catch(Exception \$e) {exit(1);}"
|
|
|
|
if [ $? -eq 1 ]; then
|
|
|
|
add_log "$cross" "composer" "Could not download composer"
|
|
|
|
exit 1;
|
|
|
|
fi
|
|
|
|
composer -q global config process-timeout 0
|
|
|
|
echo "::add-path::/Users/$USER/.composer/vendor/bin"
|
|
|
|
if [ -n "$COMPOSER_TOKEN" ]; then
|
|
|
|
composer -q global config github-oauth.github.com "$COMPOSER_TOKEN"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-05-27 17:53:52 +07:00
|
|
|
# Function to setup a remote tool.
|
2019-12-27 08:26:49 +07:00
|
|
|
add_tool() {
|
|
|
|
url=$1
|
|
|
|
tool=$2
|
2020-02-23 11:14:33 +07:00
|
|
|
tool_path="$tool_path_dir/$tool"
|
|
|
|
if [ ! -e "$tool_path" ]; then
|
|
|
|
rm -rf "$tool_path"
|
|
|
|
fi
|
2020-02-03 01:21:44 +07:00
|
|
|
|
2020-07-23 07:17:11 +07:00
|
|
|
status_code=$(sudo curl -s -w "%{http_code}" -o "$tool_path" "${curl_opts[@]}" "$url")
|
2020-02-23 11:14:33 +07:00
|
|
|
if [ "$status_code" = "200" ]; then
|
|
|
|
sudo chmod a+x "$tool_path"
|
|
|
|
if [ "$tool" = "composer" ]; then
|
2020-07-07 18:06:32 +07:00
|
|
|
configure_composer "$tool_path"
|
2020-05-21 05:21:28 +07:00
|
|
|
elif [ "$tool" = "phan" ]; then
|
2020-07-25 13:57:51 +07:00
|
|
|
add_extension fileinfo "pecl_install fileinfo" extension >/dev/null 2>&1
|
|
|
|
add_extension ast "pecl_install ast" extension >/dev/null 2>&1
|
2020-02-23 11:14:33 +07:00
|
|
|
elif [ "$tool" = "phive" ]; then
|
2020-07-25 13:57:51 +07:00
|
|
|
add_extension curl "pecl_install curl" extension >/dev/null 2>&1
|
|
|
|
add_extension mbstring "pecl_install mbstring" extension >/dev/null 2>&1
|
|
|
|
add_extension xml "pecl_install xml" extension >/dev/null 2>&1
|
2020-02-23 11:14:33 +07:00
|
|
|
elif [ "$tool" = "cs2pr" ]; then
|
|
|
|
sudo sed -i '' 's/exit(9)/exit(0)/' "$tool_path"
|
|
|
|
tr -d '\r' <"$tool_path" | sudo tee "$tool_path.tmp" >/dev/null 2>&1 && sudo mv "$tool_path.tmp" "$tool_path"
|
2020-02-03 01:21:44 +07:00
|
|
|
sudo chmod a+x "$tool_path"
|
2020-02-23 11:14:33 +07:00
|
|
|
elif [ "$tool" = "wp-cli" ]; then
|
|
|
|
sudo cp -p "$tool_path" "$tool_path_dir"/wp
|
2020-01-07 09:36:14 +07:00
|
|
|
fi
|
2020-02-23 11:14:33 +07:00
|
|
|
add_log "$tick" "$tool" "Added"
|
|
|
|
else
|
|
|
|
add_log "$cross" "$tool" "Could not setup $tool"
|
2019-12-27 08:26:49 +07:00
|
|
|
fi
|
2020-01-07 09:36:14 +07:00
|
|
|
}
|
|
|
|
|
2020-05-27 17:53:52 +07:00
|
|
|
# Function to add a tool using composer.
|
2020-02-28 14:49:12 +07:00
|
|
|
add_composertool() {
|
2020-01-07 09:36:14 +07:00
|
|
|
tool=$1
|
|
|
|
release=$2
|
|
|
|
prefix=$3
|
|
|
|
(
|
2020-01-30 13:33:30 +07:00
|
|
|
composer global require "$prefix$release" >/dev/null 2>&1 &&
|
2020-02-23 20:30:40 +07:00
|
|
|
add_log "$tick" "$tool" "Added"
|
2020-01-07 09:36:14 +07:00
|
|
|
) || add_log "$cross" "$tool" "Could not setup $tool"
|
2019-12-27 08:26:49 +07:00
|
|
|
}
|
|
|
|
|
2020-02-28 14:49:12 +07:00
|
|
|
add_blackfire() {
|
|
|
|
sudo mkdir -p usr/local/var/run
|
2020-06-19 05:39:13 +07:00
|
|
|
brew tap --shallow blackfireio/homebrew-blackfire >/dev/null 2>&1
|
2020-02-28 14:49:12 +07:00
|
|
|
brew install blackfire-agent >/dev/null 2>&1
|
2020-06-02 23:42:46 +07:00
|
|
|
if [[ -n $BLACKFIRE_SERVER_ID ]] && [[ -n $BLACKFIRE_SERVER_TOKEN ]]; then
|
2020-07-15 22:01:29 +07:00
|
|
|
blackfire-agent --register --server-id="$BLACKFIRE_SERVER_ID" --server-token="$BLACKFIRE_SERVER_TOKEN" >/dev/null 2>&1
|
2020-06-02 23:42:46 +07:00
|
|
|
brew services start blackfire-agent >/dev/null 2>&1
|
|
|
|
fi
|
|
|
|
if [[ -n $BLACKFIRE_CLIENT_ID ]] && [[ -n $BLACKFIRE_CLIENT_TOKEN ]]; then
|
2020-07-15 22:01:29 +07:00
|
|
|
blackfire config --client-id="$BLACKFIRE_CLIENT_ID" --client-token="$BLACKFIRE_CLIENT_TOKEN" >/dev/null 2>&1
|
2020-06-02 23:42:46 +07:00
|
|
|
fi
|
2020-03-02 21:09:18 +07:00
|
|
|
add_log "$tick" "blackfire" "Added"
|
|
|
|
add_log "$tick" "blackfire-agent" "Added"
|
2020-02-28 14:49:12 +07:00
|
|
|
}
|
|
|
|
|
2020-01-30 13:33:30 +07:00
|
|
|
# Function to configure PECL
|
|
|
|
configure_pecl() {
|
2020-02-23 11:14:33 +07:00
|
|
|
for tool in pear pecl; do
|
2020-05-27 17:53:52 +07:00
|
|
|
sudo "$tool" config-set php_ini "$ini_file"
|
|
|
|
sudo "$tool" channel-update "$tool".php.net
|
2020-02-23 11:14:33 +07:00
|
|
|
done
|
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() {
|
|
|
|
add_log "$tick" "PECL" "Added"
|
|
|
|
}
|
|
|
|
|
2020-05-27 17:53:52 +07:00
|
|
|
# Function to setup PHP 5.6 and newer.
|
2020-02-21 09:28:19 +07:00
|
|
|
setup_php() {
|
|
|
|
action=$1
|
2020-04-23 17:55:29 +07:00
|
|
|
export HOMEBREW_NO_INSTALL_CLEANUP=TRUE
|
2020-06-19 05:39:13 +07:00
|
|
|
brew tap --shallow shivammathur/homebrew-php
|
2020-05-06 08:23:25 +07:00
|
|
|
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"
|
2020-04-30 18:32:17 +07:00
|
|
|
fi
|
2020-04-23 17:55:29 +07:00
|
|
|
brew link --force --overwrite php@"$version"
|
2020-02-21 09:28:19 +07:00
|
|
|
}
|
|
|
|
|
2019-12-20 19:59:05 +07:00
|
|
|
# Variables
|
|
|
|
tick="✓"
|
|
|
|
cross="✗"
|
|
|
|
version=$1
|
2020-03-06 08:46:46 +07:00
|
|
|
nodot_version=${1/./}
|
2020-02-05 22:28:44 +07:00
|
|
|
old_versions="5.[3-5]"
|
2020-02-26 00:30:30 +07:00
|
|
|
tool_path_dir="/usr/local/bin"
|
2020-07-23 07:17:11 +07:00
|
|
|
curl_opts=(-sSL --retry 5 --retry-delay 1)
|
2020-04-03 15:10:11 +07:00
|
|
|
existing_version=$(php-config --version 2>/dev/null | cut -c 1-3)
|
2020-05-06 08:23:25 +07:00
|
|
|
|
2020-05-27 17:53:52 +07:00
|
|
|
read_env
|
2020-05-06 08:23:25 +07:00
|
|
|
if [ "$runner" = "self-hosted" ]; then
|
2020-06-07 04:11:28 +07:00
|
|
|
if [[ "$version" =~ $old_versions ]]; then
|
|
|
|
add_log "$cross" "PHP" "PHP $version is not supported on self-hosted runner"
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
self_hosted_setup >/dev/null 2>&1
|
|
|
|
fi
|
2020-05-06 08:23:25 +07:00
|
|
|
fi
|
2020-02-05 22:28:44 +07:00
|
|
|
|
2020-02-14 17:59:43 +07:00
|
|
|
# Setup PHP
|
2020-02-23 11:14:33 +07:00
|
|
|
step_log "Setup PHP"
|
2020-02-05 22:28:44 +07:00
|
|
|
if [[ "$version" =~ $old_versions ]]; then
|
2020-07-23 07:17:11 +07:00
|
|
|
curl "${curl_opts[@]}" https://github.com/shivammathur/php5-darwin/releases/latest/download/install.sh | bash -s "$nodot_version" >/dev/null 2>&1 &&
|
2020-02-14 17:59:43 +07:00
|
|
|
status="Installed"
|
2020-02-21 09:28:19 +07:00
|
|
|
elif [ "$existing_version" != "$version" ]; then
|
2020-04-23 17:55:29 +07:00
|
|
|
setup_php "install" >/dev/null 2>&1
|
2020-02-21 09:28:19 +07:00
|
|
|
status="Installed"
|
|
|
|
elif [ "$existing_version" = "$version" ] && [ "$update" = "true" ]; then
|
2020-04-23 17:55:29 +07:00
|
|
|
setup_php "upgrade" >/dev/null 2>&1
|
2020-02-21 09:28:19 +07:00
|
|
|
status="Updated to"
|
2020-02-14 17:59:43 +07:00
|
|
|
else
|
|
|
|
status="Found"
|
2020-02-05 22:28:44 +07:00
|
|
|
fi
|
2019-12-20 19:59:05 +07:00
|
|
|
ini_file=$(php -d "date.timezone=UTC" --ini | grep "Loaded Configuration" | sed -e "s|.*:s*||" | sed "s/ //g")
|
2020-02-26 00:30:30 +07:00
|
|
|
sudo chmod 777 "$ini_file" "$tool_path_dir"
|
2020-07-18 07:23:26 +07:00
|
|
|
echo -e "date.timezone=UTC\nmemory_limit=-1" >>"$ini_file"
|
2020-03-06 08:46:46 +07:00
|
|
|
ext_dir=$(php -i | grep -Ei "extension_dir => /" | sed -e "s|.*=> s*||")
|
2020-02-23 20:30:40 +07:00
|
|
|
scan_dir=$(php --ini | grep additional | sed -e "s|.*: s*||")
|
2020-02-05 22:28:44 +07:00
|
|
|
sudo mkdir -p "$ext_dir"
|
2019-12-20 19:59:05 +07:00
|
|
|
semver=$(php -v | head -n 1 | cut -f 2 -d ' ')
|
2020-05-27 17:53:52 +07:00
|
|
|
if [[ ! "$version" =~ $old_versions ]]; then configure_pecl >/dev/null 2>&1; fi
|
2020-02-23 11:14:33 +07:00
|
|
|
add_log "$tick" "PHP" "$status PHP $semver"
|