Switch to liip for old PHP on darwin

This commit is contained in:
Shivam Mathur 2020-02-23 09:44:33 +05:30
parent 6d21e6dc05
commit 9d77946f60
No known key found for this signature in database
GPG Key ID: 3E13E4C8591ACC2A
3 changed files with 59 additions and 90 deletions

2
dist/index.js vendored
View File

@ -2748,7 +2748,7 @@ function addExtensionDarwin(extension_csv, version, pipe) {
} }
script += script +=
'\nadd_extension ' + '\nadd_extension ' +
extension + ext_name +
' "' + ' "' +
install_command + install_command +
'" ' + '" ' +

View File

@ -69,7 +69,7 @@ export async function addExtensionDarwin(
} }
script += script +=
'\nadd_extension ' + '\nadd_extension ' +
extension + ext_name +
' "' + ' "' +
install_command + install_command +
'" ' + '" ' +

View File

@ -33,14 +33,8 @@ add_extension() {
elif php -m | grep -i -q -w "$extension"; then elif php -m | grep -i -q -w "$extension"; then
add_log "$tick" "$extension" "Enabled" add_log "$tick" "$extension" "Enabled"
elif ! php -m | grep -i -q -w "$extension"; then elif ! php -m | grep -i -q -w "$extension"; then
if [[ "$version" =~ $old_versions ]]; then (eval "$install_command" >/dev/null 2>&1 && test -f "$ext_dir/$extension.so" && add_log "$tick" "$extension" "Installed and enabled") ||
(sudo port install php"$nodot_version"-"$extension" >/dev/null 2>&1 && add_log "$tick" "$extension" "Installed and enabled") || add_log "$cross" "$extension" "Could not install $extension on PHP $semver"
(eval "$install_command" >/dev/null 2>&1 && echo "$prefix=$ext_dir/$extension.so" >>"$ini_file" && add_log "$tick" "$extension" "Installed and enabled") ||
add_log "$cross" "$extension" "Could not install $extension on PHP $semver"
else
(eval "$install_command" >/dev/null 2>&1 && add_log "$tick" "$extension" "Installed and enabled") ||
add_log "$cross" "$extension" "Could not install $extension on PHP $semver"
fi
fi fi
} }
@ -88,35 +82,31 @@ add_unstable_extension() {
add_tool() { add_tool() {
url=$1 url=$1
tool=$2 tool=$2
if [ "$tool" = "composer" ]; then tool_path_dir=/usr/local/bin
brew install composer >/dev/null 2>&1 tool_path="$tool_path_dir/$tool"
composer -q global config process-timeout 0 if [ ! -e "$tool_path" ]; then
rm -rf "$tool_path"
fi
status_code=$(sudo curl -s -w "%{http_code}" -o "$tool_path" -L "$url")
if [ "$status_code" = "200" ]; then
sudo chmod a+x "$tool_path"
if [ "$tool" = "composer" ]; then
composer -q global config process-timeout 0
elif [ "$tool" = "phive" ]; then
add_extension curl "sudo pecl install -f curl" extension >/dev/null 2>&1
add_extension mbstring "sudo pecl install -f mbstring" extension >/dev/null 2>&1
add_extension xml "sudo pecl install -f xml" extension >/dev/null 2>&1
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"
sudo chmod a+x "$tool_path"
elif [ "$tool" = "wp-cli" ]; then
sudo cp -p "$tool_path" "$tool_path_dir"/wp
fi
add_log "$tick" "$tool" "Added" add_log "$tick" "$tool" "Added"
else else
tool_path_dir=/usr/local/bin add_log "$cross" "$tool" "Could not setup $tool"
tool_path="$tool_path_dir/$tool"
if [ ! -e "$tool_path" ]; then
rm -rf "$tool_path"
fi
status_code=$(sudo curl -s -w "%{http_code}" -o "$tool_path" -L "$url")
if [ "$status_code" = "200" ]; then
sudo chmod a+x "$tool_path"
if [ "$tool" = "phive" ]; then
add_extension curl "sudo pecl install -f curl" extension >/dev/null 2>&1
add_extension mbstring "sudo pecl install -f mbstring" extension >/dev/null 2>&1
add_extension xml "sudo pecl install -f xml" extension >/dev/null 2>&1
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"
sudo chmod a+x "$tool_path"
elif [ "$tool" = "wp-cli" ]; then
sudo cp -p "$tool_path" "$tool_path_dir"/wp
fi
add_log "$tick" "$tool" "Added"
else
add_log "$cross" "$tool" "Could not setup $tool"
fi
fi fi
} }
@ -127,20 +117,18 @@ add_composer_tool() {
prefix=$3 prefix=$3
( (
composer global require "$prefix$release" >/dev/null 2>&1 && composer global require "$prefix$release" >/dev/null 2>&1 &&
sudo ln -sf "$(composer -q global config home)"/vendor/bin/"$tool" /usr/local/bin/"$tool" && sudo ln -sf "$(composer -q global config home)"/vendor/bin/"$tool" /usr/local/bin/"$tool" &&
add_log "$tick" "$tool" "Added" add_log "$tick" "$tool" "Added"
) || add_log "$cross" "$tool" "Could not setup $tool" ) || add_log "$cross" "$tool" "Could not setup $tool"
} }
# Function to configure PECL # Function to configure PECL
configure_pecl() { configure_pecl() {
if [[ ! "$version" =~ $old_versions ]]; then for tool in pear pecl; do
for tool in pear pecl; do sudo "$tool" config-set php_ini "$ini_file" >/dev/null 2>&1
sudo "$tool" config-set php_ini "$ini_file" >/dev/null 2>&1 sudo "$tool" config-set auto_discover 1 >/dev/null 2>&1
sudo "$tool" config-set auto_discover 1 >/dev/null 2>&1 sudo "$tool" channel-update "$tool".php.net >/dev/null 2>&1
sudo "$tool" channel-update "$tool".php.net >/dev/null 2>&1 done
done
fi
} }
# Function to log PECL, it is installed along with PHP # Function to log PECL, it is installed along with PHP
@ -148,44 +136,33 @@ add_pecl() {
add_log "$tick" "PECL" "Added" add_log "$tick" "PECL" "Added"
} }
# Function to add PECL when macports is used # Function to get api version for PHP 5.3, 5.4 and 5.5
add_pecl_old() { get_old_apiv() {
pecl_version='master' case $version in
if [ "$1" = "53" ]; then 5.3) echo "20090626" ;;
pecl_version='v1.9.5' 5.4) echo "20100525" ;;
fi 5.5) echo "20121212" ;;
curl -o pear.phar -sSL https://github.com/pear/pearweb_phars/raw/$pecl_version/install-pear-nozlib.phar esac
sudo php pear.phar -d /opt/local/lib/php$1 -b /usr/local/bin && rm -rf pear.phar
} }
add_macports() { # Function to setup PHP 5.3, 5.4 and 5.5
uri=$(curl -sSL https://github.com/macports/macports-base/releases | grep -Eo "(\/.*Catalina.pkg)" | head -n 1) setup_php_old() {
curl -o port.pkg -sSL https://github.com"$uri" php5=/usr/local/php5
sudo installer -pkg port.pkg -target / && rm -rf port.pkg ext_dir_parent="$php5"/lib/php/extensions
} ext_dir_name=no-debug-non-zts-$(get_old_apiv)
ext_dir="$ext_dir_parent/$ext_dir_name"
sync_macports() { sudo mv "$ext_dir" /tmp >/dev/null 2>&1 && sudo rm -rf "$php5"
while true; do sudo curl -s https://php-osx.liip.ch/install.sh | bash -s "$version" >/dev/null 2>&1
status=0 sudo rsync -a /tmp/"$ext_dir_name"/ "$ext_dir" >/dev/null 2>&1
sudo port sync || status=$? sudo rm -rf "$php5"/php.d/*developer.ini "$php5"/php.d/*xdebug.ini /tmp/ext
if [[ "$status" -eq 0 ]]; then for tool in pear peardev pecl php php-config phpize; do
break sudo ln -sf "$php5"/bin/"$tool" /usr/local/bin/"$tool"
fi
sleep 2
done done
} }
port_setup_php() { # Function to setup PHP >=5.6
sudo port install php$1 php$1-curl php$1-mbstring php$1-xmlrpc php$1-openssl php$1-opcache
sudo cp /opt/local/etc/php$1/php.ini-development /opt/local/etc/php$1/php.ini
sudo port select --set php php$1
sudo ln -sf /opt/local/bin/* /usr/local/bin
add_pecl_old "$1"
}
setup_php() { setup_php() {
action=$1 action=$1
step_log "Setup PHP"
export HOMEBREW_NO_INSTALL_CLEANUP=TRUE >/dev/null 2>&1 export HOMEBREW_NO_INSTALL_CLEANUP=TRUE >/dev/null 2>&1
brew tap shivammathur/homebrew-php >/dev/null 2>&1 brew tap shivammathur/homebrew-php >/dev/null 2>&1
brew "$action" shivammathur/php/php@"$version" >/dev/null 2>&1 brew "$action" shivammathur/php/php@"$version" >/dev/null 2>&1
@ -196,22 +173,14 @@ setup_php() {
tick="✓" tick="✓"
cross="✗" cross="✗"
version=$1 version=$1
nodot_version=${1/./}
old_versions="5.[3-5]" old_versions="5.[3-5]"
existing_version=$(php-config --version | cut -c 1-3) existing_version=$(php-config --version | cut -c 1-3)
[[ -z "${update}" ]] && update='false' || update="${update}" [[ -z "${update}" ]] && update='false' || update="${update}"
# Setup PHP # Setup PHP
step_log "Setup PHP"
if [[ "$version" =~ $old_versions ]]; then if [[ "$version" =~ $old_versions ]]; then
export PATH="/opt/local/bin:/opt/local/sbin:$PATH" setup_php_old
export TERM=xterm
step_log "Setup Macports"
add_macports >/dev/null 2>&1
add_log "$tick" "Macports" "Installed"
sync_macports >/dev/null 2>&1
add_log "$tick" "Macports" "Synced"
step_log "Setup PHP"
port_setup_php $nodot_version >/dev/null 2>&1
status="Installed" status="Installed"
elif [ "$existing_version" != "$version" ]; then elif [ "$existing_version" != "$version" ]; then
setup_php "install" setup_php "install"
@ -220,13 +189,13 @@ elif [ "$existing_version" = "$version" ] && [ "$update" = "true" ]; then
setup_php "upgrade" setup_php "upgrade"
status="Updated to" status="Updated to"
else else
step_log "Setup PHP"
status="Found" status="Found"
fi fi
ini_file=$(php -d "date.timezone=UTC" --ini | grep "Loaded Configuration" | sed -e "s|.*:s*||" | sed "s/ //g") ini_file=$(php -d "date.timezone=UTC" --ini | grep "Loaded Configuration" | sed -e "s|.*:s*||" | sed "s/ //g")
sudo chmod 777 "$ini_file" sudo chmod 777 "$ini_file"
echo "date.timezone=UTC" >>"$ini_file" echo "date.timezone=UTC" >>"$ini_file"
ext_dir=$(php -i | grep -Ei "extension_dir => /(usr|opt)" | sed -e "s|.*=> s*||") echo "detect_unicode=Off" >>"$ini_file"
ext_dir=$(php -i | grep -Ei "extension_dir => /usr" | sed -e "s|.*=> s*||")
sudo mkdir -p "$ext_dir" sudo mkdir -p "$ext_dir"
semver=$(php -v | head -n 1 | cut -f 2 -d ' ') semver=$(php -v | head -n 1 | cut -f 2 -d ' ')
configure_pecl configure_pecl