diff --git a/src/builder.rs b/src/builder.rs index a5faeca..22c94f0 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -1,4 +1,4 @@ -use std::process::Command; +use std::process::{Command, Stdio}; use based::get_pg; @@ -72,6 +72,29 @@ impl BuildEnv { .unwrap(); } + pub fn run_command_inherit(&self, cmd: &str) -> bool { + let output = Command::new("systemd-nspawn") + .arg("-D") + .arg(self.path()) + .arg("--bind") + .arg("./pacman.conf:/etc/pacman.conf") + .arg("bash") + .arg("-c") + .arg(cmd) + .stdout(Stdio::inherit()) + .output() + .expect("Failed to run systemd-nspawn container"); + + let success = output.status.success(); + + if !success { + let stderr = String::from_utf8_lossy(&output.stderr).to_string(); + log::error!("Error running command: {stderr}"); + } + + success + } + pub fn run_command(&self, cmd: &str) -> (bool, String) { let output = Command::new("systemd-nspawn") .arg("-D") @@ -133,7 +156,7 @@ pub async fn build(pkg: &PackageIndex) -> (String, Vec<(String, Vec)>) { } ); - let (success, stdout) = base_env.run_command( + let success = base_env.run_command_inherit( r#"cd /build;pacman -Syu --noconfirm;useradd -m build;echo "ALL ALL=(ALL) NOPASSWD: ALL"|tee -a /etc/sudoers;chown -R build /build;su -c "makepkg -c -C -s --noconfirm --skippgpcheck" build"#); if success { @@ -183,7 +206,7 @@ pub async fn build(pkg: &PackageIndex) -> (String, Vec<(String, Vec)>) { .await; } - (stdout, packages) + (String::new(), packages) } else { log::error!( "Error building {} / {} @ {}{}", @@ -196,6 +219,6 @@ pub async fn build(pkg: &PackageIndex) -> (String, Vec<(String, Vec)>) { String::new() } ); - (stdout, Vec::new()) + (String::new(), Vec::new()) } }