From 44edea634acd1dbf3b1db94836fb8a2d515a4f91 Mon Sep 17 00:00:00 2001 From: izder456 Date: Tue, 15 Oct 2024 20:02:37 -0500 Subject: [PATCH] Improve OpenBSD -CURRENT detection and Dry-run feedback This commit improves the -CURRENT detection by way of parsing /etc/motd This change is more future-proof as when OpenBSD nears a stable release, `uname` will temporarily report like -STABLE. This commit *also* adds feedback if -CURRENT is found to make debugging this feature easier with --dry-run, or, just a regular run as well. --- src/steps/os/openbsd.rs | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/steps/os/openbsd.rs b/src/steps/os/openbsd.rs index e51244d0..4e28895b 100644 --- a/src/steps/os/openbsd.rs +++ b/src/steps/os/openbsd.rs @@ -4,16 +4,23 @@ use crate::terminal::print_separator; use crate::utils::{get_require_sudo_string, require_option}; use color_eyre::eyre::Result; use rust_i18n::t; +use std::fs; 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 motd_content = fs::read_to_string("/etc/motd")?; + let is_current = motd_content.contains("-current"); - let version = String::from_utf8_lossy(&output.stdout); - Ok(version.trim().ends_with("-current")) + if is_current { + println!("OpenBSD system is running -current"); + } else { + println!("OpenBSD system is not running -current"); + } + + Ok(is_current) } } @@ -21,13 +28,18 @@ pub fn upgrade_openbsd(ctx: &ExecutionContext) -> Result<()> { let sudo = require_option(ctx.sudo().as_ref(), get_require_sudo_string())?; print_separator(t!("OpenBSD Update")); + let is_current = is_openbsd_current(ctx)?; + if ctx.config().dry_run() { println!("Would update the OpenBSD system"); + if is_current { + println!("Would use -s flag when upgrading system"); + } return Ok(()); } let mut args = vec!["/usr/sbin/sysupgrade", "-n"]; - if is_openbsd_current(ctx)? { + if is_current { args.push("-s"); } @@ -38,8 +50,13 @@ pub fn upgrade_packages(ctx: &ExecutionContext) -> Result<()> { let sudo = require_option(ctx.sudo().as_ref(), get_require_sudo_string())?; print_separator(t!("OpenBSD Packages")); + let is_current = is_openbsd_current(ctx)?; + if ctx.config().dry_run() { println!("Would update OpenBSD packages"); + if is_current { + println!("Would use -Dsnap flag when upgrading packages"); + } return Ok(()); }