Blame SOURCES/rear-bz1693608.patch

129f2e
diff -up rear-2.4/usr/share/rear/build/default/980_verify_rootfs.sh.build rear-2.4/usr/share/rear/build/default/980_verify_rootfs.sh
129f2e
--- rear-2.4/usr/share/rear/build/default/980_verify_rootfs.sh.build	2019-09-10 09:31:05.971102125 +0200
129f2e
+++ rear-2.4/usr/share/rear/build/default/980_verify_rootfs.sh	2019-09-10 09:31:06.002101535 +0200
129f2e
@@ -3,6 +3,33 @@
129f2e
 # i.e. test that the ReaR recovery system will be usable
129f2e
 # to avoid issues like https://github.com/rear/rear/issues/1494
129f2e
 
129f2e
+if test "$KEEP_BUILD_DIR" = "errors"; then
129f2e
+    local keep_build_dir_on_errors=1
129f2e
+else
129f2e
+    # KEEP_BUILD_DIR does not say to keep it on errors
129f2e
+    # - effective value depends on whether we are running interactively
129f2e
+    if tty -s ; then
129f2e
+        local keep_build_dir_on_errors=1
129f2e
+    else
129f2e
+        local keep_build_dir_on_errors=0
129f2e
+    fi
129f2e
+fi
129f2e
+
129f2e
+function keep_build_dir() {
129f2e
+    if ! is_true "$KEEP_BUILD_DIR" && ! is_false "$KEEP_BUILD_DIR"; then
129f2e
+        # is either empty or equal to "errors" ... or some garbage value
129f2e
+        local orig_keep_build_dir="$KEEP_BUILD_DIR"
129f2e
+        KEEP_BUILD_DIR="${keep_build_dir_on_errors}"
129f2e
+    fi
129f2e
+    if is_true "$KEEP_BUILD_DIR" ; then
129f2e
+        LogPrintError "Build area kept for investigation in $BUILD_DIR, remove it when not needed"
129f2e
+    elif ! is_false "$orig_keep_build_dir" ; then
129f2e
+        # if users disabled preserving the build dir explicitly, let's not bother them with messages
129f2e
+        LogPrintError "Build area $BUILD_DIR will be removed"
129f2e
+        LogPrintError "To preserve it for investigation set KEEP_BUILD_DIR=errors or run ReaR with -d"
129f2e
+    fi
129f2e
+}
129f2e
+
129f2e
 # In case the filesystem that contains the ROOTFS_DIR is mounted 'noexec' we cannot do the 'chroot' tests.
129f2e
 # The filesystem_name function in linux-functions.sh returns the mountpoint (not a filesystem name like 'ext4'):
129f2e
 local rootfs_dir_fs_mountpoint=$( filesystem_name $ROOTFS_DIR )
129f2e
@@ -16,7 +43,7 @@ Log "Testing that $ROOTFS_DIR contains a
129f2e
 
129f2e
 # The bash test ensures that we have a working bash in the ReaR recovery system:
129f2e
 if ! chroot $ROOTFS_DIR /bin/bash -c true ; then
129f2e
-    KEEP_BUILD_DIR=1
129f2e
+    keep_build_dir
129f2e
     BugError "ReaR recovery system in '$ROOTFS_DIR' is broken: 'bash -c true' failed"
129f2e
 fi
129f2e
 
129f2e
@@ -25,7 +52,7 @@ fi
129f2e
 # First test is 'ldd /bin/bash' to ensure 'ldd' works:
129f2e
 Log "Testing 'ldd /bin/bash' to ensure 'ldd' works for the subsequent 'ldd' tests"
129f2e
 if ! chroot $ROOTFS_DIR /bin/ldd /bin/bash 1>&2 ; then
129f2e
-    KEEP_BUILD_DIR=1
129f2e
+    keep_build_dir
129f2e
     BugError "ReaR recovery system in '$ROOTFS_DIR' is broken: 'ldd /bin/bash' failed"
129f2e
 fi
129f2e
 # Now test each binary (except links) with ldd and look for 'not found' libraries.
129f2e
@@ -83,7 +110,7 @@ test $old_LD_LIBRARY_PATH && export LD_L
129f2e
 # Report binaries with 'not found' shared object dependencies:
129f2e
 if contains_visible_char "$broken_binaries" ; then
129f2e
     LogPrintError "There are binaries or libraries in the ReaR recovery system that need additional libraries"
