From f952bafb20a7e8d7b5a94007b278b2a5059466d3 Mon Sep 17 00:00:00 2001 From: Michele Locati Date: Thu, 19 Dec 2019 14:04:35 +0100 Subject: [PATCH] Inspect data in expandPackagesToBeInstalled to detect errors --- install-php-extensions | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/install-php-extensions b/install-php-extensions index c66ec5f..0a49cf4 100755 --- a/install-php-extensions +++ b/install-php-extensions @@ -563,9 +563,14 @@ expandPackagesToBeInstalled () { expandPackagesToBeInstalled_result='' case "$(getDistro)" in alpine) + expandPackagesToBeInstalled_log="$(apk add --simulate $@ 2>&1)" + if test -n "$(printf '%s' "$expandPackagesToBeInstalled_log" | grep -E '^ERROR:')"; then + printf 'Failed to list the whole package list for %s\n\n%s\n' "$@" "$expandPackagesToBeInstalled_log" >&2 + exit 1 + fi IFS=' ' - for expandPackagesToBeInstalled_line in $(apk add --simulate $@); do + for expandPackagesToBeInstalled_line in $expandPackagesToBeInstalled_log; do if test -n "$(printf '%s' "$expandPackagesToBeInstalled_line" | grep -E '^\([0-9]*/[0-9]*) Installing ')"; then expandPackagesToBeInstalled_result="$expandPackagesToBeInstalled_result $(printf '%s' "$expandPackagesToBeInstalled_line" | cut -d ' ' -f 3)" fi @@ -573,10 +578,15 @@ expandPackagesToBeInstalled () { resetIFS ;; debian) + expandPackagesToBeInstalled_log="$(DEBIAN_FRONTEND=noninteractive apt-get install -sy $@ 2>&1)" + if test -n "$(printf '%s' "$expandPackagesToBeInstalled_log" | grep -E '^E:')"; then + printf 'Failed to list the whole package list for %s\n\n%s\n' "$@" "$expandPackagesToBeInstalled_log" >&2 + exit 1 + fi expandPackagesToBeInstalled_inNewPackages=0 IFS=' ' - for expandPackagesToBeInstalled_line in $(DEBIAN_FRONTEND=noninteractive apt-get install -sy $@); do + for expandPackagesToBeInstalled_line in $expandPackagesToBeInstalled_log; do if test $expandPackagesToBeInstalled_inNewPackages -eq 0; then if test "$expandPackagesToBeInstalled_line" = 'The following NEW packages will be installed:'; then expandPackagesToBeInstalled_inNewPackages=1