[4/4] wic: Restore compatibility with old distros

Message ID 20240508143801.557383-5-amikan@ilbers.de
State Superseded, archived
Headers show
Series Update WIC to the latest revision | expand

Commit Message

Anton Mikanovich May 8, 2024, 2:38 p.m. UTC
After update of WIC it requires sfdisk to support --disk-id command,
which is false for Debian Buster and Ubuntu Focal.
Do not try to set disk identifier for those distro versions to keep
them buildable but with lack of reproducibility.

This hack should be removed after deprecation of Buster and Focal.

Signed-off-by: Anton Mikanovich <amikan@ilbers.de>
---
 scripts/lib/wic/plugins/imager/direct.py | 12 ++++++++++++
 1 file changed, 12 insertions(+)

Patch

diff --git a/scripts/lib/wic/plugins/imager/direct.py b/scripts/lib/wic/plugins/imager/direct.py
index 33a869ec..a65ae36a 100644
--- a/scripts/lib/wic/plugins/imager/direct.py
+++ b/scripts/lib/wic/plugins/imager/direct.py
@@ -530,6 +530,13 @@  class PartitionedImage():
         exec_native_cmd("parted -s %s mklabel %s" % (device, ptable_format),
                         self.native_sysroot)
 
+    def _sfdisk_supports_disk_id(self):
+        ret, help_out = exec_native_cmd("sfdisk --help", self.native_sysroot)
+        if 'disk-id' not in help_out:
+            logger.warn("Current sfdisk version DOES NOT support changing disk ID")
+            return False
+        return True
+
     def _write_disk_guid(self):
         if self.ptable_format in ('gpt', 'gpt-hybrid'):
             if os.getenv('SOURCE_DATE_EPOCH'):
@@ -537,6 +544,11 @@  class PartitionedImage():
             else:
                 self.disk_guid = uuid.uuid4()
 
+            # Backport compatibility for Debian Buster and Ubuntu Focal
+            if not self._sfdisk_supports_disk_id():
+                logger.warn("Disk identifier can't be set, reproducibility is broken!")
+                return
+
             logger.debug("Set disk guid %s", self.disk_guid)
             sfdisk_cmd = "sfdisk --disk-id %s %s" % (self.path, self.disk_guid)
             exec_native_cmd(sfdisk_cmd, self.native_sysroot)