cli
All checks were successful
ci/woodpecker/push/build Pipeline was successful

This commit is contained in:
JMARyA 2024-12-27 07:11:37 +01:00
parent b9267827ee
commit 620b699069
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
4 changed files with 269 additions and 49 deletions

174
Cargo.lock generated
View file

@ -2,6 +2,55 @@
# It is not intended for manual editing. # It is not intended for manual editing.
version = 4 version = 4
[[package]]
name = "anstream"
version = "0.6.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b"
dependencies = [
"anstyle",
"anstyle-parse",
"anstyle-query",
"anstyle-wincon",
"colorchoice",
"is_terminal_polyfill",
"utf8parse",
]
[[package]]
name = "anstyle"
version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9"
[[package]]
name = "anstyle-parse"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b2d16507662817a6a20a9ea92df6652ee4f94f914589377d69f3b21bc5798a9"
dependencies = [
"utf8parse",
]
[[package]]
name = "anstyle-query"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "79947af37f4177cfead1110013d678905c37501914fba0efea834c3fe9a8d60c"
dependencies = [
"windows-sys",
]
[[package]]
name = "anstyle-wincon"
version = "3.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2109dbce0e72be3ec00bed26e6a7479ca384ad226efdd66db8fa2e3a38c83125"
dependencies = [
"anstyle",
"windows-sys",
]
[[package]] [[package]]
name = "bitflags" name = "bitflags"
version = "2.6.0" version = "2.6.0"
@ -20,6 +69,39 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724"
[[package]]
name = "clap"
version = "4.5.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3135e7ec2ef7b10c6ed8950f0f792ed96ee093fa088608f1c76e569722700c84"
dependencies = [
"clap_builder",
]
[[package]]
name = "clap_builder"
version = "4.5.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "30582fc632330df2bd26877bde0c1f4470d57c582bbc070376afcd04d8cb4838"
dependencies = [
"anstream",
"anstyle",
"clap_lex",
"strsim",
]
[[package]]
name = "clap_lex"
version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6"
[[package]]
name = "colorchoice"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990"
[[package]] [[package]]
name = "equivalent" name = "equivalent"
version = "1.0.1" version = "1.0.1"
@ -42,6 +124,12 @@ dependencies = [
"hashbrown", "hashbrown",
] ]
[[package]]
name = "is_terminal_polyfill"
version = "1.70.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.169" version = "0.2.169"
@ -58,6 +146,7 @@ checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
name = "navinstall" name = "navinstall"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"clap",
"nix", "nix",
"serde", "serde",
"toml", "toml",
@ -122,6 +211,12 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "strsim"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
[[package]] [[package]]
name = "syn" name = "syn"
version = "2.0.91" version = "2.0.91"
@ -173,6 +268,85 @@ version = "1.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83"
[[package]]
name = "utf8parse"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]]
name = "windows-sys"
version = "0.59.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
dependencies = [
"windows-targets",
]
[[package]]
name = "windows-targets"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_gnullvm",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
[[package]]
name = "windows_aarch64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
[[package]]
name = "windows_i686_gnu"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
[[package]]
name = "windows_i686_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
[[package]]
name = "windows_i686_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
[[package]]
name = "windows_x86_64_gnu"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
[[package]]
name = "windows_x86_64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
[[package]] [[package]]
name = "winnow" name = "winnow"
version = "0.6.20" version = "0.6.20"

View file

@ -4,6 +4,7 @@ version = "0.1.0"
edition = "2024" edition = "2024"
[dependencies] [dependencies]
clap = { version = "4.5.23", features = ["cargo"] }
nix = { version = "0.29.0", features = ["user"] } nix = { version = "0.29.0", features = ["user"] }
serde = { version = "1.0.216", features = ["derive"] } serde = { version = "1.0.216", features = ["derive"] }
toml = "0.8.19" toml = "0.8.19"

25
src/args.rs Normal file
View file

@ -0,0 +1,25 @@
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!()
.name("install")
.about("Install a system according to configuration")
.arg(arg!([config] "Config file").required(true)),
)
.subcommand(
command!()
.name("create-tar")
.about("Create a container tar image"),
)
.subcommand(
command!()
.name("create-img")
.about("Create an install on a disk image for VMs or embedded devices")
.arg(arg!([config] "Config file").required(true)),
)
.get_matches()
}

View file

@ -3,12 +3,16 @@ use std::io::Write;
use config::{DriveConfig, GeneralConfig, InstallConfig}; use config::{DriveConfig, GeneralConfig, InstallConfig};
use nix::unistd::{Uid, getuid}; use nix::unistd::{Uid, getuid};
mod args;
mod config; mod config;
fn is_root() -> bool { fn is_root() -> bool {
getuid() == Uid::from_raw(0) getuid() == Uid::from_raw(0)
} }
// TODO : Setup users
// TODO : Setup ssh (config + authorized_keys)
// DRIVE SELECTION // DRIVE SELECTION
pub fn str_vec(v: Vec<&str>) -> Vec<String> { pub fn str_vec(v: Vec<&str>) -> Vec<String> {
@ -180,21 +184,40 @@ fn run_command(cmd: &[String], input: Option<&str>, inherit: bool) -> (String, S
fn main() { fn main() {
println!("⚠️ Warning: This is an alpha version of the installer. DO NOT USE in PROD"); println!("⚠️ Warning: This is an alpha version of the installer. DO NOT USE in PROD");
let args: Vec<String> = std::env::args().collect(); let args = args::get_args();
// TODO : Cleanup CLI interface match args.subcommand() {
Some(("create-iso", _)) => {
if args.get(1).unwrap() == "create-iso" {
create_iso(); create_iso();
std::process::exit(0); std::process::exit(0);
} }
Some(("create-tar", _)) => {
println!("Tar creation is not yet supported");
unimplemented!()
}
Some(("create-img", install_args)) => {
let config_file: &String = install_args.get_one("config").unwrap();
let config_content = std::fs::read_to_string(config_file);
if args.len() < 2 { let conf: InstallConfig = match config_content {
eprintln!("Error: No configuration file provided."); Ok(content) => match toml::from_str(&content) {
Ok(config) => config,
Err(e) => {
eprintln!("Error: Could not deserialize TOML file. {e}");
std::process::exit(1); std::process::exit(1);
} }
},
Err(_) => {
eprintln!("Error: Could not read config file.");
std::process::exit(1);
}
};
let config_file = &args[1]; println!("Installing to a disk image is not yet supported");
unimplemented!()
}
Some(("install", install_args)) => {
let config_file: &String = install_args.get_one("config").unwrap();
let config_content = std::fs::read_to_string(config_file); let config_content = std::fs::read_to_string(config_file);
let conf: InstallConfig = match config_content { let conf: InstallConfig = match config_content {
@ -230,6 +253,9 @@ fn main() {
// Run the // Run the
install(conf) install(conf)
} }
_ => {}
}
}
pub fn create_iso() { pub fn create_iso() {
// TODO : Check if root // TODO : Check if root
@ -269,9 +295,3 @@ pub fn create_iso() {
std::fs::remove_dir_all("./work").unwrap(); std::fs::remove_dir_all("./work").unwrap();
} }
// TODO : CLI
// navos create-iso
// navos create-tar
// navos create-img
// navos install