|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -ex |
| 4 | + |
| 5 | +if [ -n "$DEV_DEPENDENCIES" ] || [ -n "$DEPENDENCIES" ]; then |
| 6 | + apt-get install -y --no-install-recommends $DEV_DEPENDENCIES $DEPENDENCIES |
| 7 | +fi |
| 8 | + |
| 9 | +if [ -n "$CONFIGURE_OPTIONS" ]; then |
| 10 | + docker-php-ext-configure $EXTENSION $CONFIGURE_OPTIONS |
| 11 | +fi |
| 12 | + |
| 13 | +if [ -n "$EXTENSION" ]; then |
| 14 | + set +e |
| 15 | + PACKAGE_NAME=${PACKAGE_NAME:-$EXTENSION} |
| 16 | + if apt-cache search --names-only "php${PHP_VERSION}-$PACKAGE_NAME" | grep "php${PHP_VERSION}-$PACKAGE_NAME"; then |
| 17 | + set -e |
| 18 | + apt-get install -y --no-install-recommends php${PHP_VERSION}-$PACKAGE_NAME |
| 19 | + else |
| 20 | + set -e |
| 21 | + apt-get install -y --no-install-recommends php-$PACKAGE_NAME |
| 22 | + fi |
| 23 | + |
| 24 | +fi |
| 25 | + |
| 26 | +if [ -n "$PECL_EXTENSION" ]; then |
| 27 | + # if env ready? |
| 28 | + |
| 29 | + # is phpize installed? |
| 30 | + if which pickle && which phpize; then |
| 31 | + echo "pickle found" |
| 32 | + which pickle |
| 33 | + else |
| 34 | + apt-get install -y --no-install-recommends build-essential php-pear php${PHP_VERSION}-dev pkg-config |
| 35 | + curl https://github.com/FriendsOfPHP/pickle/releases/latest/download/pickle.phar -L -o /usr/local/bin/pickle |
| 36 | + chmod +x /usr/local/bin/pickle |
| 37 | + fi |
| 38 | + |
| 39 | + if [ -n "$USE_PECL" ]; then |
| 40 | + pecl channel-update pecl.php.net && pecl channel-update pear.php.net |
| 41 | + pecl install $PECL_EXTENSION |
| 42 | + else |
| 43 | + pickle install $PECL_EXTENSION |
| 44 | + fi |
| 45 | + echo "extension=${PHP_EXT_NAME:-${PECL_EXTENSION}}.so" > /etc/php/${PHP_VERSION}/mods-available/${PHP_EXT_NAME:-${PECL_EXTENSION}}.ini |
| 46 | + # Adding this in the list of Ubuntu extensions because we use that list as a base for the modules list. |
| 47 | + # TODO: question: cannot we use /etc/php/mods-available instead??? |
| 48 | + touch /var/lib/php/modules/${PHP_VERSION}/registry/${PHP_EXT_NAME:-${PECL_EXTENSION}} |
| 49 | +fi |
| 50 | + |
| 51 | +if [ -n "$DEV_DEPENDENCIES" ]; then |
| 52 | + apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false -o APT::AutoRemove::SuggestsImportant=false $DEV_DEPENDENCIES |
| 53 | +fi |
| 54 | + |
| 55 | +if [ -n "$EXTENSION" ]; then |
| 56 | + # Let's perform a test |
| 57 | + phpenmod -v $PHP_VERSION $EXTENSION |
| 58 | + /usr/bin/real_php -m | grep "${PHP_EXT_PHP_NAME:-${PHP_EXT_NAME:-$EXTENSION}}" |
| 59 | + # Check that there is no output on STDERR when starting php: |
| 60 | + OUTPUT=`/usr/bin/real_php -r "echo '';" 2>&1` |
| 61 | + [[ "$OUTPUT" == "" ]] |
| 62 | + # And now, let's disable it! |
| 63 | + phpdismod -v $PHP_VERSION $EXTENSION |
| 64 | +fi |
| 65 | + |
| 66 | +if [ -n "$PECL_EXTENSION" ]; then |
| 67 | + # Let's perform a test |
| 68 | + PHP_EXTENSIONS="${PHP_EXT_NAME:-$PECL_EXTENSION}" PHP_VERSION="${PHP_VERSION}" /usr/bin/real_php /usr/local/bin/setup_extensions.php | bash |
| 69 | + PHP_EXTENSIONS="${PHP_EXT_NAME:-$PECL_EXTENSION}" /usr/bin/real_php /usr/local/bin/generate_conf.php > /etc/php/${PHP_VERSION}/cli/conf.d/testextension.ini |
| 70 | + |
| 71 | + /usr/bin/real_php -m | grep "${PHP_EXT_PHP_NAME:-${PHP_EXT_NAME:-$PECL_EXTENSION}}" |
| 72 | + # Check that there is no output on STDERR when starting php: |
| 73 | + OUTPUT=`/usr/bin/real_php -r "echo '';" 2>&1` |
| 74 | + [[ "$OUTPUT" == "" ]] |
| 75 | + PHP_EXTENSIONS="" PHP_VERSION="${PHP_VERSION}" /usr/bin/real_php /usr/local/bin/setup_extensions.php | bash |
| 76 | + rm /etc/php/${PHP_VERSION}/cli/conf.d/testextension.ini |
| 77 | +fi |
0 commit comments