From 9d77946f60b82e31f8d10d643567ac42b7347924 Mon Sep 17 00:00:00 2001 From: Shivam Mathur Date: Sun, 23 Feb 2020 09:44:33 +0530 Subject: [PATCH] Switch to liip for old PHP on darwin --- dist/index.js | 2 +- src/extensions.ts | 2 +- src/scripts/darwin.sh | 145 +++++++++++++++++------------------------- 3 files changed, 59 insertions(+), 90 deletions(-) diff --git a/dist/index.js b/dist/index.js index 3bdb6394..6c3415b2 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2748,7 +2748,7 @@ function addExtensionDarwin(extension_csv, version, pipe) { } script += '\nadd_extension ' + - extension + + ext_name + ' "' + install_command + '" ' + diff --git a/src/extensions.ts b/src/extensions.ts index 62f68d13..55307c6d 100644 --- a/src/extensions.ts +++ b/src/extensions.ts @@ -69,7 +69,7 @@ export async function addExtensionDarwin( } script += '\nadd_extension ' + - extension + + ext_name + ' "' + install_command + '" ' + diff --git a/src/scripts/darwin.sh b/src/scripts/darwin.sh index 76c84422..6e00341f 100644 --- a/src/scripts/darwin.sh +++ b/src/scripts/darwin.sh @@ -33,14 +33,8 @@ add_extension() { elif php -m | grep -i -q -w "$extension"; then add_log "$tick" "$extension" "Enabled" elif ! php -m | grep -i -q -w "$extension"; then - if [[ "$version" =~ $old_versions ]]; then - (sudo port install php"$nodot_version"-"$extension" >/dev/null 2>&1 && add_log "$tick" "$extension" "Installed and enabled") || - (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 + (eval "$install_command" >/dev/null 2>&1 && test -f "$ext_dir/$extension.so" && add_log "$tick" "$extension" "Installed and enabled") || + add_log "$cross" "$extension" "Could not install $extension on PHP $semver" fi } @@ -88,35 +82,31 @@ add_unstable_extension() { add_tool() { url=$1 tool=$2 - if [ "$tool" = "composer" ]; then - brew install composer >/dev/null 2>&1 - composer -q global config process-timeout 0 + tool_path_dir=/usr/local/bin + 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" = "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" else - tool_path_dir=/usr/local/bin - 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 + add_log "$cross" "$tool" "Could not setup $tool" fi } @@ -127,20 +117,18 @@ add_composer_tool() { prefix=$3 ( composer global require "$prefix$release" >/dev/null 2>&1 && - sudo ln -sf "$(composer -q global config home)"/vendor/bin/"$tool" /usr/local/bin/"$tool" && - add_log "$tick" "$tool" "Added" + sudo ln -sf "$(composer -q global config home)"/vendor/bin/"$tool" /usr/local/bin/"$tool" && + add_log "$tick" "$tool" "Added" ) || add_log "$cross" "$tool" "Could not setup $tool" } # Function to configure PECL configure_pecl() { - if [[ ! "$version" =~ $old_versions ]]; then - for tool in pear pecl; do - 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" channel-update "$tool".php.net >/dev/null 2>&1 - done - fi + for tool in pear pecl; do + 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" channel-update "$tool".php.net >/dev/null 2>&1 + done } # Function to log PECL, it is installed along with PHP @@ -148,44 +136,33 @@ add_pecl() { add_log "$tick" "PECL" "Added" } -# Function to add PECL when macports is used -add_pecl_old() { - pecl_version='master' - if [ "$1" = "53" ]; then - pecl_version='v1.9.5' - fi - curl -o pear.phar -sSL https://github.com/pear/pearweb_phars/raw/$pecl_version/install-pear-nozlib.phar - sudo php pear.phar -d /opt/local/lib/php$1 -b /usr/local/bin && rm -rf pear.phar +# Function to get api version for PHP 5.3, 5.4 and 5.5 +get_old_apiv() { + case $version in + 5.3) echo "20090626" ;; + 5.4) echo "20100525" ;; + 5.5) echo "20121212" ;; + esac } -add_macports() { - uri=$(curl -sSL https://github.com/macports/macports-base/releases | grep -Eo "(\/.*Catalina.pkg)" | head -n 1) - curl -o port.pkg -sSL https://github.com"$uri" - sudo installer -pkg port.pkg -target / && rm -rf port.pkg -} - -sync_macports() { - while true; do - status=0 - sudo port sync || status=$? - if [[ "$status" -eq 0 ]]; then - break - fi - sleep 2 +# Function to setup PHP 5.3, 5.4 and 5.5 +setup_php_old() { + php5=/usr/local/php5 + 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" + sudo mv "$ext_dir" /tmp >/dev/null 2>&1 && sudo rm -rf "$php5" + sudo curl -s https://php-osx.liip.ch/install.sh | bash -s "$version" >/dev/null 2>&1 + sudo rsync -a /tmp/"$ext_dir_name"/ "$ext_dir" >/dev/null 2>&1 + sudo rm -rf "$php5"/php.d/*developer.ini "$php5"/php.d/*xdebug.ini /tmp/ext + for tool in pear peardev pecl php php-config phpize; do + sudo ln -sf "$php5"/bin/"$tool" /usr/local/bin/"$tool" done } -port_setup_php() { - 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" -} - +# Function to setup PHP >=5.6 setup_php() { action=$1 - step_log "Setup PHP" export HOMEBREW_NO_INSTALL_CLEANUP=TRUE >/dev/null 2>&1 brew tap shivammathur/homebrew-php >/dev/null 2>&1 brew "$action" shivammathur/php/php@"$version" >/dev/null 2>&1 @@ -196,22 +173,14 @@ setup_php() { tick="✓" cross="✗" version=$1 -nodot_version=${1/./} old_versions="5.[3-5]" existing_version=$(php-config --version | cut -c 1-3) [[ -z "${update}" ]] && update='false' || update="${update}" # Setup PHP +step_log "Setup PHP" if [[ "$version" =~ $old_versions ]]; then - export PATH="/opt/local/bin:/opt/local/sbin:$PATH" - 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 + setup_php_old status="Installed" elif [ "$existing_version" != "$version" ]; then setup_php "install" @@ -220,14 +189,14 @@ elif [ "$existing_version" = "$version" ] && [ "$update" = "true" ]; then setup_php "upgrade" status="Updated to" else - step_log "Setup PHP" 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" 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" semver=$(php -v | head -n 1 | cut -f 2 -d ' ') configure_pecl -add_log "$tick" "PHP" "$status PHP $semver" \ No newline at end of file +add_log "$tick" "PHP" "$status PHP $semver"