diff --git a/config.example.toml b/config.example.toml index 3c39dba8..e56ada36 100644 --- a/config.example.toml +++ b/config.example.toml @@ -58,6 +58,8 @@ #yay_arguments = "--nodevel" #trizen_arguments = "--devel" #enable_tlmgr = true +emerge_sync_flags = "-q" +emerge_update_flags = "-uDNa --with-bdeps=y world" #[windows] # Manually select Windows updates diff --git a/src/config.rs b/src/config.rs index 44752776..bb8d28ff 100644 --- a/src/config.rs +++ b/src/config.rs @@ -12,6 +12,18 @@ use std::{env, fs}; use structopt::StructOpt; use strum::{EnumIter, EnumString, EnumVariantNames, IntoEnumIterator, VariantNames}; +#[allow(unused_macros)] +macro_rules! str_value { + ($section:ident, $value:ident) => { + pub fn $value(&self) -> Option<&str> { + self.config_file + .$section + .as_ref() + .and_then(|section| section.$value.as_deref()) + } + }; +} + macro_rules! check_deprecated { ($config:expr, $old:ident, $section:ident, $new:ident) => { if $config.$old.is_some() { @@ -110,6 +122,8 @@ pub struct Linux { trizen_arguments: Option, dnf_arguments: Option, enable_tlmgr: Option, + emerge_sync_flags: Option, + emerge_update_flags: Option, } #[derive(Deserialize, Default, Debug)] @@ -553,4 +567,10 @@ impl Config { !self.opt.disable_predefined_git_repos && get_deprecated!(&self.config_file, predefined_git_repos, git, pull_predefined).unwrap_or(true) } + + #[cfg(target_os = "linux")] + str_value!(linux, emerge_sync_flags); + + #[cfg(target_os = "linux")] + str_value!(linux, emerge_update_flags); } diff --git a/src/steps/os/linux.rs b/src/steps/os/linux.rs index f6c726dd..66ebdb6e 100644 --- a/src/steps/os/linux.rs +++ b/src/steps/os/linux.rs @@ -95,7 +95,7 @@ impl Distribution { Distribution::CentOS | Distribution::Fedora => upgrade_redhat(ctx), Distribution::ClearLinux => upgrade_clearlinux(&sudo, run_type), Distribution::Debian => upgrade_debian(&sudo, cleanup, run_type, yes), - Distribution::Gentoo => upgrade_gentoo(&sudo, run_type), + Distribution::Gentoo => upgrade_gentoo(ctx), Distribution::Suse => upgrade_suse(&sudo, run_type), Distribution::Void => upgrade_void(&sudo, run_type), Distribution::Solus => upgrade_solus(&sudo, run_type), @@ -289,8 +289,10 @@ fn upgrade_void(sudo: &Option, run_type: RunType) -> Result<()> { Ok(()) } -fn upgrade_gentoo(sudo: &Option, run_type: RunType) -> Result<()> { - if let Some(sudo) = &sudo { +fn upgrade_gentoo(ctx: &ExecutionContext) -> Result<()> { + let run_type = ctx.run_type(); + + if let Some(sudo) = &ctx.sudo() { if let Some(layman) = which("layman") { run_type.execute(&sudo).arg(layman).args(&["-s", "ALL"]).check_run()?; } @@ -298,8 +300,13 @@ fn upgrade_gentoo(sudo: &Option, run_type: RunType) -> Result<()> { println!("Syncing portage"); run_type .execute(&sudo) - .arg("/usr/bin/emerge") - .args(&["-q", "--sync"]) + .args(&["/usr/bin/emerge", "--sync"]) + .args( + ctx.config() + .emerge_sync_flags() + .map(|s| s.split_whitespace().collect()) + .unwrap_or_else(|| vec!["-q"]), + ) .check_run()?; if let Some(eix_update) = which("eix-update") { @@ -309,7 +316,12 @@ fn upgrade_gentoo(sudo: &Option, run_type: RunType) -> Result<()> { run_type .execute(&sudo) .arg("/usr/bin/emerge") - .args(&["-uDNa", "--with-bdeps=y", "world"]) + .args( + ctx.config() + .emerge_update_flags() + .map(|s| s.split_whitespace().collect()) + .unwrap_or_else(|| vec!["-uDNa", "--with-bdeps=y", "world"]), + ) .check_run()?; } else { print_warning("No sudo detected. Skipping system upgrade");