From e31078917be635fb0765b56855a21a0ce0004094 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Wed, 1 Jun 2022 01:10:55 +0300 Subject: [PATCH 01/12] Add has_extension helper --- install-extensions.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/install-extensions.sh b/install-extensions.sh index 1112a58..630f38a 100755 --- a/install-extensions.sh +++ b/install-extensions.sh @@ -11,6 +11,11 @@ die() { exit 1 } +has_extension() { + local extension="$1" + php -m | awk -vrc=1 -vextension="$extension" '$1 == extension { rc=0 } END { exit rc }' +} + install_xhprof() { local version="${1:-stable}" From 8c34c30ae6ebfe721526e8d0b9f0bc77d2f9ea15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Wed, 1 Jun 2022 01:12:36 +0300 Subject: [PATCH 02/12] Skip xhprof install if present --- install-extensions.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/install-extensions.sh b/install-extensions.sh index 630f38a..a92c681 100755 --- a/install-extensions.sh +++ b/install-extensions.sh @@ -19,6 +19,7 @@ has_extension() { install_xhprof() { local version="${1:-stable}" + has_extension "xhprof" && return 0 pecl install xhprof-$version } From 5f2fa668cdf145e4b682f7f96a61906a1441b8c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Wed, 1 Jun 2022 01:18:51 +0300 Subject: [PATCH 03/12] Use has_extension check for mongodb --- install-extensions.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install-extensions.sh b/install-extensions.sh index a92c681..f71bbb1 100755 --- a/install-extensions.sh +++ b/install-extensions.sh @@ -28,7 +28,7 @@ install_mongo() { } install_mongodb() { - php -m | grep -q mongodb || pecl install -f mongodb + has_extension "mongodb" || pecl install -f mongodb composer require --dev alcaeus/mongo-php-adapter } From 14737ebbf25e289de467d114eb9f2fb986190cd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Wed, 1 Jun 2022 13:27:02 +0300 Subject: [PATCH 04/12] Use has_extension --- install-extensions.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install-extensions.sh b/install-extensions.sh index f71bbb1..87fcb9d 100755 --- a/install-extensions.sh +++ b/install-extensions.sh @@ -49,7 +49,7 @@ install_tideways_xhprof() { config="$HOME/.phpenv/versions/$PHP_VERSION/etc/conf.d/tideways_xhprof.ini" test -f "$library" || die "Extension not available: $library" echo "extension=$library" > "$config" - php -m | grep -F "$extension" + has_extension "$extension" } case "$(uname -s):$PHP_VERSION" in From 8e467465ed0d07aee46bbf84e6cd218f94a4e007 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Wed, 1 Jun 2022 01:24:35 +0300 Subject: [PATCH 05/12] Show php config paths --- install-extensions.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/install-extensions.sh b/install-extensions.sh index 87fcb9d..fcb07f0 100755 --- a/install-extensions.sh +++ b/install-extensions.sh @@ -52,6 +52,9 @@ install_tideways_xhprof() { has_extension "$extension" } +# Show php config paths +php --ini + case "$(uname -s):$PHP_VERSION" in *:5.*) install_xhprof 0.9.4 From f6f68d08ca10ca3896199f8eaf1182a9fa826bae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Wed, 1 Jun 2022 02:01:25 +0300 Subject: [PATCH 06/12] Use path specific to GHA --- install-extensions.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install-extensions.sh b/install-extensions.sh index fcb07f0..398cc90 100755 --- a/install-extensions.sh +++ b/install-extensions.sh @@ -46,7 +46,7 @@ install_tideways_xhprof() { zts=$(php --version | grep -q ZTS && echo -zts || :) library="$PWD/tideways_xhprof-$version/tideways_xhprof-$PHP_VERSION$zts.so" - config="$HOME/.phpenv/versions/$PHP_VERSION/etc/conf.d/tideways_xhprof.ini" + config="/etc/php/$PHP_VERSION/cli/conf.d/10-tideways_xhprof.ini" test -f "$library" || die "Extension not available: $library" echo "extension=$library" > "$config" has_extension "$extension" From a2382e85fed83e586bd87cdaede8450a24a18677 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Wed, 1 Jun 2022 02:50:28 +0300 Subject: [PATCH 07/12] Unpack tideways_xhprof to vendor for cache --- install-extensions.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/install-extensions.sh b/install-extensions.sh index 398cc90..bd70270 100755 --- a/install-extensions.sh +++ b/install-extensions.sh @@ -42,10 +42,10 @@ install_tideways_xhprof() { local zts curl -fL -o "$tar" "$url" - tar -xvf "$tar" + tar -xvf "$tar" -C vendor/tideways_xhprof zts=$(php --version | grep -q ZTS && echo -zts || :) - library="$PWD/tideways_xhprof-$version/tideways_xhprof-$PHP_VERSION$zts.so" + library="$PWD/vendor/tideways_xhprof/tideways_xhprof-$version/tideways_xhprof-$PHP_VERSION$zts.so" config="/etc/php/$PHP_VERSION/cli/conf.d/10-tideways_xhprof.ini" test -f "$library" || die "Extension not available: $library" echo "extension=$library" > "$config" From 8befb8e6cf1b977e623911bc53a2d4c2308f63b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Wed, 1 Jun 2022 07:37:39 +0300 Subject: [PATCH 08/12] Optimize for cache --- install-extensions.sh | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/install-extensions.sh b/install-extensions.sh index bd70270..08f4aff 100755 --- a/install-extensions.sh +++ b/install-extensions.sh @@ -38,16 +38,20 @@ install_tideways_xhprof() { local url="https://github.com/tideways/php-xhprof-extension/releases/download/v$version/tideways-xhprof-$version-$arch.tar.gz" local extension="tideways_xhprof" local tar="$extension.tgz" - local config library + local workdir="vendor/tideways_xhprof" + local library="$PWD/$workdir/tideways_xhprof-$version/tideways_xhprof-$PHP_VERSION$zts.so" + local config local zts - curl -fL -o "$tar" "$url" - tar -xvf "$tar" -C vendor/tideways_xhprof + if [ ! -f "$library" ]; then + curl -fL -o "$tar" "$url" + mkdir -p "$workdir" + tar -xvf "$tar" -C "$workdir" + fi zts=$(php --version | grep -q ZTS && echo -zts || :) - library="$PWD/vendor/tideways_xhprof/tideways_xhprof-$version/tideways_xhprof-$PHP_VERSION$zts.so" - config="/etc/php/$PHP_VERSION/cli/conf.d/10-tideways_xhprof.ini" test -f "$library" || die "Extension not available: $library" + config="/etc/php/$PHP_VERSION/cli/conf.d/10-tideways_xhprof.ini" echo "extension=$library" > "$config" has_extension "$extension" } From 73099fc79b740e0fd624602689feb1b40ba3a323 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Wed, 1 Jun 2022 07:38:10 +0300 Subject: [PATCH 09/12] Update to 5.0.4 --- install-extensions.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/install-extensions.sh b/install-extensions.sh index 08f4aff..b04f641 100755 --- a/install-extensions.sh +++ b/install-extensions.sh @@ -3,7 +3,7 @@ set -xeu : "${TIDEWAYS_VERSION:=4.1.4}" -: "${TIDEWAYS_XHPROF_VERSION:=5.0.2}" +: "${TIDEWAYS_XHPROF_VERSION:=5.0.4}" : "${PHP_VERSION:=7.4}" die() { @@ -39,17 +39,19 @@ install_tideways_xhprof() { local extension="tideways_xhprof" local tar="$extension.tgz" local workdir="vendor/tideways_xhprof" - local library="$PWD/$workdir/tideways_xhprof-$version/tideways_xhprof-$PHP_VERSION$zts.so" + local library local config local zts + zts=$(php --version | grep -q ZTS && echo -zts || :) + library="$PWD/$workdir/tideways_xhprof-$version/tideways_xhprof-$PHP_VERSION$zts.so" + if [ ! -f "$library" ]; then curl -fL -o "$tar" "$url" mkdir -p "$workdir" tar -xvf "$tar" -C "$workdir" fi - zts=$(php --version | grep -q ZTS && echo -zts || :) test -f "$library" || die "Extension not available: $library" config="/etc/php/$PHP_VERSION/cli/conf.d/10-tideways_xhprof.ini" echo "extension=$library" > "$config" @@ -64,7 +66,7 @@ case "$(uname -s):$PHP_VERSION" in install_xhprof 0.9.4 install_mongo ;; -Linux:7.*) +Linux:7.*|Linux:8.*) install_xhprof install_mongodb install_tideways_xhprof From 40936c77e2076d4b3228619700956ed3a53f70a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Wed, 1 Jun 2022 07:45:53 +0300 Subject: [PATCH 10/12] Allow php 8.x --- install-extensions.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install-extensions.sh b/install-extensions.sh index b04f641..418ce0c 100755 --- a/install-extensions.sh +++ b/install-extensions.sh @@ -71,7 +71,7 @@ Linux:7.*|Linux:8.*) install_mongodb install_tideways_xhprof ;; -*:7.*) +*:7.*|*:8.*) install_xhprof install_mongodb ;; From ef0b3f6f5d18de512a24fc157e4cb06690d0786e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Wed, 1 Jun 2022 10:25:46 +0300 Subject: [PATCH 11/12] Switch to bash --- install-extensions.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install-extensions.sh b/install-extensions.sh index 418ce0c..a4cd673 100755 --- a/install-extensions.sh +++ b/install-extensions.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/usr/bin/env bash set -xeu From 1c90bc0020538fe8db247c956841d8ef87c3a2dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Wed, 1 Jun 2022 13:34:29 +0300 Subject: [PATCH 12/12] Use sudo for specific command only --- install-extensions.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install-extensions.sh b/install-extensions.sh index a4cd673..9094699 100755 --- a/install-extensions.sh +++ b/install-extensions.sh @@ -54,7 +54,7 @@ install_tideways_xhprof() { test -f "$library" || die "Extension not available: $library" config="/etc/php/$PHP_VERSION/cli/conf.d/10-tideways_xhprof.ini" - echo "extension=$library" > "$config" + echo "extension=$library" | sudo tee "$config" has_extension "$extension" }