2016-03-18 18:51:01 +01:00
|
|
|
#!/bin/sh
|
2015-08-05 00:16:53 +02:00
|
|
|
set -e
|
|
|
|
|
2018-04-19 21:51:31 +02:00
|
|
|
extDir="$(php -r 'echo ini_get("extension_dir");')"
|
|
|
|
cd "$extDir"
|
2015-08-05 00:16:53 +02:00
|
|
|
|
|
|
|
usage() {
|
2016-01-20 01:49:06 +01:00
|
|
|
echo "usage: $0 [options] module-name [module-name ...]"
|
2015-08-05 00:16:53 +02:00
|
|
|
echo " ie: $0 gd mysqli"
|
|
|
|
echo " $0 pdo pdo_mysql"
|
2016-01-20 01:49:06 +01:00
|
|
|
echo " $0 --ini-name 0-apc.ini apcu apc"
|
2015-08-05 00:16:53 +02:00
|
|
|
echo
|
|
|
|
echo 'Possible values for module-name:'
|
2018-04-19 21:51:31 +02:00
|
|
|
find -maxdepth 1 \
|
|
|
|
-type f \
|
|
|
|
-name '*.so' \
|
|
|
|
-exec basename '{}' ';' \
|
|
|
|
| sort \
|
|
|
|
| xargs
|
2017-09-20 00:43:41 +02:00
|
|
|
echo
|
|
|
|
echo 'Some of the above modules are already compiled into PHP; please check'
|
2017-09-20 02:03:52 +02:00
|
|
|
echo 'the output of "php -i" to see which modules are already loaded.'
|
2015-08-05 00:16:53 +02:00
|
|
|
}
|
|
|
|
|
2016-01-20 01:49:06 +01:00
|
|
|
opts="$(getopt -o 'h?' --long 'help,ini-name:' -- "$@" || { usage >&2 && false; })"
|
|
|
|
eval set -- "$opts"
|
|
|
|
|
|
|
|
iniName=
|
|
|
|
while true; do
|
|
|
|
flag="$1"
|
|
|
|
shift
|
|
|
|
case "$flag" in
|
|
|
|
--help|-h|'-?') usage && exit 0 ;;
|
|
|
|
--ini-name) iniName="$1" && shift ;;
|
|
|
|
--) break ;;
|
|
|
|
*)
|
|
|
|
{
|
|
|
|
echo "error: unknown flag: $flag"
|
|
|
|
usage
|
|
|
|
} >&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2016-03-18 18:51:01 +01:00
|
|
|
modules=
|
|
|
|
for module; do
|
2015-08-05 00:16:53 +02:00
|
|
|
if [ -z "$module" ]; then
|
|
|
|
continue
|
|
|
|
fi
|
2016-03-18 18:51:01 +01:00
|
|
|
if [ -f "$module.so" ] && ! [ -f "$module" ]; then
|
2015-08-05 00:16:53 +02:00
|
|
|
# allow ".so" to be optional
|
2016-03-18 18:51:01 +01:00
|
|
|
module="$module.so"
|
2015-08-05 00:16:53 +02:00
|
|
|
fi
|
2016-03-18 18:51:01 +01:00
|
|
|
if ! [ -f "$module" ]; then
|
2018-04-19 21:51:31 +02:00
|
|
|
echo >&2 "error: '$module' does not exist"
|
2015-08-05 00:16:53 +02:00
|
|
|
echo >&2
|
|
|
|
usage >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
2016-03-18 18:51:01 +01:00
|
|
|
modules="$modules $module"
|
2015-08-05 00:16:53 +02:00
|
|
|
done
|
|
|
|
|
2016-03-18 18:51:01 +01:00
|
|
|
if [ -z "$modules" ]; then
|
2015-08-05 00:16:53 +02:00
|
|
|
usage >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2017-05-04 20:43:02 +02:00
|
|
|
pm='unknown'
|
|
|
|
if [ -e /lib/apk/db/installed ]; then
|
|
|
|
pm='apk'
|
|
|
|
fi
|
|
|
|
|
|
|
|
apkDel=
|
|
|
|
if [ "$pm" = 'apk' ]; then
|
|
|
|
if \
|
|
|
|
[ -n "$PHPIZE_DEPS" ] \
|
|
|
|
&& ! apk info --installed .phpize-deps > /dev/null \
|
|
|
|
&& ! apk info --installed .phpize-deps-configure > /dev/null \
|
|
|
|
; then
|
|
|
|
apk add --no-cache --virtual '.docker-php-ext-enable-deps' binutils
|
|
|
|
apkDel='.docker-php-ext-enable-deps'
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2016-03-18 18:51:01 +01:00
|
|
|
for module in $modules; do
|
2017-12-09 01:25:01 +01:00
|
|
|
if readelf --wide --syms "$module" | grep -q ' zend_extension_entry$'; then
|
2015-08-05 00:16:53 +02:00
|
|
|
# https://wiki.php.net/internals/extensions#loading_zend_extensions
|
2018-04-19 21:51:31 +02:00
|
|
|
absModule="$(readlink -f "$module")"
|
|
|
|
line="zend_extension=$absModule"
|
2015-08-05 00:16:53 +02:00
|
|
|
else
|
|
|
|
line="extension=$module"
|
|
|
|
fi
|
|
|
|
|
|
|
|
ext="$(basename "$module")"
|
|
|
|
ext="${ext%.*}"
|
|
|
|
if php -r 'exit(extension_loaded("'"$ext"'") ? 0 : 1);'; then
|
|
|
|
# this isn't perfect, but it's better than nothing
|
|
|
|
# (for example, 'opcache.so' presents inside PHP as 'Zend OPcache', not 'opcache')
|
|
|
|
echo >&2
|
|
|
|
echo >&2 "warning: $ext ($module) is already loaded!"
|
|
|
|
echo >&2
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2018-11-09 10:15:03 +01:00
|
|
|
ini="$PHP_INI_DIR/conf.d/${iniName:-"docker-php-ext-$ext.ini"}"
|
2015-08-05 00:16:53 +02:00
|
|
|
if ! grep -q "$line" "$ini" 2>/dev/null; then
|
|
|
|
echo "$line" >> "$ini"
|
|
|
|
fi
|
|
|
|
done
|
2017-05-04 20:43:02 +02:00
|
|
|
|
|
|
|
if [ "$pm" = 'apk' ] && [ -n "$apkDel" ]; then
|
|
|
|
apk del $apkDel
|
|
|
|
fi
|