Skip to content

Commit

Permalink
Fix extension setup using PECL on Linux and macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
shivammathur committed Jul 28, 2022
1 parent 16011a7 commit 7e03c76
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/scripts/extensions/add_extensions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand Down Expand Up @@ -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
}

Expand All @@ -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
}

0 comments on commit 7e03c76

Please sign in to comment.