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