From fda7a3fb09b42e59a4d3ab2098229145231a0f29 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sun, 15 May 2022 21:55:37 +0200 Subject: [PATCH 1/4] This allows us to set LANG= in vconsole for keymap negotiation during crypt-unlock --- archinstall/__init__.py | 6 +++++- archinstall/lib/installer.py | 5 +++++ archinstall/lib/systemd.py | 8 ++++++++ examples/guided.py | 4 ++++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/archinstall/__init__.py b/archinstall/__init__.py index aa644d48b2..6d0853c259 100644 --- a/archinstall/__init__.py +++ b/archinstall/__init__.py @@ -32,7 +32,11 @@ from .lib.profiles import * from .lib.services import * from .lib.storage import * -from .lib.systemd import * +from .lib.systemd import ( + localectl_status, + Boot, + Ini +) from .lib.user_interaction import * from .lib.menu import Menu from .lib.menu.list_manager import ListManager diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py index b0f7ac3272..dd7930559d 100644 --- a/archinstall/lib/installer.py +++ b/archinstall/lib/installer.py @@ -1075,6 +1075,11 @@ def set_keyboard_language(self, language: str) -> bool: else: self.log('Keyboard language was not changed from default (no language specified).', fg="yellow", level=logging.INFO) + # This needs to be explicitly set in some cases due to https://github.com/archlinux/archinstall/issues/596 + if LANG := localectl_status().get('x11_layout'): + with open(f"{self.target}/etc/vconsole.conf", "a") as vconsole: + vconsole.write(f"LANG={LANG}\n") + return True def set_x11_keyboard_language(self, language: str) -> bool: diff --git a/archinstall/lib/systemd.py b/archinstall/lib/systemd.py index 417870da49..55e716ba3c 100644 --- a/archinstall/lib/systemd.py +++ b/archinstall/lib/systemd.py @@ -138,3 +138,11 @@ def SysCommandWorker(self, cmd: list, *args, **kwargs) -> SysCommandWorker: cmd[0] = locate_binary(cmd[0]) return SysCommandWorker(["systemd-run", f"--machine={self.container_name}", "--pty", *cmd], *args, **kwargs) + +def localectl_status(): + result = {} + for line in SysCommand(["localectl", "status"]): + key, value = line.strip().decode('UTF-8').split(': ', 1) + result[key.lower().replace(' ', '_')] = value + + return result \ No newline at end of file diff --git a/examples/guided.py b/examples/guided.py index f104b7e36b..29d6e9a773 100644 --- a/examples/guided.py +++ b/examples/guided.py @@ -254,6 +254,10 @@ def perform_installation(mountpoint): if archinstall.arguments.get('custom-commands', None): archinstall.run_custom_user_commands(archinstall.arguments['custom-commands'], installation) + # After certain locale's has been set, this needs + # to be re-run to avoid issues such as https://github.com/archlinux/archinstall/issues/596 + installation.mkinitcpio('-P') + installation.log("For post-installation tips, see https://wiki.archlinux.org/index.php/Installation_guide#Post-installation", fg="yellow") if not archinstall.arguments.get('silent'): prompt = str(_('Would you like to chroot into the newly created installation and perform post-installation configuration?')) From 15ed7570825296666966b3f8a0057c0aa08c4a4b Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sun, 15 May 2022 21:59:35 +0200 Subject: [PATCH 2/4] Adding missing import --- archinstall/lib/installer.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py index dd7930559d..a86347e5f2 100644 --- a/archinstall/lib/installer.py +++ b/archinstall/lib/installer.py @@ -1056,6 +1056,8 @@ def create_file(self, filename :str, owner :Optional[str] = None) -> Installatio return InstallationFile(self, filename, owner) def set_keyboard_language(self, language: str) -> bool: + from .systemd import localectl_status + log(f"Setting keyboard language to {language}", level=logging.INFO) if len(language.strip()): if not verify_keyboard_layout(language): From 6a62aa4d3afd2d39748f626e1fdd277d6cfc7d68 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sun, 15 May 2022 22:12:13 +0200 Subject: [PATCH 3/4] Making sure language and encoding is dynamic when setting vconsole parameters. --- archinstall/lib/installer.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py index a86347e5f2..b57119207e 100644 --- a/archinstall/lib/installer.py +++ b/archinstall/lib/installer.py @@ -1057,7 +1057,7 @@ def create_file(self, filename :str, owner :Optional[str] = None) -> Installatio def set_keyboard_language(self, language: str) -> bool: from .systemd import localectl_status - + log(f"Setting keyboard language to {language}", level=logging.INFO) if len(language.strip()): if not verify_keyboard_layout(language): @@ -1080,7 +1080,12 @@ def set_keyboard_language(self, language: str) -> bool: # This needs to be explicitly set in some cases due to https://github.com/archlinux/archinstall/issues/596 if LANG := localectl_status().get('x11_layout'): with open(f"{self.target}/etc/vconsole.conf", "a") as vconsole: - vconsole.write(f"LANG={LANG}\n") + with open(f'{self.target}/etc/locale.conf', 'r') as locale: + locale_data = locale.read() + + # TODO: A bit of a hack to convert LANG=en_US.UTF-8 into just US.UTF-8 + locale_and_encoding = locale_data.split('=', 1)[1].split('_', 1)[1].split('.', 1)[0] + vconsole.write(f"LANG={LANG}_{locale_and_encoding}\n") return True From d82175abcde6684a4cb648c354436bc6ea63e632 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sun, 15 May 2022 22:16:10 +0200 Subject: [PATCH 4/4] Forgot the encoding part. --- archinstall/lib/installer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py index b57119207e..5afa10bb35 100644 --- a/archinstall/lib/installer.py +++ b/archinstall/lib/installer.py @@ -1084,7 +1084,7 @@ def set_keyboard_language(self, language: str) -> bool: locale_data = locale.read() # TODO: A bit of a hack to convert LANG=en_US.UTF-8 into just US.UTF-8 - locale_and_encoding = locale_data.split('=', 1)[1].split('_', 1)[1].split('.', 1)[0] + locale_and_encoding = locale_data.split('=', 1)[1].split('_', 1)[1] vconsole.write(f"LANG={LANG}_{locale_and_encoding}\n") return True