Skip to content

Commit 6b23eff

Browse files
authored
H2T (Host-to-target) installs and prevent host pollution (#3978)
* Add host-to-target (H2T) installation mode detection - Add running_from_host() function to detect if running from installed system vs ISO - Function checks for /run/archiso existence (ISO mode) vs host mode - Add clear logging of installation mode on startup - Skip keyboard layout changes when running from host system - Fix Pyright type error in jsonify() by using Any instead of object - Update README to mention installation from existing system This enables archinstall to be run from an existing Arch installation to perform host-to-target installs on other disks/partitions. * match existing style * rem debug * info -> debug
1 parent 810a50e commit 6b23eff

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
[![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)
77

88
Just another guided/automated [Arch Linux](https://wiki.archlinux.org/index.php/Arch_Linux) installer with a twist.
9-
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)*.
9+
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)*.
1010

1111
* archinstall [discord](https://discord.gg/aDeMffrxNg) server
1212
* archinstall [#archinstall:matrix.org](https://matrix.to/#/#archinstall:matrix.org) Matrix channel

archinstall/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from archinstall.lib.packages.packages import check_package_upgrade
1414
from archinstall.tui.ui.components import tui as ttui
1515

16+
from .lib.general import running_from_host
1617
from .lib.hardware import SysInfo
1718
from .lib.output import FormattedOutput, debug, error, info, log, warn
1819
from .lib.pacman import Pacman
@@ -110,6 +111,12 @@ def main() -> int:
110111
info(new_version)
111112
time.sleep(3)
112113

114+
if running_from_host():
115+
# log which mode we are using
116+
debug('Running from Host (H2T Mode)...')
117+
else:
118+
debug('Running from ISO (Live Mode)...')
119+
113120
script = arch_config_handler.get_script()
114121

115122
mod_name = f'archinstall.scripts.{script}'

archinstall/lib/general.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,17 @@
2727
_VT100_ESCAPE_REGEX_BYTES = _VT100_ESCAPE_REGEX.encode()
2828

2929

30+
def running_from_host() -> bool:
31+
"""
32+
Check if running from an installed system.
33+
34+
Returns True if running from installed system (host mode) for host-to-target install.
35+
Returns False if /run/archiso exists (ISO mode).
36+
"""
37+
is_host = not Path('/run/archiso').exists()
38+
return is_host
39+
40+
3041
def generate_password(length: int = 64) -> str:
3142
haystack = string.printable # digits, ascii_letters, punctuation (!"#$[] etc) and whitespace
3243
return ''.join(secrets.choice(haystack) for _ in range(length))
@@ -46,7 +57,7 @@ def clear_vt100_escape_codes_from_str(data: str) -> str:
4657
return re.sub(_VT100_ESCAPE_REGEX, '', data)
4758

4859

49-
def jsonify(obj: object, safe: bool = True) -> object:
60+
def jsonify(obj: Any, safe: bool = True) -> Any:
5061
"""
5162
Converts objects into json.dumps() compatible nested dictionaries.
5263
Setting safe to True skips dictionary keys starting with a bang (!)
@@ -84,7 +95,7 @@ class JSON(json.JSONEncoder, json.JSONDecoder):
8495
"""
8596

8697
@override
87-
def encode(self, o: object) -> str:
98+
def encode(self, o: Any) -> str:
8899
return super().encode(jsonify(o))
89100

90101

@@ -94,7 +105,7 @@ class UNSAFE_JSON(json.JSONEncoder, json.JSONDecoder):
94105
"""
95106

96107
@override
97-
def encode(self, o: object) -> str:
108+
def encode(self, o: Any) -> str:
98109
return super().encode(jsonify(o, safe=False))
99110

100111

archinstall/lib/locale/utils.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from ..exceptions import ServiceException, SysCallError
2-
from ..general import SysCommand
2+
from ..general import SysCommand, running_from_host
33
from ..output import error
44

55

@@ -79,6 +79,11 @@ def get_kb_layout() -> str:
7979

8080

8181
def set_kb_layout(locale: str) -> bool:
82+
if running_from_host():
83+
# Skip when running from host - no need to change host keymap
84+
# The target installation keymap is set via installer.set_keyboard_language()
85+
return True
86+
8287
if len(locale.strip()):
8388
if not verify_keyboard_layout(locale):
8489
error(f'Invalid keyboard locale specified: {locale}')

0 commit comments

Comments
 (0)