Blame SOURCES/rear-bz2083272.patch

2f081d
commit 3d1bcf1b50ca8201a3805bc7cab6ca69c14951a1
2f081d
Author: pcahyna <pcahyna@users.noreply.github.com>
2f081d
Date:   Thu May 5 12:11:55 2022 +0200
2f081d
2f081d
    Merge pull request #2795 from pcahyna/recover-check-sums
2f081d
    
2f081d
    Verify file hashes at the end of recover after file restore from backup
2f081d
2f081d
diff --git a/usr/share/rear/conf/default.conf b/usr/share/rear/conf/default.conf
2f081d
index f231bf3d..881a0af0 100644
2f081d
--- a/usr/share/rear/conf/default.conf
2f081d
+++ b/usr/share/rear/conf/default.conf
2f081d
@@ -313,8 +313,30 @@ CDROM_SIZE=20
2f081d
 # which exits with non-zero exit code when the disk layout or those files changed
2f081d
 # (cf. https://github.com/rear/rear/issues/1134) but the checklayout workflow
2f081d
 # does not automatically recreate the rescue/recovery system.
2f081d
+# Files matching FILES_TO_PATCH_PATTERNS are added to this list automatically.
2f081d
 CHECK_CONFIG_FILES=( '/etc/drbd/' '/etc/drbd.conf' '/etc/lvm/lvm.conf' '/etc/multipath.conf' '/etc/rear/' '/etc/udev/udev.conf' )
2f081d
 
2f081d
+# FILES_TO_PATCH_PATTERNS is a space-separated list of shell glob patterns.
2f081d
+# Files that match are eligible for a final migration of UUIDs and other
2f081d
+# identifiers after recovery (if the layout recreation process has led
2f081d
+# to a change of an UUID or a device name and a corresponding change needs
2f081d
+# to be performed on restored configuration files ).
2f081d
+# See finalize/GNU/Linux/280_migrate_uuid_tags.sh
2f081d
+# The [] around the first letter make sure that shopt -s nullglob removes this file from the list if it does not exist
2f081d
+
2f081d
+FILES_TO_PATCH_PATTERNS="[b]oot/{grub.conf,menu.lst,device.map} [e]tc/grub.* \
2f081d
+                         [b]oot/grub/{grub.conf,grub.cfg,menu.lst,device.map} \
2f081d
+                         [b]oot/grub2/{grub.conf,grub.cfg,menu.lst,device.map} \
2f081d
+                         [e]tc/sysconfig/grub [e]tc/sysconfig/bootloader \
2f081d
+                         [e]tc/lilo.conf [e]tc/elilo.conf \
2f081d
+                         [e]tc/yaboot.conf \
2f081d
+                         [e]tc/mtab [e]tc/fstab \
2f081d
+                         [e]tc/mtools.conf \
2f081d
+                         [e]tc/smartd.conf [e]tc/sysconfig/smartmontools \
2f081d
+                         [e]tc/sysconfig/rawdevices \
2f081d
+                         [e]tc/security/pam_mount.conf.xml \
2f081d
+                         [b]oot/efi/*/*/grub.cfg"
2f081d
+
2f081d
 ##
2f081d
 # Relax-and-Recover recovery system update during "rear recover"
2f081d
 #
2f081d
diff --git a/usr/share/rear/finalize/GNU/Linux/250_migrate_disk_devices_layout.sh b/usr/share/rear/finalize/GNU/Linux/250_migrate_disk_devices_layout.sh
2f081d
index 1a91a0e3..e869e5e9 100644
2f081d
--- a/usr/share/rear/finalize/GNU/Linux/250_migrate_disk_devices_layout.sh
2f081d
+++ b/usr/share/rear/finalize/GNU/Linux/250_migrate_disk_devices_layout.sh
2f081d
@@ -29,19 +29,9 @@ LogPrint "The original restored files get saved in $save_original_file_dir (in $
2f081d
 
2f081d
 local symlink_target=""
2f081d
 local restored_file=""
