]> git.ipfire.org Git - people/ms/bricklayer.git/commitdiff
Add debug shell
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 12 May 2021 10:54:12 +0000 (10:54 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 12 May 2021 10:59:14 +0000 (10:59 +0000)
This shell can be accessed by typing Ctrl-Z and lays the installer in
the background and opens a shell.

This is very useful on serial consoles where there is no TTYs that can
be changed to for debugging.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/python/__init__.py
src/python/tui.py

index ed772797f66c22d55f327d5e812cd02a3efce836..7a7e32da25b2de457d337b8a1bcba4d1119b00e6 100644 (file)
@@ -48,6 +48,7 @@ class Bricklayer(object):
        def __init__(self, arch, first_install=False, debug=False, unattended=False, disks=[]):
                self.arch = arch
                self.first_install = first_install
+               self.debug = debug
                self.unattended = unattended
 
                # Enable debug logging
@@ -202,19 +203,31 @@ class Bricklayer(object):
                with open("/etc/os-release") as f:
                        return util.config_read(f)
 
-       def command(self, command, error_ok=False):
+       def command(self, command, error_ok=False, interactive=False):
                """
                        Runs a command in a shell environment
                """
                log.debug("Running command: %s" % " ".join(command))
 
+               args = {}
+
+               if not interactive:
+                       args.update({
+                               "stdout" : subprocess.PIPE,
+                               "stderr" : subprocess.STDOUT,
+                       })
+
                # Execute the command
-               p = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+               p = subprocess.run(command, **args)
 
                # Check the return code (raises CalledProcessError on non-zero)
                if not error_ok:
                        p.check_returncode()
 
+               # There is no output in interactive mode
+               if interactive:
+                       return
+
                # Decode output
                output = p.stdout.decode()
 
index 4988b691ff7bc12445a29f8861a5db9d082bc295..8a088ebc6a4cb9c6316362ddebe69dd5a27a5d26 100644 (file)
@@ -56,6 +56,24 @@ class Tui(object):
                # Wipe the screen
                self._finish_screen()
 
+       def shell(self):
+               """
+                       Opens a debug shell
+               """
+               if not self.screen:
+                       return
+
+               # Hide the installer
+               self.screen.suspend()
+
+               # Show a message how to return to the installer
+               print(_("Type <exit> to return to the install program\n"))
+
+               self.bricklayer.command(["/bin/bash", "--login"], interactive=True, error_ok=True)
+
+               # Bring back the installer
+               self.screen.resume()
+
        def refresh(self):
                """
                        Refreshes what is written on the screen
@@ -75,6 +93,12 @@ class Tui(object):
                # Setup helpline
                helpline = []
 
+               # Show how to get to shell in debug mode
+               if self.bricklayer.debug:
+                       helpline.append(
+                               _("<Ctrl-Z> Shell")
+                       )
+
                # Show key commands only when they are useful
                if not self.bricklayer.unattended:
                        helpline += (
@@ -88,6 +112,9 @@ class Tui(object):
                # Refresh the screen
                self.refresh()
 
+               # Set the suspend callback
+               self.screen.suspendCallback(self.shell)
+
        def _finish_screen(self):
                """
                        Cleanup screen