Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcodefiles <11915375+codefiles@users.noreply.github.com>2023-07-19 02:49:40 -0400
committerGitHub <noreply@github.com>2023-07-19 08:49:40 +0200
commit69c37e7c79b8756e300438fd2d25f6d40db5e04b (patch)
treee138f0a30129e52827bebf0612f26c95437bee88
parente41900a25cfbf35e550863a8415a0c7a29c9e9b2 (diff)
Uncomment `/etc/locale.gen` entry and use first column for `LANG` variable (#1939)
-rw-r--r--archinstall/lib/installer.py25
1 files changed, 21 insertions, 4 deletions
diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py
index 8c5e7648..836b6b79 100644
--- a/archinstall/lib/installer.py
+++ b/archinstall/lib/installer.py
@@ -366,7 +366,7 @@ class Installer:
with open(f'{self.target}/etc/hostname', 'w') as fh:
fh.write(hostname + '\n')
- def set_locale(self, locale_config: LocaleConfiguration):
+ def set_locale(self, locale_config: LocaleConfiguration) -> bool:
modifier = ''
lang = locale_config.sys_lang
encoding = locale_config.sys_enc
@@ -386,15 +386,32 @@ class Installer:
modifier = f"@{modifier}"
# - End patch
- with open(f'{self.target}/etc/locale.gen', 'a') as fh:
- fh.write(f'{lang}.{encoding}{modifier} {encoding}\n')
+ locale_gen = self.target / 'etc/locale.gen'
+ locale_gen_lines = locale_gen.read_text().splitlines(True)
- (self.target / "etc" / "locale.conf").write_text(f'LANG={lang}.{encoding}{modifier}\n')
+ # A locale entry in /etc/locale.gen may or may not contain the encoding
+ # in the first column of the entry; check for both cases.
+ entry_re = re.compile(rf'#{lang}(\.{encoding})?{modifier} {encoding}')
+
+ for index, line in enumerate(locale_gen_lines):
+ if entry_re.match(line):
+ uncommented_line = line.removeprefix('#')
+ locale_gen_lines[index] = uncommented_line
+ locale_gen.write_text(''.join(locale_gen_lines))
+ lang_value = uncommented_line.split()[0]
+ break
+ else:
+ error(f"Invalid locale: language '{locale_config.sys_lang}', encoding '{locale_config.sys_enc}'")
+ return False
try:
SysCommand(f'/usr/bin/arch-chroot {self.target} locale-gen')
except SysCallError as e:
error(f'Failed to run locale-gen on target: {e}')
+ return False
+
+ (self.target / 'etc/locale.conf').write_text(f'LANG={lang_value}\n')
+ return True
def set_timezone(self, zone :str, *args :str, **kwargs :str) -> bool:
if not zone: