From f95672aff54d683640ed0670d5c5e20b4bba40c7 Mon Sep 17 00:00:00 2001 From: izder456 Date: Fri, 4 Oct 2024 12:48:54 -0500 Subject: [PATCH 1/2] [FIXES #922] properly check for -CURRENT in openbsd steps and pass the correct flags --- src/steps/os/openbsd.rs | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/src/steps/os/openbsd.rs b/src/steps/os/openbsd.rs index 4630aba6..8bd22d50 100644 --- a/src/steps/os/openbsd.rs +++ b/src/steps/os/openbsd.rs @@ -1,16 +1,31 @@ use crate::command::CommandExt; use crate::execution_context::ExecutionContext; +use crate::t; use crate::terminal::print_separator; use crate::utils::{get_require_sudo_string, require_option}; use color_eyre::eyre::Result; +use std::process::Command; + +fn is_openbsd_current() -> bool { + let output = Command::new("uname") + .arg("-r") + .output() + .expect("Failed to execute uname command"); + + let version = String::from_utf8_lossy(&output.stdout); + version.trim().ends_with("-current") +} pub fn upgrade_openbsd(ctx: &ExecutionContext) -> Result<()> { let sudo = require_option(ctx.sudo().as_ref(), get_require_sudo_string())?; print_separator(t!("OpenBSD Update")); - ctx.run_type() - .execute(sudo) - .args(["/usr/sbin/sysupgrade", "-n"]) - .status_checked() + + let mut args = vec!["/usr/sbin/sysupgrade", "-n"]; + if is_openbsd_current() { + args.push("-s"); + } + + ctx.run_type().execute(sudo).args(&args).status_checked() } pub fn upgrade_packages(ctx: &ExecutionContext) -> Result<()> { @@ -24,10 +39,12 @@ pub fn upgrade_packages(ctx: &ExecutionContext) -> Result<()> { .status_checked()?; } - ctx.run_type() - .execute(sudo) - .args(["/usr/sbin/pkg_add", "-u"]) - .status_checked()?; + let mut args = vec!["/usr/sbin/pkg_add", "-u"]; + if is_openbsd_current() { + args.push("-Dsnap"); + } + + ctx.run_type().execute(sudo).args(&args).status_checked()?; Ok(()) } From ef3d14c73e75754a83b6f12e3d16ed234a914c64 Mon Sep 17 00:00:00 2001 From: izder456 Date: Sun, 13 Oct 2024 15:37:32 -0500 Subject: [PATCH 2/2] un-break ctx.config().dry_run() on OpenBSD Step --- src/steps/os/openbsd.rs | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/src/steps/os/openbsd.rs b/src/steps/os/openbsd.rs index 8bd22d50..e51244d0 100644 --- a/src/steps/os/openbsd.rs +++ b/src/steps/os/openbsd.rs @@ -1,27 +1,33 @@ use crate::command::CommandExt; use crate::execution_context::ExecutionContext; -use crate::t; use crate::terminal::print_separator; use crate::utils::{get_require_sudo_string, require_option}; use color_eyre::eyre::Result; -use std::process::Command; +use rust_i18n::t; -fn is_openbsd_current() -> bool { - let output = Command::new("uname") - .arg("-r") - .output() - .expect("Failed to execute uname command"); +fn is_openbsd_current(ctx: &ExecutionContext) -> Result { + if ctx.config().dry_run() { + println!("Would check if OpenBSD is -current"); + Ok(false) // Default to false for dry-run + } else { + let output = ctx.run_type().execute("uname").arg("-r").output_checked()?; - let version = String::from_utf8_lossy(&output.stdout); - version.trim().ends_with("-current") + let version = String::from_utf8_lossy(&output.stdout); + Ok(version.trim().ends_with("-current")) + } } pub fn upgrade_openbsd(ctx: &ExecutionContext) -> Result<()> { let sudo = require_option(ctx.sudo().as_ref(), get_require_sudo_string())?; print_separator(t!("OpenBSD Update")); + if ctx.config().dry_run() { + println!("Would update the OpenBSD system"); + return Ok(()); + } + let mut args = vec!["/usr/sbin/sysupgrade", "-n"]; - if is_openbsd_current() { + if is_openbsd_current(ctx)? { args.push("-s"); } @@ -32,6 +38,11 @@ pub fn upgrade_packages(ctx: &ExecutionContext) -> Result<()> { let sudo = require_option(ctx.sudo().as_ref(), get_require_sudo_string())?; print_separator(t!("OpenBSD Packages")); + if ctx.config().dry_run() { + println!("Would update OpenBSD packages"); + return Ok(()); + } + if ctx.config().cleanup() { ctx.run_type() .execute(sudo) @@ -40,7 +51,7 @@ pub fn upgrade_packages(ctx: &ExecutionContext) -> Result<()> { } let mut args = vec!["/usr/sbin/pkg_add", "-u"]; - if is_openbsd_current() { + if is_openbsd_current(ctx)? { args.push("-Dsnap"); }