From 09573dd0b1cf8227b3f34c78500a409774145f46 Mon Sep 17 00:00:00 2001 From: amy Date: Sun, 23 Jan 2022 14:52:10 +0100 Subject: [PATCH] made clippy shut up and ran cargo fmt --- README.md | 19 ++ src/functions/base.rs | 56 +++-- src/functions/locale.rs | 55 +++-- src/functions/mod.rs | 2 +- src/functions/network.rs | 15 +- src/functions/partition.rs | 412 ++++++++++++++++++++------------ src/functions/users.rs | 98 ++++---- src/internal/exec.rs | 2 +- src/internal/mod.rs | 7 +- src/internal/returncode_eval.rs | 55 +++-- src/main.rs | 13 +- 11 files changed, 458 insertions(+), 276 deletions(-) diff --git a/README.md b/README.md index 44cf5ed..0c0a403 100755 --- a/README.md +++ b/README.md @@ -25,12 +25,31 @@ jade partition auto /dev/sda --efi jade partition auto /dev/nvmen0 ``` +### install base packages +```sh +jade install-base +``` + +### install bootloader +```sh +# install as efi with esp being /boot/efi +jade bootloader grub-efi /boot/efi + +# install as legacy on /dev/sda +jade bootloader grub-legacy /dev/sda +``` + ### configuring locale settings ```sh # set the keyboard layout to colemak, the timezone to Europe/Berlin and set en_US.UTF-8 as the locale jade locale colemak Europe/Berlin "en_US.UTF-8 UTF-8" ``` +### create /etc/hosts +```sh +jade networking --hosts +``` + ### configue network settings ```sh # set the hostname to getcryst.al with ipv6 disabled diff --git a/src/functions/base.rs b/src/functions/base.rs index 7b1333f..bd82366 100755 --- a/src/functions/base.rs +++ b/src/functions/base.rs @@ -23,32 +23,42 @@ pub fn install_base_packages() { ]); } -pub fn create_hosts() { - files::create_file("/mnt/etc/hosts"); - files_eval(files::append_file("/mnt/etc/hosts", "127.0.0.1 localhost"), "create /etc/hosts"); -} - pub fn install_bootloader_efi(efidir: &str) { - install::install(vec!["grub", "efibootmgr",]); - exec_eval(exec_chroot("grub-install", vec![ - String::from("--target=x86_64-efi"), - format!("--efi-directory={}", efidir), - String::from("--bootloader-id=crystal"), - ]), "install grub as efi"); - exec_eval(exec_chroot("grub-mkconfig", vec![ - String::from("-o"), - String::from("/boot/grub/grub.cfg"), - ]), "create grub.cfg"); + install::install(vec!["grub", "efibootmgr"]); + exec_eval( + exec_chroot( + "grub-install", + vec![ + String::from("--target=x86_64-efi"), + format!("--efi-directory={}", efidir), + String::from("--bootloader-id=crystal"), + ], + ), + "install grub as efi", + ); + exec_eval( + exec_chroot( + "grub-mkconfig", + vec![String::from("-o"), String::from("/boot/grub/grub.cfg")], + ), + "create grub.cfg", + ); } pub fn install_bootloader_legacy(device: &str) { install::install(vec!["grub"]); - exec_eval(exec_chroot("grub-install", vec![ - String::from("--target=i386-pc"), - String::from(device), - ]), "install grub as legacy"); - exec_eval(exec_chroot("grub-mkconfig", vec![ - String::from("-o"), - String::from("/boot/grub/grub.cfg"), - ]), "create grub.cfg"); + exec_eval( + exec_chroot( + "grub-install", + vec![String::from("--target=i386-pc"), String::from(device)], + ), + "install grub as legacy", + ); + exec_eval( + exec_chroot( + "grub-mkconfig", + vec![String::from("-o"), String::from("/boot/grub/grub.cfg")], + ), + "create grub.cfg", + ); } diff --git a/src/functions/locale.rs b/src/functions/locale.rs index f5e75c5..716fefb 100755 --- a/src/functions/locale.rs +++ b/src/functions/locale.rs @@ -2,29 +2,50 @@ use crate::internal::exec::*; use crate::internal::*; pub fn set_timezone(timezone: &str) { - exec_eval(exec( - "ln", - vec![ - "-sf".to_string(), - format!("/usr/share/zoneinfo/{}", timezone), - "/etc/localtime".to_string(), - ], - ), "Set timezone"); - exec_eval(exec_chroot("hwclock", vec!["--systohc".to_string()]), "Set system clock"); + exec_eval( + exec( + "ln", + vec![ + "-sf".to_string(), + format!("/usr/share/zoneinfo/{}", timezone), + "/etc/localtime".to_string(), + ], + ), + "Set timezone", + ); + exec_eval( + exec_chroot("hwclock", vec!["--systohc".to_string()]), + "Set system clock", + ); } pub fn set_locale(locale: String) { - files_eval(files::append_file("/etc/locale.gen", "en_US.UTF-8 UTF-8"), "add en_US.UTF-8 UTF-8 to locale.gen"); - files_eval(files::append_file("/etc/locale.gen", locale.as_str()), "add locales to locale.gen"); - exec_eval(exec_chroot("locale-gen", vec!["".to_string()]), "generate locales"); + files_eval( + files::append_file("/etc/locale.gen", "en_US.UTF-8 UTF-8"), + "add en_US.UTF-8 UTF-8 to locale.gen", + ); + files_eval( + files::append_file("/etc/locale.gen", locale.as_str()), + "add locales to locale.gen", + ); + exec_eval( + exec_chroot("locale-gen", vec!["".to_string()]), + "generate locales", + ); files::create_file("/etc/locale.conf"); - files_eval(files::append_file("/etc/locale.conf", "LANG=en_US.UTF-8"), "edit locale.conf"); + files_eval( + files::append_file("/etc/locale.conf", "LANG=en_US.UTF-8"), + "edit locale.conf", + ); } pub fn set_keyboard(keyboard: &str) { files::create_file("/etc/vconsole.conf"); - files_eval(files::append_file( - "/etc/vconsole.conf", - format!("KEYMAP={}", keyboard).as_str(), - ), "set keyboard layout"); + files_eval( + files::append_file( + "/etc/vconsole.conf", + format!("KEYMAP={}", keyboard).as_str(), + ), + "set keyboard layout", + ); } diff --git a/src/functions/mod.rs b/src/functions/mod.rs index 44ff3ef..a15e19f 100755 --- a/src/functions/mod.rs +++ b/src/functions/mod.rs @@ -1,6 +1,6 @@ +pub mod base; pub mod desktops; pub mod locale; pub mod network; pub mod partition; pub mod users; -pub mod base; \ No newline at end of file diff --git a/src/functions/network.rs b/src/functions/network.rs index f36d0d9..f69f72e 100755 --- a/src/functions/network.rs +++ b/src/functions/network.rs @@ -3,14 +3,23 @@ use crate::internal::*; pub fn set_hostname(hostname: &str) { println!("Setting hostname to {}", hostname); files::create_file("/mnt/etc/hostname"); - files_eval(files::append_file("/mnt/etc/hostname", hostname), "set hostname"); + files_eval( + files::append_file("/mnt/etc/hostname", hostname), + "set hostname", + ); } pub fn create_hosts() { files::create_file("/mnt/etc/hosts"); - files_eval(files::append_file("/mnt/etc/hosts", "127.0.0.1 localhost"), "create /etc/hosts"); + files_eval( + files::append_file("/mnt/etc/hosts", "127.0.0.1 localhost"), + "create /etc/hosts", + ); } pub fn enable_ipv6() { - files_eval(files::append_file("/mnt/etc/hosts", "::1 localhost"), "add ipv6 localhost"); + files_eval( + files::append_file("/mnt/etc/hosts", "::1 localhost"), + "add ipv6 localhost", + ); } diff --git a/src/functions/partition.rs b/src/functions/partition.rs index 8ad14cf..2deb13b 100755 --- a/src/functions/partition.rs +++ b/src/functions/partition.rs @@ -7,69 +7,87 @@ pub fn partition(device: &str, mode: &str, efi: bool) { } else { log(format!("automatically partitioning {}", device)); if efi { - exec_eval(exec( - "parted", - vec![ - String::from("-s"), - String::from(device), - String::from("mklabel"), - String::from("gpt"), - ], - ), format!("create gpt label on {}", device).as_str()); - exec_eval(exec( - "parted", - vec![ - String::from("-s"), - String::from(device), - String::from("mkpart"), - String::from("fat32"), - String::from("0"), - String::from("300"), - ], - ), "create EFI partition"); - exec_eval(exec( - "parted", - vec![ - String::from("-s"), - String::from(device), - String::from("mkpart"), - String::from("btrfs"), - String::from("300"), - String::from("100%"), - ], - ), "Create btrfs root partition"); + exec_eval( + exec( + "parted", + vec![ + String::from("-s"), + String::from(device), + String::from("mklabel"), + String::from("gpt"), + ], + ), + format!("create gpt label on {}", device).as_str(), + ); + exec_eval( + exec( + "parted", + vec![ + String::from("-s"), + String::from(device), + String::from("mkpart"), + String::from("fat32"), + String::from("0"), + String::from("300"), + ], + ), + "create EFI partition", + ); + exec_eval( + exec( + "parted", + vec![ + String::from("-s"), + String::from(device), + String::from("mkpart"), + String::from("btrfs"), + String::from("300"), + String::from("100%"), + ], + ), + "Create btrfs root partition", + ); } else { - exec_eval(exec( - "parted", - vec![ - String::from("-s"), - String::from(device), - String::from("mklabel"), - String::from("msdos"), - ], - ), format!("Create msdos label on {}", device).as_str()); - exec_eval(exec( - "parted", - vec![ - String::from("-s"), - String::from(device), - String::from("mkpart"), - String::from("btrfs"), - String::from("512MIB"), - String::from("100&"), - ], - ), "create btrfs root partition"); - exec_eval(exec( - "parted", - vec![ - String::from("-s"), - String::from(device), - String::from("mkpart"), - String::from("ext4"), - String::from("1MIB"), - String::from("512MIB"), - ], - ), "create bios boot partition"); + exec_eval( + exec( + "parted", + vec![ + String::from("-s"), + String::from(device), + String::from("mklabel"), + String::from("msdos"), + ], + ), + format!("Create msdos label on {}", device).as_str(), + ); + exec_eval( + exec( + "parted", + vec![ + String::from("-s"), + String::from(device), + String::from("mkpart"), + String::from("btrfs"), + String::from("512MIB"), + String::from("100&"), + ], + ), + "create btrfs root partition", + ); + exec_eval( + exec( + "parted", + vec![ + String::from("-s"), + String::from(device), + String::from("mkpart"), + String::from("ext4"), + String::from("1MIB"), + String::from("512MIB"), + ], + ), + "create bios boot partition", + ); } } if device.contains("nvme") { @@ -81,121 +99,189 @@ pub fn partition(device: &str, mode: &str, efi: bool) { fn part_nvme(device: &str, efi: bool) { if efi { - exec_eval(exec("mkfs.vfat", vec![format!("{}p1", device)]), format!("format {}p1 as fat32", device).as_str()); - exec_eval(exec("mkfs.btrfs", vec![format!("{}p2", device)]), format!("format {}p2 as btrfs", device).as_str()); + exec_eval( + exec("mkfs.vfat", vec![format!("{}p1", device)]), + format!("format {}p1 as fat32", device).as_str(), + ); + exec_eval( + exec("mkfs.btrfs", vec![format!("{}p2", device)]), + format!("format {}p2 as btrfs", device).as_str(), + ); mount(format!("{}p2", device).as_str(), "/mnt", ""); - exec_eval(exec_workdir( - "btrfs", - "/mnt", - vec![ - String::from("subvolume"), - String::from("create"), - String::from("@"), - ], - ), "Create btrfs subvolume @"); - exec_eval(exec_workdir( - "btrfs", - "/mnt", - vec![ - String::from("subvolume"), - String::from("create"), - String::from("@home"), - ], - ), "Create btrfs subvolume @home"); + exec_eval( + exec_workdir( + "btrfs", + "/mnt", + vec![ + String::from("subvolume"), + String::from("create"), + String::from("@"), + ], + ), + "Create btrfs subvolume @", + ); + exec_eval( + exec_workdir( + "btrfs", + "/mnt", + vec![ + String::from("subvolume"), + String::from("create"), + String::from("@home"), + ], + ), + "Create btrfs subvolume @home", + ); umount("/mnt"); mount(format!("{}p2", device).as_str(), "/mnt/", "subvol=@"); files_eval(files::create_directory("/mnt/boot"), "create /mnt/boot"); - files_eval(files::create_directory("/mnt/boot/efi"), "create /mnt/boot/efi"); + files_eval( + files::create_directory("/mnt/boot/efi"), + "create /mnt/boot/efi", + ); files_eval(files::create_directory("/mnt/home"), "create /mnt/home"); - mount(format!("{}p2", device).as_str(), "/mnt/home", "subvol=@home"); + mount( + format!("{}p2", device).as_str(), + "/mnt/home", + "subvol=@home", + ); mount(format!("{}p1", device).as_str(), "/mnt/boot/efi", ""); } else { - exec_eval(exec("mkfs.ext4", vec![format!("{}p1", device)]), format!("format {}p1 as ext4", device).as_str()); - exec_eval(exec("mkfs.btrfs", vec![format!("{}p2", device)]), format!("format {}p2 as btrfs", device).as_str()); + exec_eval( + exec("mkfs.ext4", vec![format!("{}p1", device)]), + format!("format {}p1 as ext4", device).as_str(), + ); + exec_eval( + exec("mkfs.btrfs", vec![format!("{}p2", device)]), + format!("format {}p2 as btrfs", device).as_str(), + ); mount(format!("{}p2", device).as_str(), "/mnt/", ""); - exec_eval(exec_workdir( - "btrfs", - "/mnt", - vec![ - String::from("subvolume"), - String::from("create"), - String::from("@"), - ], - ), "Create btrfs subvolume @"); - exec_eval(exec_workdir( - "btrfs", - "/mnt", - vec![ - String::from("subvolume"), - String::from("create"), - String::from("@home"), - ], - ), "Create btrfs subvolume @home"); + exec_eval( + exec_workdir( + "btrfs", + "/mnt", + vec![ + String::from("subvolume"), + String::from("create"), + String::from("@"), + ], + ), + "Create btrfs subvolume @", + ); + exec_eval( + exec_workdir( + "btrfs", + "/mnt", + vec![ + String::from("subvolume"), + String::from("create"), + String::from("@home"), + ], + ), + "Create btrfs subvolume @home", + ); umount("/mnt"); mount(format!("{}p2", device).as_str(), "/mnt/", "subvol=@"); files_eval(files::create_directory("/mnt/boot"), "create /mnt/boot"); files_eval(files::create_directory("/mnt/home"), "create /mnt/home"); - mount(format!("{}p2", device).as_str(), "/mnt/home", "subvol=@home"); + mount( + format!("{}p2", device).as_str(), + "/mnt/home", + "subvol=@home", + ); mount(format!("{}p1", device).as_str(), "/mnt/boot", ""); } } fn part_disk(device: &str, efi: bool) { if efi { - exec_eval(exec("mkfs.vfat", vec![format!("{}1", device)]), format!("format {}1 as fat32", device).as_str()); - exec_eval(exec("mkfs.btrfs", vec![format!("{}2", device)]), format!("format {}2 as btrfs", device).as_str()); + exec_eval( + exec("mkfs.vfat", vec![format!("{}1", device)]), + format!("format {}1 as fat32", device).as_str(), + ); + exec_eval( + exec("mkfs.btrfs", vec![format!("{}2", device)]), + format!("format {}2 as btrfs", device).as_str(), + ); mount(format!("{}2", device).as_str(), "/mnt", ""); - exec_eval(exec_workdir( - "btrfs", - "/mnt", - vec![ - String::from("subvolume"), - String::from("create"), - String::from("@"), - ], - ), "Create btrfs subvolume @"); - exec_eval(exec_workdir( - "btrfs", - "/mnt", - vec![ - String::from("subvolume"), - String::from("create"), - String::from("@home"), - ], - ), "Create btrfs subvolume @home"); + exec_eval( + exec_workdir( + "btrfs", + "/mnt", + vec![ + String::from("subvolume"), + String::from("create"), + String::from("@"), + ], + ), + "Create btrfs subvolume @", + ); + exec_eval( + exec_workdir( + "btrfs", + "/mnt", + vec![ + String::from("subvolume"), + String::from("create"), + String::from("@home"), + ], + ), + "Create btrfs subvolume @home", + ); umount("/mnt"); mount(format!("{}2", device).as_str(), "/mnt/", "subvol=@"); files_eval(files::create_directory("/mnt/boot"), "create /mnt/boot"); - files_eval(files::create_directory("/mnt/boot/efi"), "create /mnt/boot/efi"); + files_eval( + files::create_directory("/mnt/boot/efi"), + "create /mnt/boot/efi", + ); files_eval(files::create_directory("/mnt/home"), "create /mnt/home"); mount(format!("{}2", device).as_str(), "/mnt/home", "subvol=@home"); mount(format!("{}1", device).as_str(), "/mnt/boot/efi", ""); } else { - exec_eval(exec("mkfs.ext4", vec![format!("{}1", device)]), format!("format {}1 as ext4", device).as_str()); - exec_eval(exec("mkfs.btrfs", vec![format!("{}2", device)]), format!("format {}2 as btrfs", device).as_str()); + exec_eval( + exec("mkfs.ext4", vec![format!("{}1", device)]), + format!("format {}1 as ext4", device).as_str(), + ); + exec_eval( + exec("mkfs.btrfs", vec![format!("{}2", device)]), + format!("format {}2 as btrfs", device).as_str(), + ); mount(format!("{}2", device).as_str(), "/mnt/", ""); - exec_eval(exec_workdir( - "btrfs", - "/mnt", - vec![ - String::from("subvolume"), - String::from("create"), - String::from("@"), - ], - ), "Create btrfs subvolume @"); - exec_eval(exec_workdir( - "btrfs", - "/mnt", - vec![ - String::from("subvolume"), - String::from("create"), - String::from("@home"), - ], - ), "create btrfs subvolume @home"); + exec_eval( + exec_workdir( + "btrfs", + "/mnt", + vec![ + String::from("subvolume"), + String::from("create"), + String::from("@"), + ], + ), + "Create btrfs subvolume @", + ); + exec_eval( + exec_workdir( + "btrfs", + "/mnt", + vec![ + String::from("subvolume"), + String::from("create"), + String::from("@home"), + ], + ), + "create btrfs subvolume @home", + ); umount("/mnt"); mount(format!("{}2", device).as_str(), "/mnt/", "subvol=@"); - files_eval(files::create_directory("/mnt/boot"), "create directory /mnt/boot"); - files_eval(files::create_directory("/mnt/home"), "create directory /mnt/home"); + files_eval( + files::create_directory("/mnt/boot"), + "create directory /mnt/boot", + ); + files_eval( + files::create_directory("/mnt/home"), + "create directory /mnt/home", + ); mount(format!("{}2", device).as_str(), "/mnt/home", "subvol=@home"); mount(format!("{}1", device).as_str(), "/mnt/boot", ""); } @@ -203,17 +289,27 @@ fn part_disk(device: &str, efi: bool) { fn mount(partition: &str, mountpoint: &str, options: &str) { let options = if options.is_empty() { "\"\"" } else { options }; - exec_eval(exec( - "mount", - vec![ - String::from(partition), - String::from(mountpoint), - String::from("-o"), - String::from(options), - ], - ), format!("mount {} with options {} at {}", partition, options, mountpoint).as_str()); + exec_eval( + exec( + "mount", + vec![ + String::from(partition), + String::from(mountpoint), + String::from("-o"), + String::from(options), + ], + ), + format!( + "mount {} with options {} at {}", + partition, options, mountpoint + ) + .as_str(), + ); } fn umount(mountpoint: &str) { - exec_eval(exec("umount", vec![String::from(mountpoint)]), format!("unmount {}", mountpoint).as_str()); + exec_eval( + exec("umount", vec![String::from(mountpoint)]), + format!("unmount {}", mountpoint).as_str(), + ); } diff --git a/src/functions/users.rs b/src/functions/users.rs index b13f61c..61fee2a 100755 --- a/src/functions/users.rs +++ b/src/functions/users.rs @@ -2,56 +2,68 @@ use crate::internal::exec::*; use crate::internal::*; pub fn new_user(username: &str, hasroot: bool, password: &str) { - exec_eval(exec_chroot( - "useradd", - vec![ - String::from("-m"), - String::from("-s"), - String::from("/bin/bash"), - String::from(username), - ], - ), format!("Create user {}", username).as_str()); + exec_eval( + exec_chroot( + "useradd", + vec![ + String::from("-m"), + String::from("-s"), + String::from("/bin/bash"), + String::from(username), + ], + ), + format!("Create user {}", username).as_str(), + ); if hasroot { - exec_eval(exec_chroot( + exec_eval( + exec_chroot( + "usermod", + vec![ + String::from("-a"), + String::from("-G"), + String::from("wheel"), + String::from(username), + ], + ), + format!("Add user {} to wheel group", username).as_str(), + ); + } + exec_eval( + exec_chroot( "usermod", vec![ - String::from("-a"), - String::from("-G"), - String::from("wheel"), + String::from("--password"), + String::from("$(echo"), + format!("${}", password), + String::from("|"), + String::from("openssl"), + String::from("passwd"), + String::from("-1"), + String::from("-stdin)"), String::from(username), ], - ), format!("Add user {} to wheel group", username).as_str()); - } - exec_eval(exec_chroot( - "usermod", - vec![ - String::from("--password"), - String::from("$(echo"), - format!("${}", password), - String::from("|"), - String::from("openssl"), - String::from("passwd"), - String::from("-1"), - String::from("-stdin)"), - String::from(username), - ], - ), format!("Set password for user {}", username).as_str()); + ), + format!("Set password for user {}", username).as_str(), + ); } pub fn root_pass(root_pass: &str) { println!("Setting root password to '{}'", root_pass); - exec_eval(exec_chroot( - "usermod", - vec![ - String::from("--password"), - String::from("$(echo"), - format!("${{{}}}", root_pass), - String::from("|"), - String::from("openssl"), - String::from("passwd"), - String::from("-1"), - String::from("-stdin)"), - String::from("root"), - ], - ), "set root password"); + exec_eval( + exec_chroot( + "usermod", + vec![ + String::from("--password"), + String::from("$(echo"), + format!("${{{}}}", root_pass), + String::from("|"), + String::from("openssl"), + String::from("passwd"), + String::from("-1"), + String::from("-stdin)"), + String::from("root"), + ], + ), + "set root password", + ); } diff --git a/src/internal/exec.rs b/src/internal/exec.rs index 7878ce8..116db81 100755 --- a/src/internal/exec.rs +++ b/src/internal/exec.rs @@ -7,7 +7,7 @@ pub fn exec(command: &str, args: Vec) -> Result + args: Vec, ) -> Result { let returncode = Command::new("arch-chroot") .args(&["/mnt", command]) diff --git a/src/internal/mod.rs b/src/internal/mod.rs index 101aa40..b769472 100755 --- a/src/internal/mod.rs +++ b/src/internal/mod.rs @@ -1,8 +1,8 @@ pub mod exec; pub mod files; pub mod install; -pub mod strings; pub mod returncode_eval; +pub mod strings; pub fn install(pkgs: Vec<&str>) { install::install(pkgs); @@ -20,7 +20,10 @@ pub fn files_eval(returncode: std::result::Result<(), std::io::Error>, logmsg: & returncode_eval::files_eval(returncode, logmsg); } -pub fn exec_eval(returncode: std::result::Result, logmsg: &str) { +pub fn exec_eval( + returncode: std::result::Result, + logmsg: &str, +) { returncode_eval::exec_eval(returncode, logmsg); } diff --git a/src/internal/returncode_eval.rs b/src/internal/returncode_eval.rs index 762c2da..827bc2e 100755 --- a/src/internal/returncode_eval.rs +++ b/src/internal/returncode_eval.rs @@ -1,23 +1,32 @@ -use crate::internal::*; - -pub fn exec_eval(return_code: std::result::Result, logmsg: &str) { - match &return_code { - Ok(_) => { - log(format!("{}: Success", logmsg)); - } - Err(e) => { - crash(format!("{}: Failed with error: {}", logmsg, e), return_code.unwrap_err().raw_os_error().unwrap()); - } - } -} - -pub fn files_eval(return_code: std::result::Result<(), std::io::Error>, logmsg: &str) { - match &return_code { - Ok(_) => { - log(format!("[ \x1b[2;1;32mOK\x1b[0m ] {}", logmsg)); - } - Err(e) => { - crash(format!("[ \x1b[2;1;31mFAILED\x1b[0m ] {} ERROR: {}", logmsg, e), return_code.unwrap_err().raw_os_error().unwrap()); - } - } -} \ No newline at end of file +use crate::internal::*; + +pub fn exec_eval( + return_code: std::result::Result, + logmsg: &str, +) { + match &return_code { + Ok(_) => { + log(format!("{}: Success", logmsg)); + } + Err(e) => { + crash( + format!("{}: Failed with error: {}", logmsg, e), + return_code.unwrap_err().raw_os_error().unwrap(), + ); + } + } +} + +pub fn files_eval(return_code: std::result::Result<(), std::io::Error>, logmsg: &str) { + match &return_code { + Ok(_) => { + log(format!("[ \x1b[2;1;32mOK\x1b[0m ] {}", logmsg)); + } + Err(e) => { + crash( + format!("[ \x1b[2;1;31mFAILED\x1b[0m ] {} ERROR: {}", logmsg, e), + return_code.unwrap_err().raw_os_error().unwrap(), + ); + } + } +} diff --git a/src/main.rs b/src/main.rs index 5b97251..6930ebf 100755 --- a/src/main.rs +++ b/src/main.rs @@ -44,7 +44,7 @@ fn main() { Arg::with_name("efidir") .help("The directory to install the EFI bootloader to") .required(true), - ), + ), ) .subcommand( SubCommand::with_name("grub-legacy") @@ -96,7 +96,6 @@ fn main() { .help("Wether ipv6 should be enabled") .short("i6") .long("ipv6") - .required(true) .takes_value(false), ), ) @@ -161,8 +160,12 @@ fn main() { locale::set_keyboard(kbrlayout); locale::set_timezone(timezn); } else if let Some(app) = app.subcommand_matches("networking") { - if app.is_present("ipv6") { network::enable_ipv6() } - if app.is_present("create-hosts") { network::create_hosts() } + if app.is_present("ipv6") { + network::enable_ipv6() + } + if app.is_present("create-hosts") { + network::create_hosts() + } network::set_hostname(app.value_of("hostname").unwrap()) } else if let Some(app) = app.subcommand_matches("users") { if let Some(app) = app.subcommand_matches("newUser") { @@ -184,7 +187,7 @@ fn main() { } else if let Some(app) = app.subcommand_matches("grub-legacy") { base::install_bootloader_legacy(app.value_of("device").unwrap()); } - } else if let Some(_) = app.subcommand_matches("install-base") { + } else if app.subcommand_matches("install-base").is_some() { base::install_base_packages(); } else { println!("Running TUI installer");