Blame SOURCES/rear-bz2111059.patch

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