]> git.ipfire.org Git - people/ms/bricklayer.git/commitdiff
disks: Fix automatic disk selection in unattended mode
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 9 May 2022 16:48:50 +0000 (16:48 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 9 May 2022 16:48:50 +0000 (16:48 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/python/__init__.py
src/python/disk.py
src/python/step.py

index 2dcceb201b6d3bd81d75cf1f0a5322222fa80e75..8966df186efc64b66ebc4825b5d41b13a5961930 100644 (file)
@@ -82,7 +82,7 @@ class Bricklayer(object):
                # Hardware
                self.disks = disk.Disks(self)
                for path in disks:
-                       self.disks.add_disk(path)
+                       self.disks.add_disk(path, selected=True)
 
                # Initialise the text user interface
                self.tui = tui.Tui(self)
@@ -98,6 +98,7 @@ class Bricklayer(object):
                step.UnattendedWarning,
                step.Welcome,
                timezones.SelectTimezone,
+               disk.UnattendedSelectDisk,
                disk.SelectDisk,
                disk.CalculatePartitionLayout,
                step.RootPassword,
index f56fe4089db13104fe8238f12289b6f421c471d5..935a85660953c348d508150fa709cad4167b8a6c 100644 (file)
@@ -53,7 +53,9 @@ class Disks(object):
                """
                        Scans for all disks
                """
-               self.disks.clear()
+               # Don't scan for disks if already done
+               if self.disks:
+                       return
 
                log.debug("Scanning for disks...")
 
@@ -69,7 +71,7 @@ class Disks(object):
                # Sort them alphabetically
                self.disks.sort()
 
-       def add_disk(self, path):
+       def add_disk(self, path, selected=False):
                """
                        Adds the disk at path
                """
@@ -88,6 +90,10 @@ class Disks(object):
                disk = Disk(self.bricklayer, path)
                self.disks.append(disk)
 
+               # Select this disk
+               if selected:
+                       disk.selected = True
+
                return disk
 
        def _losetup(self, path):
@@ -410,6 +416,33 @@ class Partition(object):
                self.bricklayer.command(command)
 
 
+class UnattendedSelectDisk(step.UnattendedStep):
+       """
+               Scans for any disks
+       """
+       def run(self):
+               # Nothing to do if disks have already been selected on the CLI
+               if self.bricklayer.disks.selected:
+                       return
+
+               # Scan for disks
+               self.bricklayer.disks.scan()
+
+               # End here if we could not find any disks
+               if not self.bricklayer.disks.supported:
+                       self.tui.error(
+                               _("No Disks Found"),
+                               _("No supported disks were found")
+                       )
+
+                       raise InstallAbortedError("No disks found")
+
+               # Automatically select the first disk
+               for disk in self.bricklayer.disks.supported:
+                       disk.selected = True
+                       break
+
+
 class SelectDisk(step.InteractiveStep):
        """
                Ask the user which disk(s) to use for the installation process
index 3d2417b4b76b05b2ec9abc24dbbdb64298120a2e..53b8f9f4f59e6ee6b8e77af7106fbe488d2cd280 100644 (file)
@@ -117,6 +117,16 @@ class InteractiveStep(Step):
                return not self.bricklayer.unattended
 
 
+class UnattendedStep(Step):
+       """
+               A convenience handler that only runs this step in unattended mode
+       """
+       @property
+       def enabled(self):
+               # Enable only in unattended mode
+               return self.bricklayer.unattended
+
+
 class Welcome(InteractiveStep):
        """
                Shows a very warm welcome message to the user