add untested homebrew support

This commit is contained in:
zyl 2024-10-17 18:27:41 -07:00
parent c1da19e352
commit 405cf3aba8
Signed by: zyl
SSH key fingerprint: SHA256:uxxbSXbdroP/OnKBGnEDk5q7EKB2razvstC/KmzdXXs
2 changed files with 47 additions and 12 deletions

View file

@ -77,8 +77,13 @@ async fn pupdate_remote(
Ok((remote, success)) Ok((remote, success))
} }
/// pupdates the local system using apt-get /// helper for pupdates which both follow the "X update && X upgrade" set of commands (e.g. apt-get and brew)
async fn pupdate_apt(log_dir: Option<PathBuf>) -> eyre::Result<bool> { async fn update_and_upgrade(
log_dir: Option<PathBuf>,
command: &str,
with_sudo: bool,
yes: bool,
) -> eyre::Result<bool> {
async fn log(outputs: &[std::process::Output], log_dir: Option<PathBuf>) -> eyre::Result<bool> { async fn log(outputs: &[std::process::Output], log_dir: Option<PathBuf>) -> eyre::Result<bool> {
if let Some(log_dir) = log_dir { if let Some(log_dir) = log_dir {
let mut stdout = File::create(log_dir.join("local.stdout.log")).await?; let mut stdout = File::create(log_dir.join("local.stdout.log")).await?;
@ -96,23 +101,42 @@ async fn pupdate_apt(log_dir: Option<PathBuf>) -> eyre::Result<bool> {
Ok(true) Ok(true)
} }
let update_output = Command::new("sudo") fn command_with_sudo(command: &str, with_sudo: bool) -> Command {
.arg("apt-get") if with_sudo {
let mut cmd = Command::new("sudo");
cmd.arg(command);
cmd
} else {
Command::new(command)
}
}
let update_output = command_with_sudo(command, with_sudo)
.arg("update") .arg("update")
.output() .output()
.await?; .await?;
if !update_output.status.success() { if !update_output.status.success() {
return log(&[update_output], log_dir).await; return log(&[update_output], log_dir).await;
} }
let upgrade_output = Command::new("sudo") let mut upgrade_command = command_with_sudo(command, with_sudo);
.arg("apt-get") upgrade_command.arg("upgrade");
.arg("upgrade") if yes {
.arg("-y") upgrade_command.arg("-y");
.output() }
.await?; let upgrade_output = upgrade_command.output().await?;
log(&[update_output, upgrade_output], log_dir).await log(&[update_output, upgrade_output], log_dir).await
} }
/// pupdates the local system using apt-get
async fn pupdate_apt(log_dir: Option<PathBuf>) -> eyre::Result<bool> {
update_and_upgrade(log_dir, "apt-get", true, true).await
}
/// pupdates the local system using brew, untested
async fn pupdate_homebrew(log_dir: Option<PathBuf>) -> eyre::Result<bool> {
update_and_upgrade(log_dir, "brew", false, false).await
}
#[tokio::main] #[tokio::main]
async fn main() -> eyre::Result<()> { async fn main() -> eyre::Result<()> {
let args = Args::parse(); let args = Args::parse();
@ -200,7 +224,18 @@ async fn main() -> eyre::Result<()> {
if !args.skip_local { if !args.skip_local {
println!("running local pupdates, you may be pawmpted for your password"); println!("running local pupdates, you may be pawmpted for your password");
let start = OffsetDateTime::now_utc(); let start = OffsetDateTime::now_utc();
if pupdate_apt(log_dir).await? { let result = if cfg!(target_os = "linux") {
println!("pupdating with apt-get...");
Some(pupdate_apt(log_dir).await)
} else if cfg!(target_os = "macos") {
println!("pupdating with brew...");
Some(pupdate_homebrew(log_dir).await)
} else {
eprintln!("unsupported operating system for local pupdates, skipping");
None
};
if let Some(result) = result {
result?;
let end = OffsetDateTime::now_utc(); let end = OffsetDateTime::now_utc();
let duration = end - start; let duration = end - start;

View file

@ -4,4 +4,4 @@ some things that may or may not get done at some point:
- pupdate daemon to remotely pupdate without using ssh (use ssh keys for authentication though maybe?) - pupdate daemon to remotely pupdate without using ssh (use ssh keys for authentication though maybe?)
- pupdate docker compose containers (interactively?) - pupdate docker compose containers (interactively?)
- support other pupdate methods than just apt - support other pupdate methods than just apt and homebrew