129f2e
-    KEEP_BUILD_DIR=1
129f2e
+    keep_build_dir
129f2e
     local fatal_missing_library=""
129f2e
     local ldd_output=""
129f2e
     for binary in $broken_binaries ; do
129f2e
@@ -113,9 +140,10 @@ if contains_visible_char "$broken_binari
129f2e
         # Show only the missing libraries to the user to not flood his screen with tons of other ldd output lines:
129f2e
         PrintError "$( grep 'not found' <<<"$ldd_output" )"
129f2e
     done
129f2e
+    LogPrintError "ReaR recovery system in '$ROOTFS_DIR' needs additional libraries, check $RUNTIME_LOGFILE for details"
129f2e
+    is_true "$fatal_missing_library" && keep_build_dir
129f2e
     # Usually it should be no BugError when there are libraries missing for particular binaries because probably
129f2e
     # the reason is that the user added only the plain binaries with COPY_AS_IS (instead of using REQUIRED_PROGS):
129f2e
     is_true "$fatal_missing_library" && Error "ReaR recovery system in '$ROOTFS_DIR' not usable"
129f2e
-    LogPrintError "ReaR recovery system in '$ROOTFS_DIR' needs additional libraries, check $RUNTIME_LOGFILE for details"
129f2e
 fi
129f2e
 
129f2e
diff -up rear-2.4/usr/share/rear/conf/default.conf.build rear-2.4/usr/share/rear/conf/default.conf
129f2e
--- rear-2.4/usr/share/rear/conf/default.conf.build	2019-09-10 09:31:05.996101649 +0200
129f2e
+++ rear-2.4/usr/share/rear/conf/default.conf	2019-09-10 09:31:06.002101535 +0200
129f2e
@@ -125,9 +125,19 @@ OS_VERSION=none
129f2e
 # supported values that could make it work even for your system.
129f2e
 # See the SetOSVendorAndVersion function in the config-functions.sh script.
129f2e
 
129f2e
-# Keep the build area after we are done (BOOL).
129f2e
+# Keep the build area after we are done (ternary).
129f2e
 # Useful to inspect the ReaR recovery system content in $TMPDIR/rear.XXXXXXXXXXXXXXX/rootfs/
129f2e
-# directly without the need to extract it from the initramfs/initrd in the ISO image:
129f2e
+# directly without the need to extract it from the initramfs/initrd in the ISO image.
129f2e
+# Set to "y", "Yes", etc. to always keep the build area, to "n", "No", etc. to never keep it.
129f2e
+# KEEP_BUILD_DIR is automatically set to true in debug mode (-d) and in debugscript mode (-D).
129f2e
+# In addition to true (any value that is recognized as 'yes' by the is_true function)
129f2e
+# and false (any value that is recognized as 'no' by the is_false function) it can be set
129f2e
+# to several special values:
129f2e
+# - "errors" to obtain the old behaviour where KEEP_BUILD_DIR was always set
129f2e
+# to true to keep the build area when errors in the ReaR recovery system were detected.
129f2e
+# - empty (KEEP_BUILD_DIR="") which means that the build area will be kept on errors
129f2e
+# if running interactively (in a terminal) and not otherwise (to avoid cluttering
129f2e
+# /tmp by cron or other automated jobs in case of errors).
129f2e
 KEEP_BUILD_DIR=""
129f2e
 
129f2e
 # No default workflows. This variable is filled in where the workflows are defined
129f2e
diff -up rear-2.4/usr/share/rear/lib/framework-functions.sh.build rear-2.4/usr/share/rear/lib/framework-functions.sh
129f2e
--- rear-2.4/usr/share/rear/lib/framework-functions.sh.build	2018-06-21 10:40:53.000000000 +0200
129f2e
+++ rear-2.4/usr/share/rear/lib/framework-functions.sh	2019-09-10 09:31:06.002101535 +0200
129f2e
@@ -106,7 +106,7 @@ function SourceStage () {
129f2e
 function cleanup_build_area_and_end_program () {
129f2e
     # Cleanup build area
129f2e
     Log "Finished in $((SECONDS-STARTTIME)) seconds"
129f2e
-    if test "$KEEP_BUILD_DIR" ; then
129f2e
+    if is_true "$KEEP_BUILD_DIR" ; then
129f2e
         LogPrint "You should also rm -Rf $BUILD_DIR"
129f2e
     else
129f2e
         Log "Removing build area $BUILD_DIR"