From 7e03c76ef2aa9cc1deb5b9c2395e7f0be6bd3160 Mon Sep 17 00:00:00 2001 From: Shivam Mathur Date: Fri, 29 Jul 2022 02:39:20 +0530 Subject: [PATCH] Fix extension setup using PECL on Linux and macOS --- src/scripts/extensions/add_extensions.sh | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/scripts/extensions/add_extensions.sh b/src/scripts/extensions/add_extensions.sh index 1507e66ff..6c36e05e2 100644 --- a/src/scripts/extensions/add_extensions.sh +++ b/src/scripts/extensions/add_extensions.sh @@ -144,14 +144,18 @@ add_extension() { # Function to get the PECL version of an extension. get_pecl_version() { local extension=$1 - stability="$(echo "$2" | grep -m 1 -Eio "(stable|alpha|beta|rc|snapshot|preview)")" + states=("stable" "rc" "preview" "beta" "alpha" "snapshot") + stability="$(echo "$2" | grep -m 1 -Eio "($(IFS='|' ; echo "${states[*]}"))")" + IFS=' ' read -r -a states <<< "$(echo "${states[@]}" | grep -Eo "$stability.*")" major_version=${3:-'[0-9]+'} pecl_rest='https://pecl.php.net/rest/r/' response=$(get -s -n "" "$pecl_rest$extension"/allreleases.xml) - pecl_version=$(echo "$response" | grep -m 1 -Eio "($major_version\.[0-9]+\.[0-9]+${stability}[0-9]+<)" | cut -d '<' -f 1) - if [ ! "$pecl_version" ]; then - pecl_version=$(echo "$response" | grep -m 1 -Eo "($major_version\.[0-9]+\.[0-9]+)<" | cut -d '<' -f 1) - fi + for state in "${states[@]}"; do + pecl_version=$(echo "$response" | grep -m 1 -Eio "($major_version\.[0-9]+\.[0-9]+${state}[0-9]+<)" | cut -d '<' -f 1) + [ -z "$pecl_version" ] && pecl_version=$(echo "$response" | grep -m 1 -Eio "v>(.*)<\/v>.*$state<" | grep -m 1 -Eo "($major_version\.[0-9]+\.[0-9]+.*)<" | cut -d '<' -f 1) + [ -n "$pecl_version" ] && break; + done + [ -z "$pecl_version" ] && pecl_version=$(echo "$response" | grep -m 1 -Eo "($major_version\.[0-9]+\.[0-9]+)<" | cut -d '<' -f 1) echo "$pecl_version" } @@ -185,8 +189,9 @@ add_pecl_extension() { add_log "${tick:?}" "$extension" "Enabled" else disable_extension_helper "$extension" >/dev/null 2>&1 - pecl_install "$extension-$pecl_version" - add_extension_log "$extension-$pecl_version" "Installed and enabled" + [ -n "$pecl_version" ] && pecl_version="-$pecl_version" + pecl_install "$extension$pecl_version" || add_extension "$extension" "$(get_extension_prefix "$extension")" + add_extension_log "$extension-$(php -r "echo phpversion('$extension');")" "Installed and enabled" fi } @@ -198,3 +203,8 @@ add_unstable_extension() { pecl_version=$(get_pecl_version "$extension" "$stability") add_pecl_extension "$extension" "$pecl_version" "$prefix" } + +# Function to get extension prefix +get_extension_prefix() { + echo "$1" | grep -Eq "xdebug([2-3])?$|opcache|ioncube|eaccelerator" && echo zend_extension || echo extension +}