Skip to content

Commit

Permalink
Uncomment /etc/locale.gen entry and use first column for LANG var…
Browse files Browse the repository at this point in the history
…iable (#1939)
  • Loading branch information
codefiles authored Jul 19, 2023
1 parent e41900a commit 69c37e7
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions archinstall/lib/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ def set_hostname(self, hostname: str, *args :str, **kwargs :str) -> None:
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
Expand All @@ -386,15 +386,32 @@ def set_locale(self, locale_config: LocaleConfiguration):
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:
Expand Down

0 comments on commit 69c37e7

Please sign in to comment.