From 5c4945de603540207b8e21a71e09fa54383f3cb2 Mon Sep 17 00:00:00 2001 From: JMARyA Date: Sat, 28 Dec 2024 03:37:15 +0100 Subject: [PATCH] added iso gui option --- src/args.rs | 6 +++++- src/create_iso.rs | 15 ++++++++++++--- src/install/mod.rs | 19 +++++++++++++++++++ src/main.rs | 5 +++-- 4 files changed, 39 insertions(+), 6 deletions(-) diff --git a/src/args.rs b/src/args.rs index 643ccc9..d61d4c2 100644 --- a/src/args.rs +++ b/src/args.rs @@ -3,7 +3,11 @@ use clap::{arg, command}; pub fn get_args() -> clap::ArgMatches { command!() .about("navOS Installer") - .subcommand(command!("create-iso").about("Create a new installation medium ISO")) + .subcommand( + command!("create-iso") + .about("Create a new installation medium ISO") + .arg(arg!(--without_gui "Create ISO with just terminal")), + ) .subcommand( command!() .name("install") diff --git a/src/create_iso.rs b/src/create_iso.rs index 96665dd..360e239 100644 --- a/src/create_iso.rs +++ b/src/create_iso.rs @@ -1,7 +1,9 @@ -use crate::{install::str_vec, is_root, run_command}; +use crate::{ + install::{str_vec, uncomment_tag}, + is_root, run_command, +}; -// TODO : Make GUI in install medium optional with arg `--with-gui` -pub fn create_iso() { +pub fn create_iso(without_gui: bool) { if !is_root() { eprintln!("Error: You need root to create an ISO"); std::process::exit(1); @@ -12,6 +14,13 @@ pub fn create_iso() { run_command(&cmd, None, false); } + if without_gui { + std::fs::remove_file("./iso/airootfs/etc/systemd/system/display-manager.service").unwrap(); + } else { + println!("Adding GUI packages"); + uncomment_tag("#gui: ", "./iso/packages.x86_64"); + } + std::fs::create_dir_all("./work").unwrap(); let mount_cmd = str_vec(vec![ diff --git a/src/install/mod.rs b/src/install/mod.rs index 636059c..ef44191 100644 --- a/src/install/mod.rs +++ b/src/install/mod.rs @@ -54,6 +54,25 @@ pub fn uncomment_first_value_of(value: &str, file: &str) { std::fs::write(file, new).unwrap(); } +pub fn uncomment_tag(tag: &str, file: &str) { + // read in the file + let content = std::fs::read_to_string(file).unwrap(); + let mut new = String::new(); + + // search for the first instance of `value` in the file + // uncomment the '#' symbol if there is one + for line in content.lines() { + if line.starts_with(tag) { + new.push_str(&format!("{}\n", line.trim_start_matches(tag))); + } else { + new.push_str(&format!("{line}\n")); + } + } + + // write back + std::fs::write(file, new).unwrap(); +} + pub fn install(conf: InstallConfig) { // Drive Setup format_drives(&conf.drive, conf.general.encryption); diff --git a/src/main.rs b/src/main.rs index fe3d06c..6fda904 100644 --- a/src/main.rs +++ b/src/main.rs @@ -76,8 +76,9 @@ fn main() { let args = args::get_args(); match args.subcommand() { - Some(("create-iso", _)) => { - create_iso(); + Some(("create-iso", iso_args)) => { + let without_gui = iso_args.get_flag("without_gui"); + create_iso(without_gui); std::process::exit(0); } Some(("create-tar", _)) => {