From 73f0801b0d7545c49ab53947df0edf0b9b2cd6f8 Mon Sep 17 00:00:00 2001 From: Amy Date: Fri, 21 Jan 2022 19:43:42 +0100 Subject: [PATCH] redo project structure and add logic for desktop setup --- .gitignore | 1 + src/functions/desktops.rs | 35 +++++++++++++ src/{installer => functions}/mod.rs | 0 src/{installer => functions}/network.rs | 0 src/{installer => functions}/partition.rs | 0 src/{installer => functions}/users.rs | 0 src/installer/desktops.rs | 45 ---------------- src/internal/install.rs | 5 ++ src/internal/mod.rs | 37 +++++++++++++ src/internal/strings.rs | 63 +++++++++++++++++++++++ src/main.rs | 19 ++----- 11 files changed, 146 insertions(+), 59 deletions(-) create mode 100755 src/functions/desktops.rs rename src/{installer => functions}/mod.rs (100%) rename src/{installer => functions}/network.rs (100%) rename src/{installer => functions}/partition.rs (100%) rename src/{installer => functions}/users.rs (100%) delete mode 100755 src/installer/desktops.rs create mode 100644 src/internal/install.rs create mode 100644 src/internal/mod.rs create mode 100644 src/internal/strings.rs diff --git a/.gitignore b/.gitignore index ea8c4bf..869df07 100755 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /target +Cargo.lock \ No newline at end of file diff --git a/src/functions/desktops.rs b/src/functions/desktops.rs new file mode 100755 index 0000000..cb9c147 --- /dev/null +++ b/src/functions/desktops.rs @@ -0,0 +1,35 @@ +use crate::internal::*; + +pub fn choose_pkgs(desktop_setup: &str) { + println!("Installing {}", desktop_setup); + match desktop_setup { + "onyx" => { + install(vec!("onyx", "lightdm", "lightdm-gtk-greeter", "lightdm-gtk-greeter-settings")); + } + "gnome" => { + install(vec!("gnome","gnome-tweaks","chrome-gnome-shell","gdm")); + }, + "kde" => { + install(vec!("kde", "plasma", "plasma-wayland-session", "kde-applications", "sddm")); + }, + "budgie" => { + install(vec!("budgie-desktop", "gnome", "lightdm", "lightdm-gtk-greeter", "lightdm-gtk-greeter-settings")); + }, + "cinnamon" => { + install(vec!("cinnamon", "lightdm", "lightdm-gtk-greeter", "lightdm-gtk-greeter-settings", "metacity", "gnome-shell")); + }, + "mate" => { + install(vec!("mate", "lightdm", "lightdm-gtk-greeter", "lightdm-gtk-greeter-settings", "mate-extra")); + }, + "xfce" => { + install(vec!("xfce4", "lightdm", "lightdm-gtk-greeter", "lightdm-gtk-greeter-settings", "xfce4-goodies")); + }, + "enlightenment" => { + install(vec!("enlightenment", "lightdm", "lightdm-gtk-greeter", "lightdm-gtk-greeter-settings", "terminology")); + }, + + _ => { + crash("Unknown desktop setup".to_string(), 1); + } + } +} \ No newline at end of file diff --git a/src/installer/mod.rs b/src/functions/mod.rs similarity index 100% rename from src/installer/mod.rs rename to src/functions/mod.rs diff --git a/src/installer/network.rs b/src/functions/network.rs similarity index 100% rename from src/installer/network.rs rename to src/functions/network.rs diff --git a/src/installer/partition.rs b/src/functions/partition.rs similarity index 100% rename from src/installer/partition.rs rename to src/functions/partition.rs diff --git a/src/installer/users.rs b/src/functions/users.rs similarity index 100% rename from src/installer/users.rs rename to src/functions/users.rs diff --git a/src/installer/desktops.rs b/src/installer/desktops.rs deleted file mode 100755 index caf8028..0000000 --- a/src/installer/desktops.rs +++ /dev/null @@ -1,45 +0,0 @@ -pub fn choose_pkgs(desktop_setup: &str, de: &str, dm: &str) { - if desktop_setup == "custom" { - install_desktop(de, dm); - } else { - println!("Installing {}", desktop_setup); - match desktop_setup { - "onyx" => { - install_desktop("onyx", "lightdm"); - } - "gnome" => { - install_desktop("gnome", "gdm"); - }, - "kde" => { - install_desktop("kde", "sddm"); - }, - "budgie" => { - install_desktop("budgie", "lightdm"); - }, - "cinnamon" => { - install_desktop("cinnamon", "lightdm"); - }, - "mate" => { - install_desktop("mate", "lightdm"); - }, - "xfce" => { - install_desktop("xfce", "lightdm"); - }, - "pantheon" => { - install_desktop("pantheon", "lightdm"); - }, - "enlightenment" => { - install_desktop("enlightenment", "lightdm"); - }, - - _ => { - println!("Unknown desktop setup"); - } - } - } -} - -fn install_desktop(de: &str, dm: &str) { - println!("Installing {}", de); - println!("Installing {}", dm); -} \ No newline at end of file diff --git a/src/internal/install.rs b/src/internal/install.rs new file mode 100644 index 0000000..ed226a0 --- /dev/null +++ b/src/internal/install.rs @@ -0,0 +1,5 @@ +use std::process::Command; + +pub fn install(pkgs: Vec<&str>) { + Command::new("pacman").arg("-S").args(pkgs).output().expect("Failed to install packages"); +} \ No newline at end of file diff --git a/src/internal/mod.rs b/src/internal/mod.rs new file mode 100644 index 0000000..9f7b2bd --- /dev/null +++ b/src/internal/mod.rs @@ -0,0 +1,37 @@ +pub mod install; +pub mod strings; + +pub fn install(pkgs: Vec<&str>) { + install::install(pkgs); +} + +pub fn info(a: String) { + strings::info(a); +} + +pub fn crash(a: String, b: i32) { + strings::crash(a, b); +} + +pub fn log(a: String) { + strings::log(a); +} + +pub fn prompt(a: String, b: bool) -> bool { + strings ::prompt(a, b) +} + +#[macro_export] +macro_rules! uwu { + ($x:expr) => {{ + let uwu: String = String::from_str($x).unwrap(); + let uwu = uwu.replace("l", "w"); + let uwu = uwu.replace("L", "W"); + let uwu = uwu.replace("r", "w"); + let uwu = uwu.replace("R", "W"); + let uwu = uwu.replace("na", "nya"); + let uwu = uwu.replace("Na", "Nya"); + let uwu = uwu.replace("NA", "NYA"); + uwu + }}; +} \ No newline at end of file diff --git a/src/internal/strings.rs b/src/internal/strings.rs new file mode 100644 index 0000000..f0bab70 --- /dev/null +++ b/src/internal/strings.rs @@ -0,0 +1,63 @@ +use std::{env, io}; +use std::io::Write; +use std::process::exit; +use std::str::FromStr; +use std::time::UNIX_EPOCH; +use crate::uwu; +pub fn info(a: String) { + let a = if env::var("JADE_UWU").unwrap_or_else(|_| "".to_string()) == "true" { + uwu!(&a) + } else { + a + }; + println!("\x1b[2;22;35m❖\x1b[0m \x1b[1;37m{}\x1b[0m", a) +} +pub fn crash(a: String, b: i32) { + let a = if env::var("JADE_UWU").unwrap_or_else(|_| "".to_string()) == "true" { + uwu!(&a) + } else { + a + }; + println!("\x1b[2;22;31m❌:\x1b[0m \x1b[1;91m{}\x1b[0m", a); + exit(b); +} +pub fn log(a: String) { + let a = if env::var("JADE_UWU").unwrap_or_else(|_| "".to_string()) == "true" + && env::var("JADE_UWU_DEBUG").unwrap_or_else(|_| "".to_string()) == "true" + { + uwu!(&a) + } else { + a + }; + eprintln!( + "{} {}", + std::time::SystemTime::now() + .duration_since(UNIX_EPOCH) + .unwrap() + .as_secs(), + a + ); +} +pub fn prompt(a: String, b: bool) -> bool { + let default = ["[Y/n]", "[y/N]"]; + let i = if b { 0 } else { 1 }; + let a = if env::var("JADE_UWU").unwrap_or_else(|_| "".to_string()) == "true" { + uwu!(&a) + } else { + a + }; + print!( + "\x1b[2;22;35m?\x1b[0m \x1b[1;37m{}\x1b[0m \x1b[2;22;37m{}\x1b[0m: ", + a, default[i] + ); + let mut yn: String = String::new(); + io::stdout().flush().ok(); + let _ = std::io::stdin().read_line(&mut yn); + if yn.trim().to_lowercase() == "n" || yn.trim().to_lowercase() == "no" { + false + } else if yn.trim().to_lowercase() == "y" || yn.trim().to_lowercase() == "yes" { + true + } else { + b + } +} diff --git a/src/main.rs b/src/main.rs index d2df6a3..9979078 100755 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ -mod installer; +mod functions; +mod internal; -use crate::installer::*; +use crate::functions::*; use clap::{App, Arg, SubCommand}; fn main() { @@ -96,17 +97,7 @@ fn main() { Arg::with_name("desktopsetup") .help("The desktop setup to use") .required(true), - ) - .arg( - Arg::with_name("de") - .help("The Desktop envionment to install (only read if desktopsetup is set to custom)") - .required_if("desktopsetup", "custom"), - ) - .arg( - Arg::with_name("dm") - .help("The Display Manager to install (only read if desktopsetup is set to custom)") - .required_if("desktopsetup", "custom"), - ), + ), ).get_matches(); @@ -131,7 +122,7 @@ fn main() { users::root_pass(app.value_of("rootPass").unwrap()); } } else if let Some(app) = app.subcommand_matches("desktops") { - desktops::choose_pkgs(app.value_of("desktopsetup").unwrap(), app.value_of("de").unwrap_or("none"), app.value_of("dm").unwrap_or("none")); + desktops::choose_pkgs(app.value_of("desktopsetup").unwrap()); } else { println!("Running TUI installer"); }