diff --git a/README.md b/README.md index 370e81a2f9..b6d5708503 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ [![Lint Python and Find Syntax Errors](https://github.com/archlinux/archinstall/actions/workflows/flake8.yaml/badge.svg)](https://github.com/archlinux/archinstall/actions/workflows/flake8.yaml) Just another guided/automated [Arch Linux](https://wiki.archlinux.org/index.php/Arch_Linux) installer with a twist. -The installer also doubles as a python library to install Arch Linux and manage services, packages, and other things inside the installed system *(Usually from a live medium)*. +The installer also doubles as a python library to install Arch Linux and manage services, packages, and other things inside the installed system *(Usually from a live medium or from an existing installation)*. * archinstall [discord](https://discord.gg/aDeMffrxNg) server * archinstall [#archinstall:matrix.org](https://matrix.to/#/#archinstall:matrix.org) Matrix channel diff --git a/archinstall/__init__.py b/archinstall/__init__.py index ebba9510f7..f96c840980 100644 --- a/archinstall/__init__.py +++ b/archinstall/__init__.py @@ -13,6 +13,7 @@ from archinstall.lib.packages.packages import check_package_upgrade from archinstall.tui.ui.components import tui as ttui +from .lib.general import running_from_host from .lib.hardware import SysInfo from .lib.output import FormattedOutput, debug, error, info, log, warn from .lib.pacman import Pacman @@ -110,6 +111,12 @@ def main() -> int: info(new_version) time.sleep(3) + if running_from_host(): + # log which mode we are using + debug('Running from Host (H2T Mode)...') + else: + debug('Running from ISO (Live Mode)...') + script = arch_config_handler.get_script() mod_name = f'archinstall.scripts.{script}' diff --git a/archinstall/lib/general.py b/archinstall/lib/general.py index 66d8ee03dd..057f94a220 100644 --- a/archinstall/lib/general.py +++ b/archinstall/lib/general.py @@ -27,6 +27,17 @@ _VT100_ESCAPE_REGEX_BYTES = _VT100_ESCAPE_REGEX.encode() +def running_from_host() -> bool: + """ + Check if running from an installed system. + + Returns True if running from installed system (host mode) for host-to-target install. + Returns False if /run/archiso exists (ISO mode). + """ + is_host = not Path('/run/archiso').exists() + return is_host + + def generate_password(length: int = 64) -> str: haystack = string.printable # digits, ascii_letters, punctuation (!"#$[] etc) and whitespace return ''.join(secrets.choice(haystack) for _ in range(length)) @@ -46,7 +57,7 @@ def clear_vt100_escape_codes_from_str(data: str) -> str: return re.sub(_VT100_ESCAPE_REGEX, '', data) -def jsonify(obj: object, safe: bool = True) -> object: +def jsonify(obj: Any, safe: bool = True) -> Any: """ Converts objects into json.dumps() compatible nested dictionaries. Setting safe to True skips dictionary keys starting with a bang (!) @@ -84,7 +95,7 @@ class JSON(json.JSONEncoder, json.JSONDecoder): """ @override - def encode(self, o: object) -> str: + def encode(self, o: Any) -> str: return super().encode(jsonify(o)) @@ -94,7 +105,7 @@ class UNSAFE_JSON(json.JSONEncoder, json.JSONDecoder): """ @override - def encode(self, o: object) -> str: + def encode(self, o: Any) -> str: return super().encode(jsonify(o, safe=False)) diff --git a/archinstall/lib/locale/utils.py b/archinstall/lib/locale/utils.py index e1e25a0fc4..f89b865d31 100644 --- a/archinstall/lib/locale/utils.py +++ b/archinstall/lib/locale/utils.py @@ -1,5 +1,5 @@ from ..exceptions import ServiceException, SysCallError -from ..general import SysCommand +from ..general import SysCommand, running_from_host from ..output import error @@ -79,6 +79,11 @@ def get_kb_layout() -> str: def set_kb_layout(locale: str) -> bool: + if running_from_host(): + # Skip when running from host - no need to change host keymap + # The target installation keymap is set via installer.set_keyboard_language() + return True + if len(locale.strip()): if not verify_keyboard_layout(locale): error(f'Invalid keyboard locale specified: {locale}')