xbp 0.9.1

XBP is a zero-config build pack that can also interact with proxies, kafka, sockets, synthetic monitors.
Documentation
//! Setup command module
//!
//! Installs common system packages required by deployments. The command runs a
//! curated `apt install` invocation and reports progress and errors. Intended
//! for Ubuntu/Debian systems.
use std::process::Output;
use std::time::Instant;
use tokio::process::Command;
use tracing::{debug, info};

use crate::logging::{log_timed, LogLevel};

/// Execute the `setup` command.
///
/// Runs a non-interactive set of package installs. When `debug` is true, prints
/// the command and raw output for diagnostics.
pub async fn run_setup(debug: bool) -> Result<(), String> {
    let setup_cmd: String = "sudo apt install -y net-tools nginx pkg-config libssl-dev build-essential plocate sshpass neofetch certbot python3-certbot-nginx".to_string();
    if debug {
        debug!("Running setup command: {}", setup_cmd);
    }
    let start: Instant = Instant::now();
    let output: Output = Command::new("sh")
        .arg("-c")
        .arg(setup_cmd)
        .output()
        .await
        .map_err(|e| format!("Failed to execute setup command: {}", e))?;

    let elapsed = start.elapsed();
    let _ = log_timed(
        LogLevel::Success,
        "setup",
        "Setup completed",
        elapsed.as_millis() as u64,
    )
    .await;

    if debug {
        debug!("Setup command output: {:?}", output);
        debug!("Setup command took: {:.2?}", elapsed);
    }

    if !output.status.success() {
        return Err(format!(
            "Setup failed: {}",
            String::from_utf8_lossy(&output.stderr)
        ));
    }

    if !output.stdout.is_empty() {
        info!("Setup output: {}", String::from_utf8_lossy(&output.stdout));
    }

    info!("Setup completed successfully!");
    Ok(())
}