|
|
|
let RUN_IN_CHROOT = true;
|
|
|
|
|
|
|
|
def set_keymap [keymap: string] {
|
|
|
|
debug $"Setting keymap to ($keymap)"
|
|
|
|
touch /etc/vconsole.conf
|
|
|
|
$"\nKEYMAP=($keymap)" | save -a /etc/vconsole.conf
|
|
|
|
}
|
|
|
|
|
|
|
|
def set_timezone [timezone: string] {
|
|
|
|
debug $"Setting timezone to ($timezone)"
|
|
|
|
run ln -sf $"/usr/share/zoneinfo/($timezone)" /etc/localtime
|
|
|
|
run hwclock --systohc
|
|
|
|
}
|
|
|
|
|
|
|
|
def set_locales [locales] {
|
|
|
|
debug $"Setting locales to ($locales)"
|
|
|
|
mut new_locales = $locales
|
|
|
|
|
|
|
|
if ($new_locales | length) == 0 {
|
|
|
|
warn "No locale configured. Defaulting to en_US.UTF_8"
|
|
|
|
# set a default locale
|
|
|
|
$new_locales = ["en_US.UTF-8 UTF-8"]
|
|
|
|
"LANG=en_US.UTF-8" | save -f /etc/locale.conf
|
|
|
|
} else {
|
|
|
|
# save the first locale as the leading one
|
|
|
|
let first_locale = ($new_locales.0 | split row " " | get 0)
|
|
|
|
$"LANG=($first_locale)" | save -f /etc/locale.conf
|
|
|
|
}
|
|
|
|
|
|
|
|
$new_locales | each {|$locale|
|
|
|
|
let locale_parts = ($locale | split row " ")
|
|
|
|
let locale_name = $locale_parts.0
|
|
|
|
let encoding = $locale_parts.1
|
|
|
|
$"($locale_name) ($encoding)\n" | save -a /etc/locale.gen
|
|
|
|
}
|
|
|
|
run locale-gen
|
|
|
|
}
|
|
|
|
|
|
|
|
# Applies all system changes of `configure-locale`
|
|
|
|
def main [cfg] {
|
|
|
|
debug $"Configuring locale with config ($cfg)"
|
|
|
|
set_keymap $cfg.keymap
|
|
|
|
set_timezone $cfg.timezone
|
|
|
|
set_locales $cfg.locale
|
|
|
|
|
|
|
|
info "Locale configured"
|
|
|
|
}
|