From 2bed7edaba0124ac8b857bd28adaffc661c0f129 Mon Sep 17 00:00:00 2001 From: Kevin K Date: Thu, 13 May 2021 14:57:29 -0400 Subject: [PATCH] makes rpm-ostree configurable (#712) This commit makes it possible to *not* to use `rpm-ostree` even on systems where it is detected. This commit is fully backwards compatible with previous releases, and without changing the config file all previous behaviors are the exact same. This commit adds the `rpm_ostree` field in the `[linux]` table of the configuration, and defaults to `true`. This means Topgrade will first check if `/usr/bin/rpm-ostree` exists, and only if so then check if the user does not want to use `rpm-ostree` via the configuration. If the user *does not* want to use `rpm-ostree`, then normal operation continues checking for DNF or YUM. This makes it possible for people where `rpm-ostree` is installed, but where the system is not an `ostree` based distribtuion. This happens when people are using things like `osbuild-composer` to build images, or Cockpit with the Compose feature enabled (which uses `osbuild-composer` internally). An alternative to this commit would be to make the config field a negative such as `no_rpm_ostree`, however that goes against the norm in other fields. Closes #710 --- config.example.toml | 1 + src/config.rs | 11 +++++++++++ src/steps/os/linux.rs | 18 ++++++++++-------- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/config.example.toml b/config.example.toml index 8cb618ef..bcaa9c7e 100644 --- a/config.example.toml +++ b/config.example.toml @@ -70,6 +70,7 @@ #emerge_sync_flags = "-q" #emerge_update_flags = "-uDNa --with-bdeps=y world" #redhat_distro_sync = false +#rpm_ostree = false [windows] # Manually select Windows updates diff --git a/src/config.rs b/src/config.rs index 0a0afd20..c4415aef 100644 --- a/src/config.rs +++ b/src/config.rs @@ -159,6 +159,7 @@ pub struct Linux { apt_arguments: Option, enable_tlmgr: Option, redhat_distro_sync: Option, + rpm_ostree: Option, emerge_sync_flags: Option, emerge_update_flags: Option, } @@ -669,6 +670,16 @@ impl Config { .unwrap_or(false) } + /// Use rpm-ostree in *when rpm-ostree is detected* (default: true) + #[allow(dead_code)] + pub fn rpm_ostree(&self) -> bool { + self.config_file + .linux + .as_ref() + .and_then(|linux| linux.rpm_ostree) + .unwrap_or(true) + } + /// Should we ignore failures for this step pub fn ignore_failure(&self, step: Step) -> bool { self.config_file diff --git a/src/steps/os/linux.rs b/src/steps/os/linux.rs index 38d75233..7c23bef2 100644 --- a/src/steps/os/linux.rs +++ b/src/steps/os/linux.rs @@ -237,15 +237,17 @@ fn upgrade_arch_linux(ctx: &ExecutionContext) -> Result<()> { } fn upgrade_redhat(ctx: &ExecutionContext) -> Result<()> { - if let Some(ostree) = Path::new("/usr/bin/rpm-ostree").if_exists() { - let mut command = ctx.run_type().execute(ostree); - command.arg("upgrade"); - if ctx.config().yes() { - command.arg("-y"); - } + let _ = if let Some(ostree) = Path::new("/usr/bin/rpm-ostree").if_exists() { + if ctx.config().rpm_ostree() { + let mut command = ctx.run_type().execute(ostree); + command.arg("upgrade"); + if ctx.config().yes() { + command.arg("-y"); + } - return command.check_run(); - } + return command.check_run(); + } + }; if let Some(sudo) = &ctx.sudo() { let mut command = ctx.run_type().execute(&sudo);