added iso gui option

This commit is contained in:
JMARyA 2024-12-28 03:37:15 +01:00
parent e794bef718
commit 5c4945de60
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
4 changed files with 39 additions and 6 deletions

View file

@ -3,7 +3,11 @@ use clap::{arg, command};
pub fn get_args() -> clap::ArgMatches { pub fn get_args() -> clap::ArgMatches {
command!() command!()
.about("navOS Installer") .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( .subcommand(
command!() command!()
.name("install") .name("install")

View file

@ -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(without_gui: bool) {
pub fn create_iso() {
if !is_root() { if !is_root() {
eprintln!("Error: You need root to create an ISO"); eprintln!("Error: You need root to create an ISO");
std::process::exit(1); std::process::exit(1);
@ -12,6 +14,13 @@ pub fn create_iso() {
run_command(&cmd, None, false); 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(); std::fs::create_dir_all("./work").unwrap();
let mount_cmd = str_vec(vec![ let mount_cmd = str_vec(vec![

View file

@ -54,6 +54,25 @@ pub fn uncomment_first_value_of(value: &str, file: &str) {
std::fs::write(file, new).unwrap(); 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) { pub fn install(conf: InstallConfig) {
// Drive Setup // Drive Setup
format_drives(&conf.drive, conf.general.encryption); format_drives(&conf.drive, conf.general.encryption);

View file

@ -76,8 +76,9 @@ fn main() {
let args = args::get_args(); let args = args::get_args();
match args.subcommand() { match args.subcommand() {
Some(("create-iso", _)) => { Some(("create-iso", iso_args)) => {
create_iso(); let without_gui = iso_args.get_flag("without_gui");
create_iso(without_gui);
std::process::exit(0); std::process::exit(0);
} }
Some(("create-tar", _)) => { Some(("create-tar", _)) => {