diff --git a/config.example.toml b/config.example.toml index f614c6b9..53267e21 100644 --- a/config.example.toml +++ b/config.example.toml @@ -107,3 +107,7 @@ [flatpak] # Use sudo for updating the system-wide installation #use_sudo = true + +[distrobox] +#use_root = false +#containers = ["archlinux-latest"] diff --git a/src/config.rs b/src/config.rs index 0ce65930..b9743d24 100644 --- a/src/config.rs +++ b/src/config.rs @@ -172,6 +172,14 @@ pub struct Windows { enable_winget: Option, } +#[derive(Deserialize, Default, Debug)] +#[serde(deny_unknown_fields)] +#[allow(clippy::upper_case_acronyms)] +pub struct Distrobox { + use_root: Option, + containers: Option>, +} + #[derive(Deserialize, Default, Debug)] #[serde(deny_unknown_fields)] #[allow(clippy::upper_case_acronyms)] @@ -293,6 +301,7 @@ pub struct ConfigFile { firmware: Option, vagrant: Option, flatpak: Option, + distrobox: Option, } fn config_directory(base_dirs: &BaseDirs) -> PathBuf { @@ -615,7 +624,6 @@ impl Config { } /// Extra Tmux arguments - pub fn tmux_arguments(&self) -> &Option { &self.config_file.tmux_arguments } @@ -809,6 +817,20 @@ impl Config { .and_then(|linux| linux.dnf_arguments.as_deref()) } + /// Distrobox use root + pub fn distrobox_root(&self) -> bool { + self.config_file + .distrobox + .as_ref() + .and_then(|r| r.use_root) + .unwrap_or(false) + } + + /// Distrobox containers + pub fn distrobox_containers(&self) -> Option<&Vec> { + self.config_file.distrobox.as_ref().and_then(|r| r.containers.as_ref()) + } + /// Concurrency limit for git pub fn git_concurrency_limit(&self) -> Option { self.config_file.git.as_ref().and_then(|git| git.max_concurrency) diff --git a/src/steps/os/linux.rs b/src/steps/os/linux.rs index 697b050d..e9d31694 100644 --- a/src/steps/os/linux.rs +++ b/src/steps/os/linux.rs @@ -607,14 +607,26 @@ pub fn run_protonup_update(ctx: &ExecutionContext) -> Result<()> { } pub fn run_distrobox_update(ctx: &ExecutionContext) -> Result<()> { - let distrobox = require("distrobox")?; - - print_separator("distrobox"); - - ctx.run_type() - .execute(distrobox) - .args(&["upgrade", "--all"]) - .check_run() + print_separator("Distrobox"); + match ( + match ( + ctx.run_type().execute("distrobox").arg("upgrade"), + ctx.config().distrobox_containers(), + ) { + (r, Some(c)) => { + if c.is_empty() { + return Err(SkipStep("You need to specify at least one container".to_string()).into()); + } + r.args(c) + } + (r, None) => r.arg("--all"), + }, + ctx.config().distrobox_root(), + ) { + (r, true) => r.arg("--root"), + (r, false) => r, + } + .check_run() } pub fn run_config_update(ctx: &ExecutionContext) -> Result<()> {