Allow to run flatpak update with sudo (#738)

This change adds the option `flatpak.use_sudo` that allows to update
the system-wide installation with sudo. When set to `true` the
system-wide installation will be updated with sudo. If set to `false`
(default) the update will be run as regular user.

This solves the problem where running `flatpak update` on a remote
system fails if run as regular user.

Fixes #737.
This commit is contained in:
Eberhard Beilharz
2021-06-30 12:37:41 +02:00
committed by GitHub
parent 74292ef6d2
commit 2cd1ea6845
4 changed files with 39 additions and 6 deletions

View File

@@ -89,3 +89,7 @@
[firmware]
# Offer to update firmware; if false just check for and display available updates
#upgrade = true
[flatpak]
# Use sudo for updating the system-wide installation
#use_sudo = true

View File

@@ -161,6 +161,13 @@ pub struct Firmware {
upgrade: Option<bool>,
}
#[derive(Deserialize, Default, Debug)]
#[serde(deny_unknown_fields)]
#[allow(clippy::upper_case_acronyms)]
pub struct Flatpak {
use_sudo: Option<bool>,
}
#[derive(Deserialize, Default, Debug)]
#[serde(deny_unknown_fields)]
pub struct Brew {
@@ -221,6 +228,7 @@ pub struct ConfigFile {
npm: Option<NPM>,
firmware: Option<Firmware>,
vagrant: Option<Vagrant>,
flatpak: Option<Flatpak>,
}
fn config_directory(base_dirs: &BaseDirs) -> PathBuf {
@@ -747,6 +755,15 @@ impl Config {
.unwrap_or(false)
}
#[cfg(target_os = "linux")]
pub fn flatpak_use_sudo(&self) -> bool {
self.config_file
.flatpak
.as_ref()
.and_then(|flatpak| flatpak.use_sudo)
.unwrap_or(false)
}
#[cfg(target_os = "linux")]
str_value!(linux, emerge_sync_flags);

View File

@@ -315,7 +315,7 @@ fn run() -> Result<()> {
#[cfg(target_os = "linux")]
{
runner.execute(Step::Flatpak, "Flatpak", || linux::flatpak_update(run_type))?;
runner.execute(Step::Flatpak, "Flatpak", || linux::flatpak_update(&ctx))?;
runner.execute(Step::Snap, "snap", || linux::run_snap(sudo.as_ref(), run_type))?;
}

View File

@@ -534,18 +534,30 @@ pub fn run_fwupdmgr(ctx: &ExecutionContext) -> Result<()> {
updmgr.check_run_with_codes(&[2])
}
pub fn flatpak_update(run_type: RunType) -> Result<()> {
pub fn flatpak_update(ctx: &ExecutionContext) -> Result<()> {
let flatpak = require("flatpak")?;
let sudo = require_option(ctx.sudo().as_ref(), String::from("sudo is not installed"))?;
let run_type = ctx.run_type();
print_separator("Flatpak User Packages");
run_type
.execute(&flatpak)
.args(&["update", "--user", "-y"])
.check_run()?;
run_type
.execute(&flatpak)
.args(&["update", "--system", "-y"])
.check_run()
print_separator("Flatpak System Packages");
if ctx.config().flatpak_use_sudo() {
run_type
.execute(sudo)
.arg(flatpak)
.args(&["update", "--system", "-y"])
.check_run()
} else {
run_type
.execute(&flatpak)
.args(&["update", "--system", "-y"])
.check_run()
}
}
pub fn run_snap(sudo: Option<&PathBuf>, run_type: RunType) -> Result<()> {