parent
bc69d74ac2
commit
30e2db26ca
18 changed files with 257 additions and 337 deletions
57
src/main.rs
57
src/main.rs
|
@ -1,21 +1,18 @@
|
|||
use std::io::Write;
|
||||
|
||||
use config::InstallConfig;
|
||||
use nix::unistd::{Uid, getuid};
|
||||
|
||||
mod args;
|
||||
mod config;
|
||||
mod create_iso;
|
||||
mod install;
|
||||
mod linux;
|
||||
mod pkg;
|
||||
use create_iso::create_iso;
|
||||
use install::install;
|
||||
use linux::is_root;
|
||||
use yansi::{Color, Paint};
|
||||
|
||||
fn is_root() -> bool {
|
||||
getuid() == Uid::from_raw(0)
|
||||
}
|
||||
|
||||
fn print_status(msg: &str) {
|
||||
println!(
|
||||
"{} {}",
|
||||
|
@ -24,52 +21,6 @@ fn print_status(msg: &str) {
|
|||
);
|
||||
}
|
||||
|
||||
fn run_command(cmd: &[String], input: Option<&str>, inherit: bool) -> (String, String) {
|
||||
print_status(&cmd.join(" "));
|
||||
|
||||
let mut cmd_setup = std::process::Command::new(cmd[0].clone());
|
||||
let mut cmd_setup = cmd_setup.args(cmd.into_iter().skip(1).collect::<Vec<_>>());
|
||||
|
||||
if inherit {
|
||||
assert!(input.is_none());
|
||||
cmd_setup = cmd_setup
|
||||
.stdout(std::process::Stdio::inherit())
|
||||
.stdin(std::process::Stdio::inherit());
|
||||
} else {
|
||||
cmd_setup = cmd_setup.stdout(std::process::Stdio::piped());
|
||||
}
|
||||
|
||||
if input.is_some() {
|
||||
cmd_setup = cmd_setup.stdin(std::process::Stdio::piped());
|
||||
}
|
||||
|
||||
let mut child = cmd_setup.spawn().unwrap();
|
||||
|
||||
if let Some(input) = input {
|
||||
let stdin = child.stdin.as_mut().unwrap();
|
||||
stdin.write_all(input.as_bytes()).unwrap();
|
||||
stdin.flush().unwrap();
|
||||
}
|
||||
|
||||
let status = child.wait_with_output().unwrap();
|
||||
assert!(status.status.success());
|
||||
|
||||
let output = String::from_utf8(status.stdout).unwrap();
|
||||
let stderr = String::from_utf8(status.stderr).unwrap();
|
||||
|
||||
if !stderr.trim().is_empty() {
|
||||
if !inherit {
|
||||
eprintln!("{}", stderr);
|
||||
}
|
||||
}
|
||||
|
||||
if !inherit {
|
||||
println!("{}", output);
|
||||
}
|
||||
|
||||
(output, stderr)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
println!(
|
||||
"{}",
|
||||
|
@ -87,7 +38,7 @@ fn main() {
|
|||
let kb_variant: Option<&str> =
|
||||
iso_args.get_one("kb_variant").map(|x: &String| x.as_str());
|
||||
|
||||
create_iso(without_gui, &kb_layout, kb_variant);
|
||||
create_iso(without_gui, kb_layout, kb_variant);
|
||||
std::process::exit(0);
|
||||
}
|
||||
Some(("create-tar", _)) => {
|
||||
|
@ -163,7 +114,7 @@ fn main() {
|
|||
}
|
||||
|
||||
// Run the
|
||||
install(conf)
|
||||
install(conf);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue