Improve OpenBSD -CURRENT detection and Dry-run feedback (#954)

* 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.

* Make OpenBSD step less talky and improve verbiage.

This commit removes the command flag feedback. This commit also swaps the output "update", for "upgrade", making this step closer to other steps for consistency.
This commit is contained in:
λP.(P izzy)
2024-10-17 19:26:27 -05:00
committed by GitHub
parent 9ffdc9649e
commit 2c2569c4f8

View File

@@ -4,16 +4,16 @@ 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<bool> {
let motd_content = fs::read_to_string("/etc/motd")?;
let is_current = motd_content.contains("-current");
if ctx.config().dry_run() {
println!("Would check if OpenBSD is -current");
Ok(false) // Default to false for dry-run
Ok(is_current)
} else {
let output = ctx.run_type().execute("uname").arg("-r").output_checked()?;
let version = String::from_utf8_lossy(&output.stdout);
Ok(version.trim().ends_with("-current"))
Ok(is_current)
}
}
@@ -21,13 +21,15 @@ 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");
println!("Would upgrade the OpenBSD system");
return Ok(());
}
let mut args = vec!["/usr/sbin/sysupgrade", "-n"];
if is_openbsd_current(ctx)? {
if is_current {
args.push("-s");
}
@@ -38,8 +40,10 @@ 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");
println!("Would upgrade OpenBSD packages");
return Ok(());
}
@@ -51,7 +55,7 @@ pub fn upgrade_packages(ctx: &ExecutionContext) -> Result<()> {
}
let mut args = vec!["/usr/sbin/pkg_add", "-u"];
if is_openbsd_current(ctx)? {
if is_current {
args.push("-Dsnap");
}