diff --git a/.github/workflows/test-extensions.yml b/.github/workflows/test-extensions.yml index 0a4ea9c..bb2ae20 100644 --- a/.github/workflows/test-extensions.yml +++ b/.github/workflows/test-extensions.yml @@ -109,3 +109,22 @@ jobs: with: fetch-depth: 1 - run: docker run --rm --volume "$(pwd):/app" --workdir /app php:7.4-alpine ./scripts/test-installversion "${{ matrix.xdebug_version }}" + test_composer: + name: Test installing composer + needs: + - check_syntax_data + - check_syntax_shell + - check_syntax_php + runs-on: ubuntu-latest + strategy: + matrix: + composer_version: + - '' + - '1' + - '2.0.1' + steps: + - name: Checkout + uses: actions/checkout@v2 + - run: | + docker run --rm --volume "$(pwd):/app" --workdir /app php:7.4-alpine ./scripts/test-installcomposer "${{ matrix.composer_version }}" + diff --git a/README.md b/README.md index 1a4a35b..620d4ee 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,21 @@ For example: install-php-extensions xdebug-2.9.7 ``` +### Installing composer + +You can also install [composer](https://getcomposer.org/), and you also can specify a major version of it, or a full version. + +Examples: + +```sh +# Install the latest version +install-php-extensions @composer +# Install the latest 1.x version +install-php-extensions @composer-1 +# Install a specific version +install-php-extensions @composer-2.0.2 +``` + ## Supported PHP extensions diff --git a/install-php-extensions b/install-php-extensions index a4ee0c8..e5c0818 100755 --- a/install-php-extensions +++ b/install-php-extensions @@ -107,6 +107,8 @@ processPHPMuduleArgument() { if test -n "$processPHPMuduleArgument_version"; then if printf '%s' "$PROCESSED_PHP_MODULE_ARGUMENT" | grep -Eq '^[a-zA-Z0-9_]+$'; then eval PHP_WANTEDMODULEVERSION_$PROCESSED_PHP_MODULE_ARGUMENT="$processPHPMuduleArgument_version" + elif printf '%s' "$PROCESSED_PHP_MODULE_ARGUMENT" | grep -Eq '^@[a-zA-Z0-9_]+$'; then + eval PHP_WANTEDMODULEVERSION__${PROCESSED_PHP_MODULE_ARGUMENT#@}="$processPHPMuduleArgument_version" else printf 'Unable to parse the following module name:\n%s\n' "$PROCESSED_PHP_MODULE_ARGUMENT" >&2 fi @@ -123,6 +125,8 @@ processPHPMuduleArgument() { getWantedPHPModuleVersion() { if printf '%s' "$1" | grep -Eq '^[a-zA-Z0-9_]+$'; then eval printf '%s' "\${PHP_WANTEDMODULEVERSION_$1:-}" + elif printf '%s' "$1" | grep -Eq '^@[a-zA-Z0-9_]+$'; then + eval printf '%s' "\${PHP_WANTEDMODULEVERSION__${1#@}:-}" fi } @@ -147,6 +151,9 @@ setPHPPreinstalledModules() { ;; esac done + if command -v composer >/dev/null; then + PHP_PREINSTALLED_MODULES="$PHP_PREINSTALLED_MODULES @composer" + fi resetIFS PHP_PREINSTALLED_MODULES="${PHP_PREINSTALLED_MODULES# }" } @@ -252,6 +259,12 @@ sortModulesToInstall() { PHP_MODULES_TO_INSTALL="msgpack $PHP_MODULES_TO_INSTALL" PHP_MODULES_TO_INSTALL="${PHP_MODULES_TO_INSTALL% }" fi + # In any case, first of all, we need to install composer + if stringInList '@composer' "$PHP_MODULES_TO_INSTALL"; then + PHP_MODULES_TO_INSTALL="$(removeStringFromList '@composer' "$PHP_MODULES_TO_INSTALL")" + PHP_MODULES_TO_INSTALL="@composer $PHP_MODULES_TO_INSTALL" + PHP_MODULES_TO_INSTALL="${PHP_MODULES_TO_INSTALL% }" + fi } # Get the required APT/APK packages for a specific PHP version and for the list of module handles @@ -273,7 +286,9 @@ buildRequiredPackageLists() { esac case "$DISTRO_VERSION" in alpine@*) - buildRequiredPackageLists_volatile="$PHPIZE_DEPS" + if test $# -gt 1 || test "${1:-}" != '@composer'; then + buildRequiredPackageLists_volatile="$PHPIZE_DEPS" + fi if test -z "$(apk info 2>/dev/null | grep -E ^libssl)"; then buildRequiredPackageLists_libssl='libssl1.0' elif test -z "$(apk info 2>/dev/null | grep -E '^libressl.*-libtls')"; then @@ -1045,6 +1060,24 @@ installOracleInstantClient() { esac } +# Install Composer +installComposer() { + installComposer_version="$(getWantedPHPModuleVersion @composer)" + if test -z "$installComposer_version"; then + installComposer_fullname=composer + installComposer_flags='' + else + installComposer_fullname="$(printf 'composer v%s' "$installComposer_version")" + if printf '%s' "$installComposer_version" | grep -Eq '^[0-9]+$'; then + installComposer_flags="--$installComposer_version" + else + installComposer_flags="--version=$installComposer_version" + fi + fi + printf '### INSTALLING %s ###\n' "$installComposer_fullname" + curl -sSLf https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer $installComposer_flags +} + # Install a bundled PHP module given its handle # # Arguments: @@ -1736,6 +1769,9 @@ installPECLModule() { configureInstaller() { USE_PICKLE=0 for PHP_MODULE_TO_INSTALL in $PHP_MODULES_TO_INSTALL; do + if test "${PHP_MODULE_TO_INSTALL#@}" != "$PHP_MODULE_TO_INSTALL"; then + continue + fi if ! stringInList "$PHP_MODULE_TO_INSTALL" "$BUNDLED_MODULES"; then if test $PHP_MAJMIN_VERSION -lt 800; then pecl channel-update pecl.php.net || true @@ -1902,9 +1938,13 @@ buildRequiredPackageLists $PHP_MODULES_TO_INSTALL if test -n "$PACKAGES_PERSISTENT$PACKAGES_VOLATILE"; then installRequiredPackages fi -setTargetTriplet +if test "$PHP_MODULES_TO_INSTALL" != '@composer'; then + setTargetTriplet +fi for PHP_MODULE_TO_INSTALL in $PHP_MODULES_TO_INSTALL; do - if stringInList "$PHP_MODULE_TO_INSTALL" "$BUNDLED_MODULES"; then + if test "$PHP_MODULE_TO_INSTALL" = '@composer'; then + installComposer + elif stringInList "$PHP_MODULE_TO_INSTALL" "$BUNDLED_MODULES"; then installBundledModule "$PHP_MODULE_TO_INSTALL" else MODULE_SOURCE='' diff --git a/scripts/test-installcomposer b/scripts/test-installcomposer new file mode 100755 index 0000000..6e90821 --- /dev/null +++ b/scripts/test-installcomposer @@ -0,0 +1,30 @@ +#!/bin/sh + +# Let's set a sane environment +set -o errexit +set -o nounset + +WANTED_VERSION="${1:-}" +INSTALLME=@composer +if test -n "$WANTED_VERSION"; then + INSTALLME="$INSTALLME-$1" +fi + +./install-php-extensions "$INSTALLME" + +INSTALLED_VERSION="$(composer --version | sed -E 's/^.*[Vv]ersion\s*(\S+).*$/\1/')" +if test -z "$WANTED_VERSION"; then + echo 'Installing the latest version worked' +elif printf '%s' "$WANTED_VERSION" | grep -Eq '^[0-9]+$'; then + if test "${INSTALLED_VERSION#$WANTED_VERSION.}" = "$INSTALLED_VERSION"; then + printf 'Installing major version %s DID NOT worked (we installed version %s)\n' "$WANTED_VERSION" "$INSTALLED_VERSION" + exit 1 + fi + printf 'Installing major version %s worked (we installed version %s)\n' "$WANTED_VERSION" "$INSTALLED_VERSION" +else + if test "$INSTALLED_VERSION" != "$WANTED_VERSION"; then + printf 'Installing specific version %s DID NOT worked (we installed version %s)\n' "$WANTED_VERSION" "$INSTALLED_VERSION" + exit 1 + fi + printf 'Installing specific version %s worked\n' "$INSTALLED_VERSION" +fi