Make firmware upgrade configurable (#739)

This change adds an option, firmware.upgrade, that if set to `false`
only checks for and displays available firmware updates. If set to `true`
(default) the user is offered to run the firmware upgrade.
This commit is contained in:
Eberhard Beilharz
2021-06-30 11:15:18 +02:00
committed by GitHub
parent 5ec1f4d2d6
commit 74292ef6d2
3 changed files with 30 additions and 5 deletions

View File

@@ -85,3 +85,7 @@
[npm]
# Use sudo if the NPM directory isn't owned by the current user
#use_sudo = true
[firmware]
# Offer to update firmware; if false just check for and display available updates
#upgrade = true

View File

@@ -154,6 +154,13 @@ pub struct NPM {
use_sudo: Option<bool>,
}
#[derive(Deserialize, Default, Debug)]
#[serde(deny_unknown_fields)]
#[allow(clippy::upper_case_acronyms)]
pub struct Firmware {
upgrade: Option<bool>,
}
#[derive(Deserialize, Default, Debug)]
#[serde(deny_unknown_fields)]
pub struct Brew {
@@ -212,6 +219,7 @@ pub struct ConfigFile {
git: Option<Git>,
windows: Option<Windows>,
npm: Option<NPM>,
firmware: Option<Firmware>,
vagrant: Option<Vagrant>,
}
@@ -730,6 +738,15 @@ impl Config {
.unwrap_or(false)
}
#[cfg(target_os = "linux")]
pub fn firmware_upgrade(&self) -> bool {
self.config_file
.firmware
.as_ref()
.and_then(|firmware| firmware.upgrade)
.unwrap_or(false)
}
#[cfg(target_os = "linux")]
str_value!(linux, emerge_sync_flags);

View File

@@ -521,13 +521,17 @@ pub fn run_fwupdmgr(ctx: &ExecutionContext) -> Result<()> {
.arg("refresh")
.check_run_with_codes(&[2])?;
let mut upgrade = ctx.run_type().execute(&fwupdmgr);
let mut updmgr = ctx.run_type().execute(&fwupdmgr);
upgrade.arg("update");
if ctx.config().yes() {
upgrade.arg("-y");
if ctx.config().firmware_upgrade() {
updmgr.arg("update");
if ctx.config().yes() {
updmgr.arg("-y");
}
} else {
updmgr.arg("get-updates");
}
upgrade.check_run_with_codes(&[2])
updmgr.check_run_with_codes(&[2])
}
pub fn flatpak_update(run_type: RunType) -> Result<()> {