Blame SOURCES/rear-bz1693608.patch

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