pmbootstrap init: add locale selection (MR 2004)

Adds a list of locales user can choose from on init step.
If locale isn't default, then "lang" package is installed
and LANG is changed to the chosen locale.
This commit is contained in:
HenriDellal 2020-12-09 23:37:28 +03:00 committed by Alexey Min
parent 2247fc5aad
commit 196186df24
No known key found for this signature in database
GPG Key ID: 0B19D2A65870B448
3 changed files with 45 additions and 0 deletions

View File

@ -51,6 +51,7 @@ config_keys = ["aports",
"jobs",
"kernel",
"keymap",
"locale",
"nonfree_firmware",
"nonfree_userland",
"ssh_keys",
@ -84,6 +85,7 @@ defaults = {
"jobs": str(multiprocessing.cpu_count() + 1),
"kernel": "stable",
"keymap": "",
"locale": "C.UTF-8",
"log": "$WORK/log.txt",
"mirror_alpine": "http://dl-2.alpinelinux.org/alpine/",
"mirrors_postmarketos": ["http://mirror.postmarketos.org/postmarketos/"],
@ -109,6 +111,26 @@ is_interactive = sys.stdout.isatty() and \
sys.stdin.isatty()
# List of available locales taken from musl-locales package; see
# https://pkgs.alpinelinux.org/contents?name=musl-locales
locales = [
"C.UTF-8",
"ch_DE.UTF-8",
"de_CH.UTF-8",
"de_DE.UTF-8",
"en_GB.UTF-8",
"en_US.UTF-8",
"es_ES.UTF-8",
"fr_FR.UTF-8",
"it_IT.UTF-8",
"nb_NO.UTF-8",
"nl_NL.UTF-8",
"pt_BR.UTF-8",
"ru_RU.UTF-8",
"sv_SE.UTF-8"
]
#
# CHROOT
#

View File

@ -427,6 +427,16 @@ def ask_build_pkgs_on_install(args):
default=args.build_pkgs_on_install)
def ask_for_locale(args):
locales = pmb.config.locales
logging.info(f"Available locales ({len(locales)}): {', '.join(locales)}")
return pmb.helpers.cli.ask(args, "Choose default locale for installation",
default=args.locale,
lowercase_answer=False,
validation_regex="|".join(locales),
complete=locales)
def frontend(args):
require_programs()
@ -483,6 +493,9 @@ def frontend(args):
# Configure timezone info
cfg["pmbootstrap"]["timezone"] = ask_for_timezone(args)
# Locale
cfg["pmbootstrap"]["locale"] = ask_for_locale(args)
# Hostname
cfg["pmbootstrap"]["hostname"] = ask_for_hostname(args, device)

View File

@ -678,6 +678,7 @@ def create_device_rootfs(args, step, steps):
logging.info(f'*** ({step}/{steps}) CREATE DEVICE ROOTFS ("{args.device}")'
' ***')
suffix = f"rootfs_{args.device}"
# Create user before installing packages, so post-install scripts of
# pmaports can figure out the username (legacy reasons: pmaports#820)
set_user(args)
@ -698,6 +699,9 @@ def create_device_rootfs(args, step, steps):
install_packages += args.extra_packages.split(",")
if args.add:
install_packages += args.add.split(",")
locale_is_set = (args.locale != pmb.config.defaults["locale"])
if locale_is_set:
install_packages += ["lang", "musl-locales"]
pmb.helpers.repo.update(args, args.deviceinfo["arch"])
@ -725,6 +729,12 @@ def create_device_rootfs(args, step, steps):
# Set timezone
pmb.chroot.root(args, ["setup-timezone", "-z", args.timezone], suffix)
# Set locale
if locale_is_set:
pmb.chroot.root(args, ["sed", "-i",
f"s/LANG=C.UTF-8/LANG={args.locale}/",
"/etc/profile.d/locale.sh"], suffix)
# Set the hostname as the device name
setup_hostname(args)