From 5dd11eecd6f3b4cd85cbd985c8c1414f098da4f4 Mon Sep 17 00:00:00 2001
From: Markus Frosch <markus.frosch@icinga.com>
Date: Tue, 31 Mar 2020 15:50:55 +0200
Subject: [PATCH] rpm: Make sure to exit on subshell errors

For older versions of bash...
---
 icinga-build-rpm-binary | 12 ++++++------
 icinga-build-rpm-source | 15 +++++++--------
 2 files changed, 13 insertions(+), 14 deletions(-)

diff --git a/icinga-build-rpm-binary b/icinga-build-rpm-binary
index 4733d2e..edff8f2 100755
--- a/icinga-build-rpm-binary
+++ b/icinga-build-rpm-binary
@@ -20,7 +20,7 @@ case "$ICINGA_BUILD_OS" in
       # Note: force rebuilding here, because zypper is a bit dumb
       run-retry-timeout sudo zypper --non-interactive clean --all
       run-retry-timeout sudo zypper --non-interactive --no-gpg-checks --gpg-auto-import-keys ref -fs
-    )
+    ) || exit 1
     ;;
   *)
     (
@@ -33,7 +33,7 @@ case "$ICINGA_BUILD_OS" in
         run-retry-timeout sudo yum clean expire-cache
         run-retry-timeout sudo yum makecache fast
       fi
-    )
+    ) || exit 1
     ;;
 esac
 
@@ -44,7 +44,7 @@ case "$ICINGA_BUILD_OS" in
       set -ex
       # shellcheck disable=SC2046
       run-retry-timeout sudo zypper --non-interactive install $(rpm -qpR "${source_rpm}")
-    )
+    ) || exit 1
     ;;
   *)
     (
@@ -55,7 +55,7 @@ case "$ICINGA_BUILD_OS" in
         set -ex
         run-retry-timeout sudo yum-builddep -y "${source_rpm}"
       fi
-    )
+    ) || exit 1
     ;;
 esac
 
@@ -87,7 +87,7 @@ eval "$(get_rpmbuild --rebuild "${source_rpm}")"
   else
     "${RPMBUILD[@]}"
   fi
-)
+) || exit 1
 
 if command -v ccache &>/dev/null && [ -d "${CCACHE_DIR}" ]; then
   cached_files="$(find "${CCACHE_DIR}" -type f ! -name ccache.conf ! -name stats | wc -l)"
@@ -121,4 +121,4 @@ echo "[ Running rpmlint ]"
     ) || lintrc=$?
   done
   [ "$lintrc" -eq 0 ]
-) || [ "${ICINGA_BUILD_IGNORE_LINT}" -eq 1 ]
+  ) || ([ "${ICINGA_BUILD_IGNORE_LINT}" -eq 1 ] && exit 1) || exit 1
diff --git a/icinga-build-rpm-source b/icinga-build-rpm-source
index cec244f..e9aae4f 100755
--- a/icinga-build-rpm-source
+++ b/icinga-build-rpm-source
@@ -7,7 +7,7 @@ set -e
 (
   set -ex
   rm -rf "${BUILDDIR:?}/"
-)
+) || exit 1
 
 echo "[ git show ]"
 GIT_PAGER='cat' git show -s || true
@@ -22,7 +22,7 @@ echo
   mkdir "${BUILDDIR}"/{,SPECS,SOURCES,BUILD,SRPMS,RPMS}
   cp -v ./*.spec "${BUILDDIR}/SPECS/"
   find . -maxdepth 1 -type f ! -name "*.spec" -exec cp -vt "${BUILDDIR}/SOURCES/" {} \;
-)
+) || exit 1
 
 if [ -d /etc/rpmdevtools ]; then
   if ! grep -Pq ^--netrc /etc/rpmdevtools/curlrc; then
@@ -45,14 +45,14 @@ if [ "$ICINGA_BUILD_TYPE" == "release" ] ; then
     set -ex
     cd "${BUILDDIR}/SOURCES/"
     run-retry-timeout spectool -g ../SPECS/*.spec
-  )
+  ) || exit 1
 else
   echo "[ Creating snapshot tarball ]"
   (
     set -ex
     UPSTREAM_GIT_BRANCH="$ICINGA_BUILD_UPSTREAM_BRANCH" run-retry-timeout ./get_snapshot
     mv -t "${BUILDDIR}/SOURCES/" ./*.version ./*.tar*
-  )
+  ) || exit 1
 
   echo "[ Building snapshot version ]"
   (
@@ -70,7 +70,7 @@ else
   	  -e '0,/^Source0\?: /{s/\(Source0\?\): .*/Source0: '"${tarball}"'/}' \
   	  -e '0,/^%global\s\+\(git_\)\?commit /{s/\(%global\s\+\(git_\)\?commit\).*/%global commit '"${git_commit}"'/}' \
   	   "SPECS/${ICINGA_BUILD_PROJECT}.spec"
-  )
+  ) || exit 1
 fi
 
 
@@ -84,8 +84,7 @@ echo "[ Building source RPM ]"
   # (he could test the package in repository)
   rpm -qp --queryformat "%{VERSION}-%{RELEASE}" "SRPMS/"*"${ICINGA_BUILD_PROJECT}"*".src.rpm" \
     >"${ICINGA_BUILD_PROJECT}-package.version"
-
-)
+) || exit 1
 
 echo "[ Running rpmlint ]"
 lintconf=(--info --verbose -o "NetworkEnabled True")
@@ -107,4 +106,4 @@ fi
     | tee "${BUILDDIR}/"rpmlint-srpm.log || lintrc=$?
 
   [ "$lintrc" -eq 0 ]
-) || [ "${ICINGA_BUILD_IGNORE_LINT}" -eq 1 ]
+) || ([ "${ICINGA_BUILD_IGNORE_LINT}" -eq 1 ] && exit 1) || exit 1
-- 
GitLab