SHA256
More work on install stage
This commit is contained in:
1 parent
029df21d3e
commit
1399c56135
3 files changed
+176
-14
No files matched your search
+58
-5
@@ -124,6 +124,62 @@ fn exec_command_out(cmd: &str, args: &Vec<&str>) -> Result<String, ExecCommandEr
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
/// Exec command and logs its output via log::info! in real time
|
||||
///
|
||||
fn exec_command_log(cmd: &str, args: &Vec<&str>) -> Result<(), ExecCommandError> {
|
||||
use std::io::{BufRead, BufReader};
|
||||
use std::process::{Command, Stdio};
|
||||
use std::thread;
|
||||
|
||||
log::debug!("Executing command {} {:?}", cmd, args);
|
||||
|
||||
// Configure the command to pipe stdout
|
||||
let mut child = Command::new(cmd)
|
||||
.args(args)
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
.spawn()?;
|
||||
|
||||
// Take ownership of the stdout handle
|
||||
let stdout = child
|
||||
.stdout
|
||||
.take()
|
||||
.ok_or("Failed to capture stdout".to_string())?;
|
||||
let mut stderr = child
|
||||
.stderr
|
||||
.take()
|
||||
.ok_or("Failed to capture stderr".to_string())?;
|
||||
|
||||
let stderr_handle = thread::spawn(move || {
|
||||
let mut buf = Vec::new();
|
||||
use std::io::Read;
|
||||
let _ = stderr.read_to_end(&mut buf);
|
||||
buf
|
||||
});
|
||||
|
||||
// Wrap in BufReader for efficient line-by-line reading
|
||||
let reader = BufReader::new(stdout);
|
||||
|
||||
// Iterate and log each line in real time
|
||||
for line in reader.lines() {
|
||||
match line {
|
||||
Ok(text) => log::info!("{}: {}", cmd, text),
|
||||
Err(e) => log::error!("Read error: {}", e),
|
||||
}
|
||||
}
|
||||
|
||||
// Wait for the process to finish to prevent zombies and check status
|
||||
let status = child.wait()?;
|
||||
let stderr_output = stderr_handle.join().unwrap();
|
||||
|
||||
if status.success() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(CommandFailed::new(cmd, args, stderr_output).into())
|
||||
}
|
||||
}
|
||||
|
||||
/// sync system time with chrony
|
||||
/// dinitctl start chrony
|
||||
pub fn dinit_sync_time_chrony() -> Result<(), ExecCommandError> {
|
||||
@@ -133,7 +189,7 @@ pub fn dinit_sync_time_chrony() -> Result<(), ExecCommandError> {
|
||||
/// Install base system
|
||||
/// basestrap /mnt base base-devel dinit elogind-dinit
|
||||
pub fn basestrap_dinit(root_dir: &str) -> Result<(), ExecCommandError> {
|
||||
exec_command(
|
||||
exec_command_log(
|
||||
"basestrap",
|
||||
&vec![root_dir, "base", "base-devel", "dinit", "elogind-dinit"],
|
||||
)
|
||||
@@ -142,10 +198,7 @@ pub fn basestrap_dinit(root_dir: &str) -> Result<(), ExecCommandError> {
|
||||
pub fn basestrap(root_dir: &str, pkg_list: &[&str]) -> Result<(), ExecCommandError> {
|
||||
let mut args: Vec<&str> = vec![root_dir];
|
||||
args.extend(pkg_list);
|
||||
exec_command(
|
||||
"basestrap",
|
||||
&args,
|
||||
)
|
||||
exec_command_log("basestrap", &args)
|
||||
}
|
||||
|
||||
/// Executes parted command with given arguments
|
||||
|
||||
Reference in new issue
Block a user