From ef2941603c561c126720ffb75ccbba09b09b9a61 Mon Sep 17 00:00:00 2001 From: Michele Locati Date: Thu, 23 Jan 2020 13:48:18 +0100 Subject: [PATCH 1/3] Test that previously installed APT packages are restored --- .travis.yml | 4 ++++ scripts/invoke-shfmt | 1 + scripts/test-restore-apt | 17 +++++++++++++++++ 3 files changed, 22 insertions(+) create mode 100755 scripts/test-restore-apt diff --git a/.travis.yml b/.travis.yml index 522d292..43d226f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -62,6 +62,10 @@ jobs: name: Test extensions on Debian 10 (buster) env: DOCKER_DISTRO=buster + - <<: *test-extensions-job-template + name: Test restoring previous packages + script: docker run --rm --volume "$TRAVIS_BUILD_DIR:/app" --workdir /app php:7.3-stretch ./scripts/test-restore-apt + - stage: Update docs name: Update README.md if: branch = master AND type = push diff --git a/scripts/invoke-shfmt b/scripts/invoke-shfmt index 801c6f6..4c24e41 100755 --- a/scripts/invoke-shfmt +++ b/scripts/invoke-shfmt @@ -23,6 +23,7 @@ shfmt $PARAMS \ scripts/common \ scripts/invoke-shfmt \ scripts/lint \ + scripts/test-restore-apt \ scripts/travisci-test-extensions \ scripts/travisci-update-readme \ scripts/update-readme diff --git a/scripts/test-restore-apt b/scripts/test-restore-apt new file mode 100755 index 0000000..6545a0e --- /dev/null +++ b/scripts/test-restore-apt @@ -0,0 +1,17 @@ +#!/bin/sh + +# Let's set a sane environment +set -o errexit +set -o nounset + +apt-get update -qq +apt-get install -qqy libssl-dev + +./install-php-extensions zip + +if test -z "$(dpkg --get-selections | grep -E '^libssl-dev[:\s].*install$')"; then + echo 'The libssl-dev APT package has not been restored.' >&2 + exit 1 +fi + +echo 'The libssl-dev APT package has been correctly restored.' From 8b5078f47fd44e8c2b1eee8e21d6c14ee1a36ccf Mon Sep 17 00:00:00 2001 From: Michele Locati Date: Thu, 23 Jan 2020 14:50:55 +0100 Subject: [PATCH 2/3] Restore previously installed APT packages --- install-php-extensions | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/install-php-extensions b/install-php-extensions index 4b1d4eb..a0ebb61 100755 --- a/install-php-extensions +++ b/install-php-extensions @@ -199,6 +199,7 @@ sortModulesToInstall() { # Set: # PACKAGES_PERSISTENT # PACKAGES_VOLATILE +# PACKAGES_PREVIOUS buildRequiredPackageLists() { buildRequiredPackageLists_persistent='' buildRequiredPackageLists_volatile='' @@ -634,6 +635,7 @@ buildRequiredPackageLists() { done PACKAGES_PERSISTENT='' PACKAGES_VOLATILE='' + PACKAGES_PREVIOUS='' if test -z "$buildRequiredPackageLists_persistent$buildRequiredPackageLists_volatile"; then return fi @@ -643,7 +645,6 @@ buildRequiredPackageLists() { ;; debian) DEBIAN_FRONTEND=noninteractive apt-get update -q - DEBIAN_FRONTEND=noninteractive apt-get autoremove --purge -y -q ;; esac if test -n "$buildRequiredPackageLists_persistent"; then @@ -665,6 +666,13 @@ buildRequiredPackageLists() { done PACKAGES_VOLATILE="${PACKAGES_VOLATILE# }" fi + if test -n "$PACKAGES_PERSISTENT$PACKAGES_VOLATILE"; then + case "$buildRequiredPackageLists_distro" in + debian) + PACKAGES_PREVIOUS="$(dpkg --get-selections | grep -E '\sinstall$' | awk '{ print $1 }')" + ;; + esac + fi } # Get the full list of APT/APK packages that will be installed, given the required packages @@ -1290,6 +1298,14 @@ cleanup() { ;; esac fi + if test -n "$PACKAGES_PREVIOUS"; then + case "$cleanup_distro" in + debian) + printf '### RESTORING PREVIOUSLY INSTALLED PACKAGES ###\n' + DEBIAN_FRONTEND=noninteractive apt-get install -qqy $PACKAGES_PREVIOUS + ;; + esac + fi case "$cleanup_distro" in alpine) rm -rf /var/cache/apk/* From dc2c90a66346337d95f02ed92178963bf58cda66 Mon Sep 17 00:00:00 2001 From: Michele Locati Date: Thu, 23 Jan 2020 14:54:42 +0100 Subject: [PATCH 3/3] Upgrade packages in test-restore-apt --- scripts/test-restore-apt | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/test-restore-apt b/scripts/test-restore-apt index 6545a0e..dd9f408 100755 --- a/scripts/test-restore-apt +++ b/scripts/test-restore-apt @@ -5,6 +5,7 @@ set -o errexit set -o nounset apt-get update -qq +apt-get upgrade -qqy apt-get install -qqy libssl-dev ./install-php-extensions zip