add set locale and keyboard layout properly

axtloss/rework-partitioning
axtlos 1 year ago
parent 7bad6e1c4c
commit 8b95bef9a9
No known key found for this signature in database
GPG Key ID: C08EB728CFA2DF4E

@ -3,9 +3,6 @@ use crate::internal::*;
pub fn set_timezone(timezone: &str) {
exec_eval(
// Remember this should run in a chroot
// not on the host, as linking to /mnt/usr/share/zoneinfo
// will mean you're gonna have a bad time
exec_chroot(
"ln",
vec![
@ -27,6 +24,11 @@ pub fn set_locale(locale: String) {
files::append_file("/mnt/etc/locale.gen", "en_US.UTF-8 UTF-8"),
"add en_US.UTF-8 UTF-8 to locale.gen",
);
files::create_file("/mnt/etc/locale.conf");
files_eval(
files::append_file("/mnt/etc/locale.conf", "LANG=en_US.UTF-8"),
"edit locale.conf",
);
for i in (0..locale.split(' ').count()).step_by(2) {
files_eval(
files::append_file(
@ -39,16 +41,21 @@ pub fn set_locale(locale: String) {
),
"add locales to locale.gen",
);
if locale.split(' ').collect::<Vec<&str>>()[i] != "en_US.UTF-8" {
files_eval(
files::sed_file(
"/mnt/etc/locale.conf",
"en_US.UTF-8",
locale.split(' ').collect::<Vec<&str>>()[i]
),
format!("Set locale {} in /etc/locale.conf", locale.split(' ').collect::<Vec<&str>>()[i]).as_str()
);
}
}
exec_eval(exec_chroot("locale-gen", vec![]), "generate locales");
files::create_file("/mnt/etc/locale.conf");
files_eval(
files::append_file("/mnt/etc/locale.conf", "LANG=en_US.UTF-8"),
"edit locale.conf",
);
}
pub fn set_keyboard(keyboard: &str) {
pub fn set_keyboard(keyboard: &str, variant: &str) {
files::create_file("/mnt/etc/vconsole.conf");
files_eval(
files::append_file(
@ -57,4 +64,31 @@ pub fn set_keyboard(keyboard: &str) {
),
"set keyboard layout",
);
if variant.to_lowercase() == "normal" {
exec_eval(
exec::exec_chroot(
"gsettings",
vec![
"set".to_string(),
"org.gnome.desktop.input-sources".to_string(),
"sources".to_string(),
format!("[('xkb', '{keyboard})]")
],
),
"Set Keymap using gsettings"
);
} else {
exec_eval(
exec::exec_chroot(
"gsettings",
vec![
"set".to_string(),
"org.gnome.desktop.input-sources".to_string(),
"sources".to_string(),
format!("[('xkb', '{keyboard}+{variant})]")
],
),
"Set Keymap using gsettings"
);
}
}

@ -40,6 +40,7 @@ struct Bootloader {
struct Locale {
locale: Vec<String>,
keymap: String,
variant: String,
timezone: String,
}
@ -124,7 +125,7 @@ pub fn read_config(configpath: PathBuf) {
log::info!("Using keymap : {}", config.locale.keymap);
log::info!("Setting timezone : {}", config.locale.timezone);
locale::set_locale(config.locale.locale.join(" "));
locale::set_keyboard(config.locale.keymap.as_str());
locale::set_keyboard(config.locale.keymap.as_str(), config.locale.variant.as_str());
locale::set_timezone(config.locale.timezone.as_str());
println!();
log::info!("Hostname : {}", config.networking.hostname);

Loading…
Cancel
Save