Blame SOURCES/rear-bz2111059.patch

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