add set locale and keyboard layout properly

axtloss/rework-partitioning
axtlos 2 years 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) { pub fn set_timezone(timezone: &str) {
exec_eval( 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( exec_chroot(
"ln", "ln",
vec![ vec![
@ -27,6 +24,11 @@ pub fn set_locale(locale: String) {
files::append_file("/mnt/etc/locale.gen", "en_US.UTF-8 UTF-8"), files::append_file("/mnt/etc/locale.gen", "en_US.UTF-8 UTF-8"),
"add en_US.UTF-8 UTF-8 to locale.gen", "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) { for i in (0..locale.split(' ').count()).step_by(2) {
files_eval( files_eval(
files::append_file( files::append_file(
@ -39,16 +41,21 @@ pub fn set_locale(locale: String) {
), ),
"add locales to locale.gen", "add locales to locale.gen",
); );
} if locale.split(' ').collect::<Vec<&str>>()[i] != "en_US.UTF-8" {
exec_eval(exec_chroot("locale-gen", vec![]), "generate locales");
files::create_file("/mnt/etc/locale.conf");
files_eval( files_eval(
files::append_file("/mnt/etc/locale.conf", "LANG=en_US.UTF-8"), files::sed_file(
"edit locale.conf", "/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");
} }
pub fn set_keyboard(keyboard: &str) { pub fn set_keyboard(keyboard: &str, variant: &str) {
files::create_file("/mnt/etc/vconsole.conf"); files::create_file("/mnt/etc/vconsole.conf");
files_eval( files_eval(
files::append_file( files::append_file(
@ -57,4 +64,31 @@ pub fn set_keyboard(keyboard: &str) {
), ),
"set keyboard layout", "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 { struct Locale {
locale: Vec<String>, locale: Vec<String>,
keymap: String, keymap: String,
variant: String,
timezone: String, timezone: String,
} }
@ -124,7 +125,7 @@ pub fn read_config(configpath: PathBuf) {
log::info!("Using keymap : {}", config.locale.keymap); log::info!("Using keymap : {}", config.locale.keymap);
log::info!("Setting timezone : {}", config.locale.timezone); log::info!("Setting timezone : {}", config.locale.timezone);
locale::set_locale(config.locale.locale.join(" ")); 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()); locale::set_timezone(config.locale.timezone.as_str());
println!(); println!();
log::info!("Hostname : {}", config.networking.hostname); log::info!("Hostname : {}", config.networking.hostname);

Loading…
Cancel
Save