fix #1 unattended install option
All checks were successful
ci/woodpecker/push/build Pipeline was successful
All checks were successful
ci/woodpecker/push/build Pipeline was successful
This commit is contained in:
parent
601d32bc92
commit
dd581a69f5
3 changed files with 58 additions and 18 deletions
|
@ -8,12 +8,14 @@ pub fn get_args() -> clap::ArgMatches {
|
|||
.about("Create a new installation medium ISO")
|
||||
.arg(arg!(--without_gui "Create ISO with just terminal"))
|
||||
.arg(arg!(--kb_layout <LAYOUT> "Create ISO with this keyboard layout"))
|
||||
.arg(arg!(--kb_variant <VARIANT> "Create ISO with this keyboard layout variant")),
|
||||
.arg(arg!(--kb_variant <VARIANT> "Create ISO with this keyboard layout variant"))
|
||||
.arg(arg!(--install <CONFIG> "Create ISO which automatically installs <CONFIG> upon boot."))
|
||||
)
|
||||
.subcommand(
|
||||
command!()
|
||||
.name("install")
|
||||
.about("Install a system according to configuration")
|
||||
.arg(arg!(-f --force "Install without confirming config"))
|
||||
.arg(arg!([config] "Config file").required(true)),
|
||||
)
|
||||
.subcommand(
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
use crate::{install::uncomment_tag, is_root, linux::run_command, print_status};
|
||||
use yansi::{Color, Paint};
|
||||
|
||||
use crate::{expect_yes, install::uncomment_tag, is_root, linux::run_command, print_status};
|
||||
|
||||
/// Build the `kxkbrc` file for the given `layout` and `variant
|
||||
pub fn build_kxkbrc(layout: &str, variant: Option<&str>) -> String {
|
||||
|
@ -11,24 +13,42 @@ pub fn build_kxkbrc(layout: &str, variant: Option<&str>) -> String {
|
|||
res
|
||||
}
|
||||
|
||||
pub fn create_iso(without_gui: bool, kb_layout: &str, kb_variant: Option<&str>) {
|
||||
pub fn create_iso(
|
||||
without_gui: bool,
|
||||
kb_layout: &str,
|
||||
kb_variant: Option<&str>,
|
||||
install: Option<&String>,
|
||||
) {
|
||||
if !is_root() {
|
||||
eprintln!("Error: You need root to create an ISO");
|
||||
std::process::exit(1);
|
||||
}
|
||||
|
||||
if install.is_some() {
|
||||
println!(
|
||||
"{} The --install option will create an ISO file which immidiately upon boot installs the selected config.",
|
||||
"WARNING:".paint(Color::Yellow)
|
||||
);
|
||||
print!("{}", "DISCLAIMER: I know that this could be dangerous and I myself am ultimately responsible for any damages [yes/no]: ".paint(Color::Red));
|
||||
expect_yes();
|
||||
}
|
||||
|
||||
if !std::fs::exists("./iso").unwrap() {
|
||||
let cmd = vec!["git", "clone", "https://git.hydrar.de/navos/iso"];
|
||||
run_command(&cmd, None, false);
|
||||
}
|
||||
|
||||
if without_gui {
|
||||
if without_gui || install.is_some() {
|
||||
std::fs::remove_file("./iso/airootfs/etc/systemd/system/display-manager.service").unwrap();
|
||||
} else {
|
||||
print_status("Adding GUI packages");
|
||||
uncomment_tag("#gui: ", "./iso/packages.x86_64");
|
||||
}
|
||||
|
||||
if let Some(install_conf) = install {
|
||||
setup_auto_install(&install_conf);
|
||||
}
|
||||
|
||||
print_status("Setting keyboard layout");
|
||||
std::fs::create_dir_all("./iso/airootfs/etc/skel/.config").unwrap();
|
||||
std::fs::write(
|
||||
|
@ -53,3 +73,13 @@ pub fn create_iso(without_gui: bool, kb_layout: &str, kb_variant: Option<&str>)
|
|||
|
||||
std::fs::remove_dir_all("./work").unwrap();
|
||||
}
|
||||
|
||||
pub fn setup_auto_install(conf: &str) {
|
||||
print_status("Setting up automatic install upon boot");
|
||||
std::fs::copy(conf, "./iso/airootfs/root/config.toml").unwrap();
|
||||
std::fs::write(
|
||||
"./iso/airootfs/root/.zshrc",
|
||||
"navinstall install --force /root/config.toml;sleep 30;reboot\n",
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
|
36
src/main.rs
36
src/main.rs
|
@ -39,8 +39,9 @@ fn main() {
|
|||
let kb_layout: &String = iso_args.get_one("kb_layout").unwrap_or(&kb_layout_default);
|
||||
let kb_variant: Option<&str> =
|
||||
iso_args.get_one("kb_variant").map(|x: &String| x.as_str());
|
||||
let auto_install_config: Option<&String> = iso_args.get_one("install");
|
||||
|
||||
create_iso(without_gui, kb_layout, kb_variant);
|
||||
create_iso(without_gui, kb_layout, kb_variant, auto_install_config);
|
||||
std::process::exit(0);
|
||||
}
|
||||
Some(("create-tar", _)) => {
|
||||
|
@ -79,6 +80,7 @@ fn main() {
|
|||
}
|
||||
|
||||
let config_file: &String = install_args.get_one("config").unwrap();
|
||||
let force = install_args.get_flag("force");
|
||||
let config_content = std::fs::read_to_string(config_file);
|
||||
|
||||
let conf: InstallConfig = match config_content {
|
||||
|
@ -99,19 +101,10 @@ fn main() {
|
|||
}
|
||||
};
|
||||
|
||||
print_config(&conf);
|
||||
print!("Do you want to proceed with this configuration? (yes/no) ");
|
||||
|
||||
let mut input = String::new();
|
||||
std::io::stdout().flush().expect("Error flushing stdout.");
|
||||
std::io::stdin()
|
||||
.read_line(&mut input)
|
||||
.expect("Error reading input.");
|
||||
let input = input.trim().to_lowercase();
|
||||
|
||||
if input != "yes" {
|
||||
println!("Installation aborted.");
|
||||
std::process::exit(0);
|
||||
if !force {
|
||||
print_config(&conf);
|
||||
print!("Do you want to proceed with this configuration? (yes/no) ");
|
||||
expect_yes();
|
||||
}
|
||||
|
||||
// Run the
|
||||
|
@ -120,3 +113,18 @@ fn main() {
|
|||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
/// Read user input and exit if the input is not "yes"
|
||||
pub fn expect_yes() {
|
||||
let mut input = String::new();
|
||||
std::io::stdout().flush().expect("Error flushing stdout.");
|
||||
std::io::stdin()
|
||||
.read_line(&mut input)
|
||||
.expect("Error reading input.");
|
||||
let input = input.trim().to_lowercase();
|
||||
|
||||
if input != "yes" {
|
||||
println!("Installation aborted.");
|
||||
std::process::exit(0);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue