php/5.6/docker-php-ext-enable

86 lines
1.8 KiB
Plaintext
Raw Normal View History

2015-08-05 00:23:38 +02:00
#!/bin/bash
set -e
2015-08-07 02:48:56 +02:00
cd "$(php -r 'echo ini_get("extension_dir");')"
2015-08-05 00:23:38 +02:00
usage() {
2016-01-20 02:31:29 +01:00
echo "usage: $0 [options] module-name [module-name ...]"
2015-08-05 00:23:38 +02:00
echo " ie: $0 gd mysqli"
echo " $0 pdo pdo_mysql"
2016-01-20 02:31:29 +01:00
echo " $0 --ini-name 0-apc.ini apcu apc"
2015-08-05 00:23:38 +02:00
echo
echo 'Possible values for module-name:'
echo $(find -maxdepth 1 -type f -name '*.so' -exec basename '{}' ';' | sort)
}
2016-01-20 02:31:29 +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
2015-08-05 00:23:38 +02:00
modules=()
while [ $# -gt 0 ]; do
module="$1"
shift
if [ -z "$module" ]; then
continue
fi
if [ -f "$module.so" -a ! -f "$module" ]; then
# allow ".so" to be optional
module+='.so'
fi
if [ ! -f "$module" ]; then
echo >&2 "error: $(readlink -f "$module") does not exist"
echo >&2
usage >&2
exit 1
fi
modules+=( "$module" )
done
if [ "${#modules[@]}" -eq 0 ]; then
usage >&2
exit 1
fi
for module in "${modules[@]}"; do
2016-01-07 01:31:49 +01:00
if nm -g "$module" | grep -q ' zend_extension_entry$'; then
2015-08-05 00:23:38 +02:00
# https://wiki.php.net/internals/extensions#loading_zend_extensions
2015-08-07 02:48:56 +02:00
line="zend_extension=$(readlink -f "$module")"
2015-08-05 00:23:38 +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
2016-01-20 02:31:29 +01:00
ini="/usr/local/etc/php/conf.d/${iniName:-"docker-php-ext-$ext.ini"}"
2015-08-05 00:23:38 +02:00
if ! grep -q "$line" "$ini" 2>/dev/null; then
echo "$line" >> "$ini"
fi
done