From 0f746eb241643ad8439e8bc44f4a25977cb5cb30 Mon Sep 17 00:00:00 2001 From: axtloss Date: Mon, 25 Jul 2022 22:03:05 +0200 Subject: [PATCH 1/6] make usermod work --- src/functions/users.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/functions/users.rs b/src/functions/users.rs index 7dfb7f3..aa7231b 100755 --- a/src/functions/users.rs +++ b/src/functions/users.rs @@ -21,10 +21,8 @@ pub fn new_user(username: &str, hasroot: bool, password: &str) { exec_chroot( "usermod", vec![ - String::from("-a"), - String::from("-G"), + String::from("-aG"), String::from("wheel"), - String::from("nix-users"), String::from(username), ], ), @@ -54,4 +52,4 @@ pub fn root_pass(root_pass: &str) { ), "set root password", ); -} \ No newline at end of file +} From 1fce78304f222525b63cff66d740d9f66c52a168 Mon Sep 17 00:00:00 2001 From: axtloss Date: Thu, 28 Jul 2022 22:24:56 +0200 Subject: [PATCH 2/6] Make jade automatically has the password when used this only affects using it from the terminal --- README.md | 8 +++----- src/functions/users.rs | 25 +++++++++++++++++++++++-- src/internal/config.rs | 1 + src/main.rs | 2 +- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index ccfcaf4..72ddd7f 100755 --- a/README.md +++ b/README.md @@ -68,18 +68,16 @@ jade networking getcryst.al --ipv6 ### configure users ```sh # make a new user called nonRootHaver, without sudo and easytohack as the password -# jade uses prehashed passwords for user creation, so you'll have to calculate the hash of the password -jade users newUser nonRootHaver $(openssl passwd -6 easytohack) +jade users newUser nonRootHaver easytohack # make a user called rootHaver, with sudo and omgsosuperhardtohack as the password -jade users newUser rootHaver $(openssl passwd -6 omgsuperhardtohack) --sudoer +jade users newUser rootHaver omgsuperhardtohack --sudoer ``` ### set root password ```sh # set the root password to 'muchSecurity,veryHardToHack' -# the same hashing thing goes for root passwords -jade users rootPass $(openssl passwd -6 muchSecurity,veryHardToHack) +jade users rootPass muchSecurity,veryHardToHack ``` ### install a desktop environment diff --git a/src/functions/users.rs b/src/functions/users.rs index aa7231b..d9a59a3 100755 --- a/src/functions/users.rs +++ b/src/functions/users.rs @@ -1,7 +1,15 @@ use crate::internal::exec::*; use crate::internal::*; +use std::process::Command; -pub fn new_user(username: &str, hasroot: bool, password: &str) { +pub fn new_user(username: &str, hasroot: bool, password: &str, do_hash_pass: bool) { + if do_hash_pass { + let hashed_pass = &*hash_pass(password).stdout; + let password = match std::str::from_utf8(hashed_pass) { + Ok(v) => v, + Err(e) => panic!("Failed to hash password, invalid UTF-8 sequence {}", e), + }; + } exec_eval( exec_chroot( "useradd", @@ -10,7 +18,7 @@ pub fn new_user(username: &str, hasroot: bool, password: &str) { String::from("-s"), String::from("/bin/bash"), String::from("-p"), - String::from(password), + String::from(password).replace("\n", ""), String::from(username), ], ), @@ -39,6 +47,19 @@ pub fn new_user(username: &str, hasroot: bool, password: &str) { } } +pub fn hash_pass(password: &str) -> std::process::Output { + let output = Command::new("openssl") + .args([ + "passwd", + "-1", + password + ]) + .output() + .expect("Failed to hash password"); + return output; + +} + pub fn root_pass(root_pass: &str) { exec_eval( exec_chroot( diff --git a/src/internal/config.rs b/src/internal/config.rs index bdf217a..868d3cb 100755 --- a/src/internal/config.rs +++ b/src/internal/config.rs @@ -142,6 +142,7 @@ pub fn read_config(configpath: PathBuf) { config.users[i].name.as_str(), config.users[i].hasroot, config.users[i].password.as_str(), + false, ); println!("---------"); } diff --git a/src/main.rs b/src/main.rs index adee0c8..9a630af 100755 --- a/src/main.rs +++ b/src/main.rs @@ -49,7 +49,7 @@ fn main() { } Command::Users { subcommand } => match subcommand { UsersSubcommand::NewUser(args) => { - users::new_user(&args.username, args.hasroot, &args.password); + users::new_user(&args.username, args.hasroot, &args.password, true); } UsersSubcommand::RootPass { password } => { users::root_pass(&password); From 660407638deef130ffa3a5399ba98a9aa1b0be83 Mon Sep 17 00:00:00 2001 From: axtloss Date: Fri, 29 Jul 2022 20:04:00 +0200 Subject: [PATCH 3/6] Make append function add newline before appending --- src/internal/files.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/internal/files.rs b/src/internal/files.rs index 91bcad2..0523fb2 100755 --- a/src/internal/files.rs +++ b/src/internal/files.rs @@ -32,7 +32,9 @@ pub fn copy_file(path: &str, destpath: &str) { pub fn append_file(path: &str, content: &str) -> std::io::Result<()> { log::info!("Append '{}' to file {}", content.trim_end(), path); let mut file = OpenOptions::new().append(true).open(path)?; + file.write_all("\n".as_bytes())?; file.write_all(content.as_bytes())?; + file.write("\n".as_bytes())?; Ok(()) } From acd5f935e651f40690bc7bcc59716f779ee061e7 Mon Sep 17 00:00:00 2001 From: axtloss Date: Fri, 29 Jul 2022 20:08:39 +0200 Subject: [PATCH 4/6] Make clippy happy --- src/functions/base.rs | 2 +- src/functions/unakite.rs | 1 + src/functions/users.rs | 6 +++--- src/internal/files.rs | 4 +--- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/functions/base.rs b/src/functions/base.rs index 9bf0572..5224eea 100755 --- a/src/functions/base.rs +++ b/src/functions/base.rs @@ -5,7 +5,7 @@ use std::path::PathBuf; use log::warn; pub fn install_base_packages(kernel: String) { - let mut kernel_to_install: String = String::new(); + let kernel_to_install: String; std::fs::create_dir_all("/mnt/etc").unwrap(); files::copy_file("/etc/pacman.conf", "/mnt/etc/pacman.conf"); if kernel.is_empty() { diff --git a/src/functions/unakite.rs b/src/functions/unakite.rs index 0391eb0..818e5bb 100644 --- a/src/functions/unakite.rs +++ b/src/functions/unakite.rs @@ -154,6 +154,7 @@ pub fn setup_unakite(root: &str, oldroot: &str, efi: bool, efidir: &str, bootdev "unakite", true, "Cp7oN04ZY0PsA", // unakite + false, ); exec_eval( exec( diff --git a/src/functions/users.rs b/src/functions/users.rs index d9a59a3..78cc4bc 100755 --- a/src/functions/users.rs +++ b/src/functions/users.rs @@ -5,7 +5,7 @@ use std::process::Command; pub fn new_user(username: &str, hasroot: bool, password: &str, do_hash_pass: bool) { if do_hash_pass { let hashed_pass = &*hash_pass(password).stdout; - let password = match std::str::from_utf8(hashed_pass) { + let _password = match std::str::from_utf8(hashed_pass) { Ok(v) => v, Err(e) => panic!("Failed to hash password, invalid UTF-8 sequence {}", e), }; @@ -18,7 +18,7 @@ pub fn new_user(username: &str, hasroot: bool, password: &str, do_hash_pass: boo String::from("-s"), String::from("/bin/bash"), String::from("-p"), - String::from(password).replace("\n", ""), + String::from(password).replace('\n', ""), String::from(username), ], ), @@ -56,7 +56,7 @@ pub fn hash_pass(password: &str) -> std::process::Output { ]) .output() .expect("Failed to hash password"); - return output; + output } diff --git a/src/internal/files.rs b/src/internal/files.rs index 0523fb2..4167da6 100755 --- a/src/internal/files.rs +++ b/src/internal/files.rs @@ -32,9 +32,7 @@ pub fn copy_file(path: &str, destpath: &str) { pub fn append_file(path: &str, content: &str) -> std::io::Result<()> { log::info!("Append '{}' to file {}", content.trim_end(), path); let mut file = OpenOptions::new().append(true).open(path)?; - file.write_all("\n".as_bytes())?; - file.write_all(content.as_bytes())?; - file.write("\n".as_bytes())?; + file.write_all(format!("\n{content}\n").as_bytes())?; Ok(()) } From 28c9643bd285a5caecfb582921f9f7999185dca8 Mon Sep 17 00:00:00 2001 From: Michal Date: Fri, 29 Jul 2022 19:51:58 +0100 Subject: [PATCH 5/6] Fixed issue where kernel_to_install wouldn't be properly set --- src/args.rs | 1 - src/functions/base.rs | 64 ++++++++---- src/functions/mod.rs | 2 +- src/functions/partition.rs | 197 ++++++++++++------------------------- src/functions/unakite.rs | 82 +++++---------- src/functions/users.rs | 11 +-- src/internal/config.rs | 68 ++++++++++--- src/main.rs | 16 +-- 8 files changed, 204 insertions(+), 237 deletions(-) diff --git a/src/args.rs b/src/args.rs index 009a3e9..7e6d01c 100644 --- a/src/args.rs +++ b/src/args.rs @@ -154,7 +154,6 @@ pub fn parse_partitions(s: &str) -> Result { )) } - #[derive(Debug, ArgEnum, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Serialize, Deserialize)] pub enum PartitionMode { #[clap(name = "auto")] diff --git a/src/functions/base.rs b/src/functions/base.rs index 5224eea..da8c4fd 100755 --- a/src/functions/base.rs +++ b/src/functions/base.rs @@ -1,30 +1,29 @@ use crate::internal::exec::*; -use crate::internal::*; use crate::internal::files::append_file; -use std::path::PathBuf; +use crate::internal::*; use log::warn; +use std::path::PathBuf; pub fn install_base_packages(kernel: String) { - let kernel_to_install: String; std::fs::create_dir_all("/mnt/etc").unwrap(); files::copy_file("/etc/pacman.conf", "/mnt/etc/pacman.conf"); - if kernel.is_empty() { - kernel_to_install = "linux".to_string(); + let kernel_to_install = if kernel.is_empty() { + "linux" } else { match kernel.as_str() { - "linux" => kernel_to_install = "linux".to_string(), - "linux-lts" => kernel_to_install = "linux-lts".to_string(), - "linux-zen" => kernel_to_install = "linux-zen".to_string(), - "linux-hardened" => kernel_to_install = "linux-hardened".to_string(), + "linux" => "linux", + "linux-lts" => "linux-lts", + "linux-zen" => "linux-zen", + "linux-hardened" => "linux-hardened", _ => { warn!("Unknown kernel: {}, using default instead", kernel); - kernel_to_install = "linux".to_string(); + "linux" } } - } + }; install::install(vec![ "base", - kernel_to_install.as_str(), + kernel_to_install, "linux-firmware", "systemd-sysvcompat", "networkmanager", @@ -55,7 +54,13 @@ pub fn genfstab() { } pub fn install_bootloader_efi(efidir: PathBuf) { - install::install(vec!["grub", "efibootmgr", "grub-btrfs", "crystal-grub-theme", "os-prober"]); + install::install(vec![ + "grub", + "efibootmgr", + "grub-btrfs", + "crystal-grub-theme", + "os-prober", + ]); let efidir = std::path::Path::new("/mnt").join(efidir); let efi_str = efidir.to_str().unwrap(); if !std::path::Path::new(&format!("/mnt{efi_str}")).exists() { @@ -66,7 +71,7 @@ pub fn install_bootloader_efi(efidir: PathBuf) { "grub-install", vec![ String::from("--target=x86_64-efi"), - format!("--efi-directory={}" , efi_str), + format!("--efi-directory={}", efi_str), String::from("--bootloader-id=crystal"), String::from("--removable"), ], @@ -85,8 +90,11 @@ pub fn install_bootloader_efi(efidir: PathBuf) { "install grub as efi without --removable", ); files_eval( - append_file("/mnt/etc/default/grub", "GRUB_THEME=\"/usr/share/grub/themes/crystal/theme.txt\""), - "enable crystal grub theme" + append_file( + "/mnt/etc/default/grub", + "GRUB_THEME=\"/usr/share/grub/themes/crystal/theme.txt\"", + ), + "enable crystal grub theme", ); exec_eval( exec_chroot( @@ -98,7 +106,12 @@ pub fn install_bootloader_efi(efidir: PathBuf) { } pub fn install_bootloader_legacy(device: PathBuf) { - install::install(vec!["grub", "grub-btrfs", "crystal-grub-theme", "os-prober"]); + install::install(vec![ + "grub", + "grub-btrfs", + "crystal-grub-theme", + "os-prober", + ]); if !device.exists() { crash(format!("The device {device:?} does not exist"), 1); } @@ -111,8 +124,11 @@ pub fn install_bootloader_legacy(device: PathBuf) { "install grub as legacy", ); files_eval( - append_file("/mnt/etc/default/grub", "GRUB_THEME=\"/usr/share/grub/themes/crystal/theme.txt\""), - "enable crystal grub theme" + append_file( + "/mnt/etc/default/grub", + "GRUB_THEME=\"/usr/share/grub/themes/crystal/theme.txt\"", + ), + "enable crystal grub theme", ); exec_eval( exec_chroot( @@ -138,7 +154,15 @@ pub fn install_homemgr() { pub fn install_flatpak() { install(vec!["flatpak"]); exec_eval( - exec_chroot("flatpak", vec![String::from("remote-add"), String::from("--if-not-exists"), String::from("flathub"), String::from("https://flathub.org/repo/flathub.flatpakrepo")]), + exec_chroot( + "flatpak", + vec![ + String::from("remote-add"), + String::from("--if-not-exists"), + String::from("flathub"), + String::from("https://flathub.org/repo/flathub.flatpakrepo"), + ], + ), "add flathub remote", ) } diff --git a/src/functions/mod.rs b/src/functions/mod.rs index 178cb10..27cc900 100755 --- a/src/functions/mod.rs +++ b/src/functions/mod.rs @@ -3,5 +3,5 @@ pub mod desktops; pub mod locale; pub mod network; pub mod partition; +pub mod unakite; pub mod users; -pub mod unakite; \ No newline at end of file diff --git a/src/functions/partition.rs b/src/functions/partition.rs index a094f4a..76f9aa3 100755 --- a/src/functions/partition.rs +++ b/src/functions/partition.rs @@ -1,5 +1,5 @@ -use crate::args::PartitionMode; use crate::args; +use crate::args::PartitionMode; use crate::internal::exec::*; use crate::internal::*; use std::path::{Path, PathBuf}; @@ -9,130 +9,60 @@ mkfs.btrfs mkfs.ext2 mkfs.ext4 mkfs.minix mkfs.vfat */ pub fn fmt_mount(mountpoint: &str, filesystem: &str, blockdevice: &str) { match filesystem { - "vfat" => { - exec_eval( - exec( - "mkfs.vfat", - vec![ - String::from("-F"), - String::from("32"), - String::from(blockdevice), - ], - ), - format!("Formatting {blockdevice} as vfat").as_str(), - ) - } - "bfs" => { - exec_eval( - exec( - "mkfs.bfs", - vec![ - String::from(blockdevice), - ], - ), - format!("Formatting {blockdevice} as bfs").as_str(), - ) - } - "cramfs" => { - exec_eval( - exec( - "mkfs.cramfs", - vec![ - String::from(blockdevice), - ], - ), - format!("Formatting {blockdevice} as cramfs").as_str(), - ) - } - "ext3" => { - exec_eval( - exec( - "mkfs.ext3", - vec![ - String::from(blockdevice), - ], - ), - format!("Formatting {blockdevice} as ext3").as_str(), - ) - } - "fat" => { - exec_eval( - exec( - "mkfs.fat", - vec![ - String::from(blockdevice), - ], - ), - format!("Formatting {blockdevice} as fat").as_str(), - ) - } - "msdos" => { - exec_eval( - exec( - "mkfs.msdos", - vec![ - String::from(blockdevice), - ], - ), - format!("Formatting {blockdevice} as msdos").as_str(), - ) - } - "xfs" => { - exec_eval( - exec( - "mkfs.xfs", - vec![ - String::from(blockdevice), - ], - ), - format!("Formatting {blockdevice} as xfs").as_str(), - ) - } - "btrfs" => { - exec_eval( - exec( - "mkfs.btrfs", - vec![ - String::from("-f"), - String::from(blockdevice), - ], - ), - format!("Formatting {blockdevice} as btrfs").as_str(), - ) - } - "ext2" => { - exec_eval( - exec( - "mkfs.ext2", - vec![ - String::from(blockdevice), - ], - ), - format!("Formatting {blockdevice} as ext2").as_str(), - ) - } - "ext4" => { - exec_eval( - exec( - "mkfs.ext4", - vec![ - String::from(blockdevice), - ], - ), - format!("Formatting {blockdevice} as ext4").as_str(), - ) - } - "minix" => { - exec_eval( - exec( - "mkfs.minix", - vec![ - String::from(blockdevice), - ], - ), - format!("Formatting {blockdevice} as minix").as_str(), - ) - } + "vfat" => exec_eval( + exec( + "mkfs.vfat", + vec![ + String::from("-F"), + String::from("32"), + String::from(blockdevice), + ], + ), + format!("Formatting {blockdevice} as vfat").as_str(), + ), + "bfs" => exec_eval( + exec("mkfs.bfs", vec![String::from(blockdevice)]), + format!("Formatting {blockdevice} as bfs").as_str(), + ), + "cramfs" => exec_eval( + exec("mkfs.cramfs", vec![String::from(blockdevice)]), + format!("Formatting {blockdevice} as cramfs").as_str(), + ), + "ext3" => exec_eval( + exec("mkfs.ext3", vec![String::from(blockdevice)]), + format!("Formatting {blockdevice} as ext3").as_str(), + ), + "fat" => exec_eval( + exec("mkfs.fat", vec![String::from(blockdevice)]), + format!("Formatting {blockdevice} as fat").as_str(), + ), + "msdos" => exec_eval( + exec("mkfs.msdos", vec![String::from(blockdevice)]), + format!("Formatting {blockdevice} as msdos").as_str(), + ), + "xfs" => exec_eval( + exec("mkfs.xfs", vec![String::from(blockdevice)]), + format!("Formatting {blockdevice} as xfs").as_str(), + ), + "btrfs" => exec_eval( + exec( + "mkfs.btrfs", + vec![String::from("-f"), String::from(blockdevice)], + ), + format!("Formatting {blockdevice} as btrfs").as_str(), + ), + "ext2" => exec_eval( + exec("mkfs.ext2", vec![String::from(blockdevice)]), + format!("Formatting {blockdevice} as ext2").as_str(), + ), + "ext4" => exec_eval( + exec("mkfs.ext4", vec![String::from(blockdevice)]), + format!("Formatting {blockdevice} as ext4").as_str(), + ), + "minix" => exec_eval( + exec("mkfs.minix", vec![String::from(blockdevice)]), + format!("Formatting {blockdevice} as minix").as_str(), + ), "don't format" => { log::debug!("Not formatting {}", blockdevice); } @@ -147,20 +77,19 @@ pub fn fmt_mount(mountpoint: &str, filesystem: &str, blockdevice: &str) { } } exec_eval( - exec( - "mkdir", - vec![ - String::from("-p"), - String::from(mountpoint), - ], - ), + exec("mkdir", vec![String::from("-p"), String::from(mountpoint)]), format!("Creating mountpoint {mountpoint} for {blockdevice}").as_str(), ); mount(blockdevice, mountpoint, ""); } -pub fn partition(device: PathBuf, mode: PartitionMode, efi: bool, partitions: &mut Vec, unakite: bool) { - +pub fn partition( + device: PathBuf, + mode: PartitionMode, + efi: bool, + partitions: &mut Vec, + unakite: bool, +) { println!("{:?}", mode); match mode { PartitionMode::Auto => { diff --git a/src/functions/unakite.rs b/src/functions/unakite.rs index 818e5bb..c4028f4 100644 --- a/src/functions/unakite.rs +++ b/src/functions/unakite.rs @@ -1,11 +1,16 @@ +use crate::args::DesktopSetup; +use crate::functions::partition::mount; +use crate::functions::*; use crate::internal::exec::*; use crate::internal::*; -use crate::functions::*; -use crate::functions::partition::mount; use std::path::PathBuf; -use crate::args::DesktopSetup; pub fn install_bootloader_efi(efidir: PathBuf) { - install::install(vec!["grub", "efibootmgr", "grub-btrfs", "crystal-grub-theme"]); + install::install(vec![ + "grub", + "efibootmgr", + "grub-btrfs", + "crystal-grub-theme", + ]); let efidir = std::path::Path::new("/mnt").join(efidir); let efi_str = efidir.to_str().unwrap(); if !std::path::Path::new(&format!("/mnt{efi_str}")).exists() { @@ -16,7 +21,7 @@ pub fn install_bootloader_efi(efidir: PathBuf) { "grub-install", vec![ String::from("--target=x86_64-efi"), - format!("--efi-directory={}" , efi_str), + format!("--efi-directory={}", efi_str), String::from("--bootloader-id=unakite"), String::from("--removable"), ], @@ -35,8 +40,11 @@ pub fn install_bootloader_efi(efidir: PathBuf) { "install unakite grub as efi without --removable", ); files_eval( - files::append_file("/mnt/etc/default/grub", "GRUB_THEME=\"/usr/share/grub/themes/crystal/theme.txt\""), - "enable crystal grub theme" + files::append_file( + "/mnt/etc/default/grub", + "GRUB_THEME=\"/usr/share/grub/themes/crystal/theme.txt\"", + ), + "enable crystal grub theme", ); exec_eval( exec_chroot( @@ -50,88 +58,52 @@ pub fn install_bootloader_efi(efidir: PathBuf) { pub fn remount(root: &str, oldroot: &str, efi: bool, efidir: &str, bootdev: &str, firstrun: bool) { if efi && firstrun { exec_eval( - exec( - "umount", - vec![String::from(bootdev)], - ), + exec("umount", vec![String::from(bootdev)]), &format!("Unmount {}", bootdev), ); exec_eval( - exec( - "umount", - vec![String::from(oldroot)], - ), + exec("umount", vec![String::from(oldroot)]), "Unmount old root", ); mount(root, "/mnt", ""); exec_eval( - exec( - "mkdir", - vec![ - String::from("-p"), - String::from(efidir), - ], - ), + exec("mkdir", vec![String::from("-p"), String::from(efidir)]), format!("Creating mountpoint {efidir} for {bootdev}").as_str(), ); mount(bootdev, efidir, ""); } else if efi && !firstrun { exec_eval( - exec( - "umount", - vec![String::from(bootdev)], - ), + exec("umount", vec![String::from(bootdev)]), &format!("Unmount {}", bootdev), ); exec_eval( - exec( - "umount", - vec![String::from(root)], - ), + exec("umount", vec![String::from(root)]), "Unmount unakite root", ); mount(oldroot, "/mnt", ""); mount(bootdev, efidir, ""); } else if !efi && firstrun { exec_eval( - exec( - "umount", - vec![String::from(bootdev)], - ), + exec("umount", vec![String::from(bootdev)]), &format!("Unmount {}", bootdev), ); exec_eval( - exec( - "umount", - vec![String::from(oldroot)], - ), + exec("umount", vec![String::from(oldroot)]), "Unmount old root", ); mount(root, "/mnt", ""); exec_eval( - exec( - "mkdir", - vec![ - String::from("-p"), - String::from("/mnt/boot"), - ], - ), + exec("mkdir", vec![String::from("-p"), String::from("/mnt/boot")]), format!("Creating mountpoint /boot for {bootdev}").as_str(), ); mount(bootdev, "/mnt/boot", ""); } else if !efi && !firstrun { exec_eval( - exec( - "umount", - vec![String::from(bootdev)], - ), + exec("umount", vec![String::from(bootdev)]), &format!("Unmount {}", bootdev), ); exec_eval( - exec( - "umount", - vec![String::from(root)], - ), + exec("umount", vec![String::from(root)]), "Unmount unakite root", ); mount(oldroot, "/mnt", ""); @@ -192,7 +164,7 @@ pub fn setup_unakite(root: &str, oldroot: &str, efi: bool, efidir: &str, bootdev vec![ String::from("/tmp/jade.json"), String::from("/mnt/etc/installSettings.json"), - ] + ], ), "Copy jade.json to /etc/installSettings.json in unakite", ); @@ -202,6 +174,6 @@ pub fn setup_unakite(root: &str, oldroot: &str, efi: bool, efidir: &str, bootdev "grub-mkconfig", vec![String::from("-o"), String::from("/boot/grub/grub.cfg")], ), - "Recreate grub.cfg in crystal" + "Recreate grub.cfg in crystal", ); } diff --git a/src/functions/users.rs b/src/functions/users.rs index 78cc4bc..d63d445 100755 --- a/src/functions/users.rs +++ b/src/functions/users.rs @@ -49,15 +49,10 @@ pub fn new_user(username: &str, hasroot: bool, password: &str, do_hash_pass: boo pub fn hash_pass(password: &str) -> std::process::Output { let output = Command::new("openssl") - .args([ - "passwd", - "-1", - password - ]) + .args(["passwd", "-1", password]) .output() .expect("Failed to hash password"); output - } pub fn root_pass(root_pass: &str) { @@ -66,9 +61,7 @@ pub fn root_pass(root_pass: &str) { "bash", vec![ String::from("-c"), - format!( - r#"'usermod --password {root_pass} root'"# - ), + format!(r#"'usermod --password {root_pass} root'"#), ], ), "set root password", diff --git a/src/internal/config.rs b/src/internal/config.rs index 868d3cb..928014f 100755 --- a/src/internal/config.rs +++ b/src/internal/config.rs @@ -1,5 +1,5 @@ -use crate::args::{DesktopSetup, PartitionMode}; use crate::args; +use crate::args::{DesktopSetup, PartitionMode}; use crate::functions::*; use crate::internal::*; use serde::{Deserialize, Serialize}; @@ -105,7 +105,7 @@ pub fn read_config(configpath: PathBuf) { config.partition.mode, config.partition.efi, &mut partitions, - config.unakite.enable + config.unakite.enable, ); base::install_base_packages(config.kernel); base::genfstab(); @@ -183,20 +183,66 @@ pub fn read_config(configpath: PathBuf) { } install(extra_packages); log::info!("Setup unakite"); - if config.partition.mode == PartitionMode::Auto && !config.partition.efi && config.unakite.enable && !config.partition.device.to_string().contains("nvme") { + if config.partition.mode == PartitionMode::Auto + && !config.partition.efi + && config.unakite.enable + && !config.partition.device.to_string().contains("nvme") + { let root = PathBuf::from("/dev/").join(config.partition.device.as_str()); - unakite::setup_unakite(format!("{}2",root.to_str().unwrap()).as_str(), format!("{}3",root.to_str().unwrap()).as_str(), config.partition.efi, "/boot", format!("{}1",root.to_str().unwrap()).as_str()) - } else if config.partition.mode == PartitionMode::Auto && config.partition.efi && config.unakite.enable && !config.partition.device.to_string().contains("nvme") { + unakite::setup_unakite( + format!("{}2", root.to_str().unwrap()).as_str(), + format!("{}3", root.to_str().unwrap()).as_str(), + config.partition.efi, + "/boot", + format!("{}1", root.to_str().unwrap()).as_str(), + ) + } else if config.partition.mode == PartitionMode::Auto + && config.partition.efi + && config.unakite.enable + && !config.partition.device.to_string().contains("nvme") + { let root = PathBuf::from("/dev/").join(config.partition.device.as_str()); - unakite::setup_unakite(format!("{}2",root.to_str().unwrap()).as_str(), format!("{}3",root.to_str().unwrap()).as_str(), config.partition.efi, "/boot/efi", format!("{}1",root.to_str().unwrap()).as_str()) + unakite::setup_unakite( + format!("{}2", root.to_str().unwrap()).as_str(), + format!("{}3", root.to_str().unwrap()).as_str(), + config.partition.efi, + "/boot/efi", + format!("{}1", root.to_str().unwrap()).as_str(), + ) } else if config.unakite.enable { - unakite::setup_unakite(&config.unakite.root, &config.unakite.oldroot, config.partition.efi, &config.unakite.efidir, &config.unakite.bootdev); - } else if config.partition.mode == PartitionMode::Auto && config.partition.efi && config.unakite.enable && config.partition.device.to_string().contains("nvme") { + unakite::setup_unakite( + &config.unakite.root, + &config.unakite.oldroot, + config.partition.efi, + &config.unakite.efidir, + &config.unakite.bootdev, + ); + } else if config.partition.mode == PartitionMode::Auto + && config.partition.efi + && config.unakite.enable + && config.partition.device.to_string().contains("nvme") + { let root = PathBuf::from("/dev/").join(config.partition.device.as_str()); - unakite::setup_unakite(format!("{}p2",root.to_str().unwrap()).as_str(), format!("{}p3",root.to_str().unwrap()).as_str(), config.partition.efi, "/boot/efi", format!("{}p1",root.to_str().unwrap()).as_str()) - } else if config.partition.mode == PartitionMode::Auto && !config.partition.efi && config.unakite.enable && config.partition.device.to_string().contains("nvme") { + unakite::setup_unakite( + format!("{}p2", root.to_str().unwrap()).as_str(), + format!("{}p3", root.to_str().unwrap()).as_str(), + config.partition.efi, + "/boot/efi", + format!("{}p1", root.to_str().unwrap()).as_str(), + ) + } else if config.partition.mode == PartitionMode::Auto + && !config.partition.efi + && config.unakite.enable + && config.partition.device.to_string().contains("nvme") + { let root = PathBuf::from("/dev/").join(config.partition.device.as_str()); - unakite::setup_unakite(format!("{}p2",root.to_str().unwrap()).as_str(), format!("{}p3",root.to_str().unwrap()).as_str(), config.partition.efi, "/boot", format!("{}p1",root.to_str().unwrap()).as_str()) + unakite::setup_unakite( + format!("{}p2", root.to_str().unwrap()).as_str(), + format!("{}p3", root.to_str().unwrap()).as_str(), + config.partition.efi, + "/boot", + format!("{}p1", root.to_str().unwrap()).as_str(), + ) } else { log::info!("Unakite disabled"); } diff --git a/src/main.rs b/src/main.rs index 9a630af..95c13fe 100755 --- a/src/main.rs +++ b/src/main.rs @@ -14,12 +14,16 @@ fn main() { match opt.command { Command::Partition(args) => { let mut partitions = args.partitions; - partition::partition(args.device, args.mode, args.efi, &mut partitions, args.unakite); + partition::partition( + args.device, + args.mode, + args.efi, + &mut partitions, + args.unakite, + ); } Command::InstallBase(args) => { - base::install_base_packages( - args.kernel, - ); + base::install_base_packages(args.kernel); } Command::GenFstab => { base::genfstab(); @@ -57,7 +61,7 @@ fn main() { }, Command::Nix => { base::install_homemgr(); - }, + } Command::Flatpak => { base::install_flatpak(); } @@ -69,7 +73,7 @@ fn main() { &args.efidir, &args.bootdev, ); - }, + } Command::Config { config } => { crate::internal::config::read_config(config); } From 1ddef5e7a85c4e7608a8abf6e6cf4cfa893a81c3 Mon Sep 17 00:00:00 2001 From: axtloss Date: Sat, 30 Jul 2022 13:39:07 +0200 Subject: [PATCH 6/6] Fix issue with unmounted /mnt/dev resolves #12 --- src/functions/partition.rs | 2 +- src/internal/install.rs | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/functions/partition.rs b/src/functions/partition.rs index a094f4a..5be84d3 100755 --- a/src/functions/partition.rs +++ b/src/functions/partition.rs @@ -785,7 +785,7 @@ pub fn mount(partition: &str, mountpoint: &str, options: &str) { } } -fn umount(mountpoint: &str) { +pub fn umount(mountpoint: &str) { exec_eval( exec("umount", vec![String::from(mountpoint)]), format!("unmount {}", mountpoint).as_str(), diff --git a/src/internal/install.rs b/src/internal/install.rs index b15d13a..7d94d43 100755 --- a/src/internal/install.rs +++ b/src/internal/install.rs @@ -1,4 +1,6 @@ use crate::internal::*; +use crate::functions::partition::mount; +use crate::functions::partition::umount; use std::process::Command; pub fn install(pkgs: Vec<&str>) { @@ -6,4 +8,5 @@ pub fn install(pkgs: Vec<&str>) { Command::new("pacstrap").arg("/mnt").args(&pkgs).status(), format!("Install packages {}", pkgs.join(", ")).as_str(), ); + umount("/mnt/dev"); }