2f081d
-# the funny [] around the first letter make sure that shopt -s nullglob removes this file from the list if it does not exist
2f081d
-# the files without a [] are mandatory, like fstab FIXME: but below there is [e]tc/fstab not etc/fstab - why?
2f081d
-
2f081d
-for restored_file in [b]oot/{grub.conf,menu.lst,device.map} [e]tc/grub.* [b]oot/grub/{grub.conf,menu.lst,device.map} \
2f081d
-                     [b]oot/grub2/{grub.conf,grub.cfg,menu.lst,device.map} \
2f081d
-                     [e]tc/sysconfig/grub [e]tc/sysconfig/bootloader \
2f081d
-                     [e]tc/lilo.conf \
2f081d
-                     [e]tc/yaboot.conf \
2f081d
-                     [e]tc/mtab [e]tc/fstab \
2f081d
-                     [e]tc/mtools.conf \
2f081d
-                     [e]tc/smartd.conf [e]tc/sysconfig/smartmontools \
2f081d
-                     [e]tc/sysconfig/rawdevices \
2f081d
-                     [e]tc/security/pam_mount.conf.xml [b]oot/efi/*/*/grub.cfg
2f081d
+# The variable expansion is deliberately not quoted in order to perform
2f081d
+# pathname expansion on the variable value.
2f081d
+for restored_file in $FILES_TO_PATCH_PATTERNS
2f081d
 do
2f081d
     # Silently skip directories and file not found:
2f081d
     test -f "$restored_file" || continue
2f081d
diff --git a/usr/share/rear/finalize/GNU/Linux/280_migrate_uuid_tags.sh b/usr/share/rear/finalize/GNU/Linux/280_migrate_uuid_tags.sh
2f081d
index 074689a1..d994ce8e 100644
2f081d
--- a/usr/share/rear/finalize/GNU/Linux/280_migrate_uuid_tags.sh
2f081d
+++ b/usr/share/rear/finalize/GNU/Linux/280_migrate_uuid_tags.sh
2f081d
@@ -23,18 +23,9 @@ LogPrint "Migrating filesystem UUIDs in certain restored files in $TARGET_FS_ROO
2f081d
 
2f081d
 local symlink_target=""
2f081d
 local restored_file=""
2f081d
-# the funny [] around the first letter make sure that shopt -s nullglob removes this file from the list if it does not exist
2f081d
-# the files without a [] are mandatory, like fstab FIXME: but below there is [e]tc/fstab not etc/fstab - why?
2f081d
-for restored_file in [b]oot/{grub.conf,menu.lst,device.map} [e]tc/grub.* \
2f081d
-                     [b]oot/grub/{grub.conf,grub.cfg,menu.lst,device.map} \
2f081d
-                     [b]oot/grub2/{grub.conf,grub.cfg,menu.lst,device.map} \
2f081d
-                     [e]tc/sysconfig/grub [e]tc/sysconfig/bootloader \
2f081d
-                     [e]tc/lilo.conf [e]tc/elilo.conf \
2f081d
-                     [e]tc/mtab [e]tc/fstab \
2f081d
-                     [e]tc/mtools.conf \
2f081d
-                     [e]tc/smartd.conf [e]tc/sysconfig/smartmontools \
2f081d
-                     [e]tc/sysconfig/rawdevices \
2f081d
-                     [e]tc/security/pam_mount.conf.xml [b]oot/efi/*/*/grub.cfg
2f081d
+# The variable expansion is deliberately not quoted in order to perform
2f081d
+# pathname expansion on the variable value.
2f081d
+for restored_file in $FILES_TO_PATCH_PATTERNS
2f081d
 do
2f081d
     # Silently skip directories and file not found:
2f081d
     test -f "$restored_file" || continue
