diff --git a/src/install/kernel.rs b/src/install/kernel.rs index afe37ce..5e27c7e 100644 --- a/src/install/kernel.rs +++ b/src/install/kernel.rs @@ -15,9 +15,16 @@ pub fn setup_mkinitcpio(conf: &DriveConfig) { ); // Set kernel cmdline - // TODO : Encryption support std::fs::create_dir_all("/mnt/etc/kernel").unwrap(); - std::fs::write("/mnt/etc/kernel/cmdline", format!("root={}", conf.root)).unwrap(); + + if conf.encryption.is_some() { + let block_uuid = find_uuid_by_dev(&conf.root).unwrap(); + std::fs::write("/mnt/etc/kernel/cmdline", + format!("rd.luks.options=timeout=30s rd.luks.name={block_uuid}=root root=/dev/mapper/root rw") + ).unwrap(); + } else { + std::fs::write("/mnt/etc/kernel/cmdline", format!("root={}", conf.root)).unwrap(); + } // TODO : more configs print_status("Writing /etc/mkinitcpio.conf"); @@ -29,3 +36,29 @@ pub fn setup_mkinitcpio(conf: &DriveConfig) { arch_chroot(&["mkinitcpio", "--allpresets"], None, true); } + +fn find_uuid_by_dev(dev: &str) -> Option { + let dir_path = "/dev/disk/by-uuid"; + + if let Ok(entries) = std::fs::read_dir(dir_path) { + for entry in entries.flatten() { + let path = entry.path(); + + if let Ok(target) = std::fs::read_link(&path) { + let resolved_path = path.parent().unwrap().join(&target); + + if resolved_path + .to_string_lossy() + .ends_with(dev.split("/").last().unwrap()) + { + // Match -> Return found Block Device UUID + if let Some(filename) = path.file_name() { + return Some(filename.to_string_lossy().to_string()); + } + } + } + } + } + + None +} diff --git a/src/install/mod.rs b/src/install/mod.rs index a197d79..207704f 100644 --- a/src/install/mod.rs +++ b/src/install/mod.rs @@ -1,6 +1,3 @@ -// TODO : Setup ssh (config + authorized_keys) -// TODO : Setup virtualization -// TODO : Setup docker // TODO : Autojoin docker swarm // TODO : Autojoin teleport @@ -101,8 +98,6 @@ pub fn install(conf: InstallConfig) { install_pkgs(&pkg::DESKTOP_PKG); print_status("Enable SDDM"); - // TODO : Setup KDE Keyboard Layout - std::os::unix::fs::symlink( "/usr/lib/systemd/system/sddm.service", "/mnt/etc/systemd/system/display-manager.service",