Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions archinstall/lib/boot.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
from __future__ import annotations

import time
from collections.abc import Iterator
from types import TracebackType
from typing import Self
from typing import TYPE_CHECKING, ClassVar, Self

from .exceptions import SysCallError
from .general import SysCommand, SysCommandWorker, locate_binary
from .installer import Installer
from .output import error
from .storage import storage

if TYPE_CHECKING:
from .installer import Installer


class Boot:
_active_boot: ClassVar[Self | None] = None

def __init__(self, installation: Installer):
self.instance = installation
self.container_name = 'archinstall'
self.session: SysCommandWorker | None = None
self.ready = False

def __enter__(self) -> Self:
if (existing_session := storage.get('active_boot', None)) and existing_session.instance != self.instance:
if Boot._active_boot and Boot._active_boot.instance != self.instance:
raise KeyError('Archinstall only supports booting up one instance and another session is already active.')

if existing_session:
self.session = existing_session.session
self.ready = existing_session.ready
if Boot._active_boot:
self.session = Boot._active_boot.session
self.ready = Boot._active_boot.ready
else:
# '-P' or --console=pipe could help us not having to do a bunch
# of os.write() calls, but instead use pipes (stdin, stdout and stderr) as usual.
Expand All @@ -46,7 +51,7 @@ def __enter__(self) -> Self:
self.ready = True
break

storage['active_boot'] = self
Boot._active_boot = self
return self

def __exit__(self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None) -> None:
Expand Down Expand Up @@ -75,7 +80,7 @@ def __exit__(self, exc_type: type[BaseException] | None, exc_value: BaseExceptio
shutdown_exit_code = shutdown.exit_code

if self.session and (self.session.exit_code == 0 or shutdown_exit_code == 0):
storage['active_boot'] = None
Boot._active_boot = None
else:
session_exit_code = self.session.exit_code if self.session else -1

Expand Down
5 changes: 1 addition & 4 deletions archinstall/lib/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from archinstall.tui.curses_menu import Tui

from .args import arch_config_handler
from .boot import Boot
from .exceptions import DiskError, HardwareIncompatibilityError, RequirementError, ServiceException, SysCallError
from .general import SysCommand, run
from .hardware import SysInfo
Expand Down Expand Up @@ -1977,8 +1978,6 @@ def set_keyboard_language(self, language: str) -> bool:

# In accordance with https://github.com/archlinux/archinstall/issues/107#issuecomment-841701968
# Setting an empty keymap first, allows the subsequent call to set layout for both console and x11.
from .boot import Boot

with Boot(self) as session:
os.system('systemd-run --machine=archinstall --pty localectl set-keymap ""')

Expand All @@ -2005,8 +2004,6 @@ def set_x11_keyboard_language(self, language: str) -> bool:
error(f'Invalid x11-keyboard language specified: {language}')
return False

from .boot import Boot

with Boot(self) as session:
session.SysCommand(['localectl', 'set-x11-keymap', '""'])

Expand Down
2 changes: 0 additions & 2 deletions archinstall/lib/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@
from typing import TYPE_CHECKING, NotRequired, TypedDict

if TYPE_CHECKING:
from archinstall.lib.boot import Boot
from archinstall.lib.installer import Installer


class _StorageDict(TypedDict):
active_boot: NotRequired['Boot | None']
installation_session: NotRequired['Installer']


Expand Down