2f081d
diff --git a/usr/share/rear/finalize/default/060_compare_files.sh b/usr/share/rear/finalize/default/060_compare_files.sh
2f081d
new file mode 100644
2f081d
index 00000000..6947fda9
2f081d
--- /dev/null
2f081d
+++ b/usr/share/rear/finalize/default/060_compare_files.sh
2f081d
@@ -0,0 +1,6 @@
2f081d
+if [ -e $VAR_DIR/layout/config/files.md5sum ] ; then
2f081d
+    if ! chroot $TARGET_FS_ROOT md5sum -c --quiet < $VAR_DIR/layout/config/files.md5sum 1>> >( tee -a "$RUNTIME_LOGFILE" 1>&7 ) 2>> >( tee -a "$RUNTIME_LOGFILE" 1>&8 ) ; then
2f081d
+        LogPrintError "Error: Restored files do not match the recreated system in $TARGET_FS_ROOT"
2f081d
+        return 1
2f081d
+    fi
2f081d
+fi
2f081d
diff --git a/usr/share/rear/layout/save/default/490_check_files_to_patch.sh b/usr/share/rear/layout/save/default/490_check_files_to_patch.sh
2f081d
new file mode 100644
2f081d
index 00000000..ee717063
2f081d
--- /dev/null
2f081d
+++ b/usr/share/rear/layout/save/default/490_check_files_to_patch.sh
2f081d
@@ -0,0 +1,43 @@
2f081d
+# FILES_TO_PATCH_PATTERNS is a space-separated list of shell glob patterns.
2f081d
+# Files that match are eligible for a final migration of UUIDs and other
2f081d
+# identifiers after recovery (if the layout recreation process has led
2f081d
+# to a change of an UUID or a device name and a corresponding change needs
2f081d
+# to be performed on restored configuration files ).
2f081d
+# See finalize/GNU/Linux/280_migrate_uuid_tags.sh
2f081d
+# We should add all such files to CHECK_CONFIG_FILES - if they change,
2f081d
+# we risk inconsistencies between the restored files and recreated layout,
2f081d
+# or failures of UUID migration.
2f081d
+
2f081d
+local file final_file symlink_target
2f081d
+
2f081d
+# The patterns are relative to /, change directory there
2f081d
+# so that the shell finds the files during pathname expansion
2f081d
+pushd / >/dev/null
2f081d
+# The variable expansion is deliberately not quoted in order to perform
2f081d
+# pathname expansion on the variable value.
2f081d
+for file in $FILES_TO_PATCH_PATTERNS ; do
2f081d
+    final_file="/$file"
2f081d
+    IsInArray "$final_file" "${CHECK_CONFIG_FILES[@]}" && continue
2f081d
+    # Symlink handling (partially from 280_migrate_uuid_tags.sh):
2f081d
+    # avoid dead symlinks, and symlinks to files on dynamic filesystems
2f081d
+    # ( /proc etc.) - they are expected to change and validating
2f081d
+    # their checksums has no sense
2f081d
+    if test -L "$final_file" ; then
2f081d
+        if symlink_target="$( readlink -e "$final_file" )" ; then
2f081d
+            # If the symlink target contains /proc/ /sys/ /dev/ or /run/ we skip it because then
2f081d
+            # the symlink target is considered to not be a restored file that needs to be patched
2f081d
+            # and thus we don't need to generate and check its hash, either
2f081d
+            # cf. https://github.com/rear/rear/pull/2047#issuecomment-464846777
2f081d
+            if echo $symlink_target | egrep -q '/proc/|/sys/|/dev/|/run/' ; then
2f081d
+                Log "Skip adding symlink $final_file target $symlink_target on /proc/ /sys/ /dev/ or /run/ to CHECK_CONFIG_FILES"
2f081d
+                continue
2f081d
+            fi
2f081d
+            Debug "Adding symlink $final_file with target $symlink_target to CHECK_CONFIG_FILES"
2f081d
+        else
2f081d
+            LogPrint "Skip adding dead symlink $final_file to CHECK_CONFIG_FILES"
2f081d
+            continue
2f081d
+        fi
2f081d
+    fi
2f081d
+    CHECK_CONFIG_FILES+=( "$final_file" )
2f081d
+done
2f081d
+popd >/dev/null
2f081d
diff --git a/usr/share/rear/layout/save/default/600_snapshot_files.sh b/usr/share/rear/layout/save/default/600_snapshot_files.sh
2f081d
index 0ebf197c..3ac6b07e 100644
2f081d
--- a/usr/share/rear/layout/save/default/600_snapshot_files.sh
2f081d
+++ b/usr/share/rear/layout/save/default/600_snapshot_files.sh
2f081d
@@ -3,7 +3,8 @@ if [ "$WORKFLOW" = "checklayout" ] ; then
2f081d
     return 0
2f081d
 fi
2f081d
 
2f081d
-config_files=()
2f081d
+local obj
2f081d
+local config_files=()
2f081d
 for obj in "${CHECK_CONFIG_FILES[@]}" ; do
2f081d
     if [ -d "$obj" ] ; then
2f081d
         config_files+=( $( find "$obj" -type f ) )