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:
committed by
GitHub
parent
74292ef6d2
commit
2cd1ea6845
@@ -89,3 +89,7 @@
|
|||||||
[firmware]
|
[firmware]
|
||||||
# Offer to update firmware; if false just check for and display available updates
|
# Offer to update firmware; if false just check for and display available updates
|
||||||
#upgrade = true
|
#upgrade = true
|
||||||
|
|
||||||
|
[flatpak]
|
||||||
|
# Use sudo for updating the system-wide installation
|
||||||
|
#use_sudo = true
|
||||||
|
|||||||
@@ -161,6 +161,13 @@ pub struct Firmware {
|
|||||||
upgrade: Option<bool>,
|
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)]
|
#[derive(Deserialize, Default, Debug)]
|
||||||
#[serde(deny_unknown_fields)]
|
#[serde(deny_unknown_fields)]
|
||||||
pub struct Brew {
|
pub struct Brew {
|
||||||
@@ -221,6 +228,7 @@ pub struct ConfigFile {
|
|||||||
npm: Option<NPM>,
|
npm: Option<NPM>,
|
||||||
firmware: Option<Firmware>,
|
firmware: Option<Firmware>,
|
||||||
vagrant: Option<Vagrant>,
|
vagrant: Option<Vagrant>,
|
||||||
|
flatpak: Option<Flatpak>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn config_directory(base_dirs: &BaseDirs) -> PathBuf {
|
fn config_directory(base_dirs: &BaseDirs) -> PathBuf {
|
||||||
@@ -747,6 +755,15 @@ impl Config {
|
|||||||
.unwrap_or(false)
|
.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")]
|
#[cfg(target_os = "linux")]
|
||||||
str_value!(linux, emerge_sync_flags);
|
str_value!(linux, emerge_sync_flags);
|
||||||
|
|
||||||
|
|||||||
@@ -315,7 +315,7 @@ fn run() -> Result<()> {
|
|||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[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))?;
|
runner.execute(Step::Snap, "snap", || linux::run_snap(sudo.as_ref(), run_type))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -534,19 +534,31 @@ pub fn run_fwupdmgr(ctx: &ExecutionContext) -> Result<()> {
|
|||||||
updmgr.check_run_with_codes(&[2])
|
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 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");
|
print_separator("Flatpak User Packages");
|
||||||
|
|
||||||
run_type
|
run_type
|
||||||
.execute(&flatpak)
|
.execute(&flatpak)
|
||||||
.args(&["update", "--user", "-y"])
|
.args(&["update", "--user", "-y"])
|
||||||
.check_run()?;
|
.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
|
run_type
|
||||||
.execute(&flatpak)
|
.execute(&flatpak)
|
||||||
.args(&["update", "--system", "-y"])
|
.args(&["update", "--system", "-y"])
|
||||||
.check_run()
|
.check_run()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn run_snap(sudo: Option<&PathBuf>, run_type: RunType) -> Result<()> {
|
pub fn run_snap(sudo: Option<&PathBuf>, run_type: RunType) -> Result<()> {
|
||||||
let sudo = require_option(sudo, String::from("sudo is not installed"))?;
|
let sudo = require_option(sudo, String::from("sudo is not installed"))?;
|
||||||
|
|||||||
Reference in New Issue
Block a user