diff --git a/src/stages/install/mod.rs b/src/stages/install/mod.rs index b8145e2..5f8bf75 100644 --- a/src/stages/install/mod.rs +++ b/src/stages/install/mod.rs @@ -18,7 +18,7 @@ Actual installation script. */ -use std::path::Path; +use std::{fs, path::Path}; use crate::{ kira_disk_layout::{self, BlkDev, FSType, PartInfo, PartLayout, PartRole}, @@ -43,6 +43,8 @@ const MNT_DIR: &str = "/mnt/inst_root"; const ROOT_PARTLABEL_DEV: &str = "/dev/disk/by-partlabel/bee-root"; const EFI_PARTLABLE_DEV: &str = "/dev/disk/by-partlabel/bee-efi"; const SWAP_PARTLABLE_DEV: &str = "/dev/disk/by-partlabel/bee-swap"; +const CONSOLE_FONT: &str = "ter-v24n"; + /// /// List of packages for desktop (elogind-dinit no need for headles system) /// @@ -246,41 +248,75 @@ fn init_disk(part_layout: &PartLayout, mnt_dir: &str) -> Result<(), ExecCommandE Ok(()) } +/// +/// Writes locales from loc_lines to locale.gen file passed in loc_gen_file_path +/// Checks if locales from loc_lines defined in locale.gen +/// +fn locale_gen_write( + loc_gen_file_path: &str, + loc_lines: &Vec, +) -> Result<(), ExecCommandError> { + use std::fs::OpenOptions; + use std::io::Write; + + // need this to check for locales existance + let loc_gen_content = fs::read_to_string(loc_gen_file_path)?; + + // Open locale.gen file in append mode + let mut locale_file = OpenOptions::new() + .create(false) + .append(true) + .open(loc_gen_file_path)?; + + writeln!( + locale_file, + "\n# Next lines is autogenerated by Kira Installer" + )?; + for loc in loc_lines { + // check if locale defined + if loc_gen_content.contains(loc) { + writeln!(locale_file, "{}", loc)?; + log::info!("Added ({}) locale.", loc); + } else { + // if not defined write comment on this matter + log::info!("Locale ({}) is not defined in locale.gen file.", loc); + writeln!(locale_file, "# Missing: {}", loc)?; + } + } + + Ok(()) +} + fn config_stuff(k_config: KiraConfig) -> Result<(), ExecCommandError> { use std::fs::OpenOptions; use std::io::Write; - const LOCALES_GEN_FILE_NAME: &str = "/etc/locale.gen"; + let loc_gen_fn = format!("{}/etc/locale.gen", MNT_DIR); log::info!("Generating fstab..."); kira_system::fstabgen(MNT_DIR)?; - log::info!("Configuring locales..."); - let loc_data = k_config.res_locale.as_ref().unwrap(); { + let loc_data = k_config.res_locale.as_ref().unwrap(); let lang_line = loc_data.lang_locale.locale_gen_line(); let formats_line = loc_data.formats_locale.locale_gen_line(); - // Open locale.gen file in append mode - let mut locale_file = OpenOptions::new() - .create(false) - .append(true) - .open(LOCALES_GEN_FILE_NAME)?; - - writeln!(locale_file, "\n# Next lines is autogenerated by kira-installer")?; - // write lang - writeln!(locale_file, "{}", &lang_line)?; - // write formats - if lang_line != formats_line { - writeln!(locale_file, "{}", &formats_line)?; - } + let mut loc_lines: Vec = Vec::new(); // if selected locale is not en, we will add en_US.UTF-8 UTF-8 to locales.gen if !lang_line.starts_with("en_") && !formats_line.starts_with("en_") { - writeln!(locale_file, "en_US.UTF-8 UTF-8")?; + loc_lines.push("en_US.UTF-8 UTF-8".into()); } + // write formats locale if it is different from lang locale + if lang_line != formats_line { + loc_lines.push(formats_line); + } + loc_lines.push(lang_line); + + locale_gen_write(&loc_gen_fn, &loc_lines)?; } kira_system::exec_cmd_chroot(MNT_DIR, "locale-gen", &vec![])?; + log::info!("Kayboard conf: {}", k_config.res_keyboard.as_ref().unwrap()); //Simpler said.. it adds missing values for XKBLAYOUT=XX //and XKBMODEL=XXXX to /etc/vconsole.conf diff --git a/src/stages/keyboard/mod.rs b/src/stages/keyboard/mod.rs index dc0c399..628e405 100644 --- a/src/stages/keyboard/mod.rs +++ b/src/stages/keyboard/mod.rs @@ -130,6 +130,12 @@ pub struct KeyboardStageResult { pub keyboard_layout: KeyboarLayout, } +impl std::fmt::Display for KeyboardStageResult { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "keyboard_model: {} | keyboard_layout: {}", &self.keyboard_model, &self.keyboard_layout) + } +} + #[derive(Debug, Clone)] pub enum Message { SelectKeyboardModel(KeyboarModel), diff --git a/src/stages/locale/mod.rs b/src/stages/locale/mod.rs index 7b70542..d0cf76f 100644 --- a/src/stages/locale/mod.rs +++ b/src/stages/locale/mod.rs @@ -59,13 +59,7 @@ impl LocaleData { // creates text to be appended to locale.gen file // in case of C locale outputs empty string pub fn locale_gen_line(&self) -> String { - if self.code == "C.UTF-8" { - String::new() - } - else { - format!("{} {}", &self.code, &self.charset) - } - + format!("{} {}", &self.code, &self.charset) } }