Blame SOURCES/rear-bz2111059.patch

5d051d
commit 552dd6bfb20fdb3dc712b5243656d147392c27c3
5d051d
Author: Johannes Meixner <jsmeix@suse.com>
5d051d
Date:   Thu Jun 2 15:25:52 2022 +0200
5d051d
5d051d
    Merge pull request #2811 from rear/jsmeix-RECOVERY_COMMANDS
5d051d
    
5d051d
    Add PRE_RECOVERY_COMMANDS and POST_RECOVERY_COMMANDS
5d051d
    as alternative to PRE_RECOVERY_SCRIPT and POST_RECOVERY_SCRIPT
5d051d
    see the description in default.conf how to use them and how they work.
5d051d
    See https://github.com/rear/rear/pull/2811 and see also
5d051d
    https://github.com/rear/rear/pull/2735 therein in particular
5d051d
    https://github.com/rear/rear/pull/2735#issuecomment-1134686196
5d051d
    Additionally use LogPrint to show the user the executed commands,
5d051d
    see https://github.com/rear/rear/pull/2789
5d051d
5d051d
diff --git a/usr/share/rear/conf/default.conf b/usr/share/rear/conf/default.conf
5d051d
index cb14da8b..b14525da 100644
5d051d
--- a/usr/share/rear/conf/default.conf
5d051d
+++ b/usr/share/rear/conf/default.conf
5d051d
@@ -3117,14 +3117,37 @@ ELILO_BIN=
5d051d
 ################ ---- custom scripts
5d051d
 #
5d051d
 # NOTE: The scripts can be defined as an array to better handly spaces in parameters.
5d051d
-# The scripts are called like this: eval "${PRE_RECOVERY_SCRIPT[@]}"
5d051d
+# The scripts are called like this:
5d051d
+#   eval "${PRE_RECOVERY_SCRIPT[@]}"
5d051d
+#
5d051d
+# Alternatively, commands can be executed by using the corresponding
5d051d
+# PRE_RECOVERY_COMMANDS and POST_RECOVERY_COMMANDS array variables
5d051d
+# which evaluate like this:
5d051d
+#   for command in "${PRE_RECOVERY_COMMANDS[@]}" ; do
5d051d
+#     eval "$command"
5d051d
+#   done
5d051d
+#
5d051d
+# Using PRE_RECOVERY_COMMANDS and POST_RECOVERY_COMMANDS
5d051d
+# is simpler when multiple commands should be executed.
5d051d
+# For example,
5d051d
+#   PRE_RECOVERY_SCRIPT=( 'echo Hello' ';' 'sleep 3' )
5d051d
+# can be rewritten as
5d051d
+#   PRE_RECOVERY_COMMANDS=( 'echo Hello' 'sleep 3' )
5d051d
+# or
5d051d
+#   PRE_RECOVERY_COMMANDS=( 'echo Hello' )
5d051d
+#   PRE_RECOVERY_COMMANDS+=( 'sleep 3' )
5d051d
+
5d051d
+# Those get called at the very beginning of "rear recover".
5d051d
+# The PRE_RECOVERY_COMMANDS are called directly before the PRE_RECOVERY_SCRIPT.
5d051d
+# Nothing was recreated and you have only the plain ReaR rescue/recovery system:
5d051d
+PRE_RECOVERY_COMMANDS=()
5d051d
+PRE_RECOVERY_SCRIPT=
5d051d
 
5d051d
-# Call this after Relax-and-Recover did everything in the recover workflow.
5d051d
-# Use $TARGET_FS_ROOT (by default '/mnt/local') to refer to the recovered system.
5d051d
+# Those get called at the very end of "rear recover".
5d051d
+# The POST_RECOVERY_COMMANDS are called directly after the POST_RECOVERY_SCRIPT.
5d051d
+# Use $TARGET_FS_ROOT (by default '/mnt/local') to access the recreated target system.
5d051d
 POST_RECOVERY_SCRIPT=
5d051d
-
5d051d
-# Call this before Relax-and-Recover starts to do anything in the recover workflow. You have the rescue system but nothing else
5d051d
-PRE_RECOVERY_SCRIPT=
5d051d
+POST_RECOVERY_COMMANDS=()
5d051d
 
5d051d
 # PRE/POST Backup scripts will provide the ability to run certain tasks before and after a ReaR backup.
5d051d
 # for example:
5d051d
diff --git a/usr/share/rear/setup/default/010_pre_recovery_script.sh b/usr/share/rear/setup/default/010_pre_recovery_script.sh
5d051d
index 005107cc..8b4e4a36 100644
5d051d
--- a/usr/share/rear/setup/default/010_pre_recovery_script.sh
5d051d
+++ b/usr/share/rear/setup/default/010_pre_recovery_script.sh
5d051d
@@ -1,4 +1,14 @@
5d051d
+
5d051d
+# The PRE_RECOVERY_COMMANDS are called directly before the PRE_RECOVERY_SCRIPT
5d051d
+# so PRE_RECOVERY_COMMANDS can also be used to prepare things for the PRE_RECOVERY_SCRIPT:
5d051d
+
5d051d
+local command
5d051d
+for command in "${PRE_RECOVERY_COMMANDS[@]}" ; do
5d051d
+    LogPrint "Running PRE_RECOVERY_COMMANDS '$command'"
5d051d
+    eval "$command"
5d051d
+done
5d051d
+
5d051d
 if test "$PRE_RECOVERY_SCRIPT" ; then
5d051d
-	Log "Running PRE_RECOVERY_SCRIPT '${PRE_RECOVERY_SCRIPT[@]}'"
5d051d
-	eval "${PRE_RECOVERY_SCRIPT[@]}"
5d051d
+    LogPrint "Running PRE_RECOVERY_SCRIPT '${PRE_RECOVERY_SCRIPT[@]}'"
5d051d
+    eval "${PRE_RECOVERY_SCRIPT[@]}"
5d051d
 fi
5d051d
diff --git a/usr/share/rear/wrapup/default/500_post_recovery_script.sh b/usr/share/rear/wrapup/default/500_post_recovery_script.sh
5d051d
index 77751800..866c9368 100644
5d051d
--- a/usr/share/rear/wrapup/default/500_post_recovery_script.sh
5d051d
+++ b/usr/share/rear/wrapup/default/500_post_recovery_script.sh
5d051d
@@ -1,4 +1,14 @@
5d051d
+
5d051d
+# The POST_RECOVERY_COMMANDS are called directly after the POST_RECOVERY_SCRIPT
5d051d
+# so POST_RECOVERY_COMMANDS can also be used to clean up things after the POST_RECOVERY_SCRIPT:
5d051d
+
5d051d
 if test "$POST_RECOVERY_SCRIPT" ; then
5d051d
-	Log "Running POST_RECOVERY_SCRIPT '${POST_RECOVERY_SCRIPT[@]}'"
5d051d
-	eval "${POST_RECOVERY_SCRIPT[@]}"
5d051d
+    LogPrint "Running POST_RECOVERY_SCRIPT '${POST_RECOVERY_SCRIPT[@]}'"
5d051d
+    eval "${POST_RECOVERY_SCRIPT[@]}"
5d051d
 fi
5d051d
+
5d051d
+local command
5d051d
+for command in "${POST_RECOVERY_COMMANDS[@]}" ; do
5d051d
+    LogPrint "Running POST_RECOVERY_COMMANDS '$command'"
5d051d
+    eval "$command"
5d051d
+done