-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathinstall-extensions.sh
executable file
·85 lines (70 loc) · 1.96 KB
/
install-extensions.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env bash
set -xeu
: "${TIDEWAYS_VERSION:=4.1.4}"
: "${TIDEWAYS_XHPROF_VERSION:=5.0.4}"
: "${PHP_VERSION:=7.4}"
die() {
echo >&2 "ERROR: $*"
exit 1
}
has_extension() {
local extension="$1"
php -m | awk -vrc=1 -vextension="$extension" '$1 == extension { rc=0 } END { exit rc }'
}
install_xhprof() {
local ext="xhprof" version="${1:-stable}"
has_extension "$ext" && return 0
# https://github.com/shivammathur/setup-php/issues/905
sudo rm -rf /tmp/pear # shivammathur's leftovers...
# Allow installing to /usr/local/php
sudo chown -R "$(id -un):" /usr/local/php/
pecl install "$ext-$version"
}
install_mongo() {
local ext="mongo" version="${1:-stable}"
has_extension "$ext" && return 0
echo no | pecl install "$ext-$version"
}
install_mongodb() {
has_extension "mongodb" || pecl install -f mongodb
composer require --dev alcaeus/mongo-php-adapter
}
install_tideways_xhprof() {
local version=$TIDEWAYS_XHPROF_VERSION
local arch=$(uname -m)
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 workdir="vendor/tideways_xhprof"
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
test -f "$library" || die "Extension not available: $library"
config="/etc/php/$PHP_VERSION/cli/conf.d/10-tideways_xhprof.ini"
echo "extension=$library" | sudo tee "$config"
has_extension "$extension"
}
pecl version
php -m
case "$(uname -s):$PHP_VERSION" in
*:5.*)
install_xhprof 0.9.4
install_mongo 1.6.16
;;
Linux:7.*|Linux:8.*)
install_xhprof
install_mongodb
install_tideways_xhprof
;;
*:7.*|*:8.*)
install_xhprof
install_mongodb
;;
esac