Blame SOURCES/rear-bz2083272.patch

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