Skip to content

Commit

Permalink
un-break ctx.config().dry_run() on OpenBSD Step
Browse files Browse the repository at this point in the history
  • Loading branch information
Izder456 committed Oct 13, 2024
1 parent c8860f9 commit ef3d14c
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions src/steps/os/openbsd.rs
Original file line number Diff line number Diff line change
@@ -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<bool> {
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");
}

Expand All @@ -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)
Expand All @@ -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");
}

Expand Down

0 comments on commit ef3d14c

Please sign in to comment.