Add configuration flags for portage arguments (#436)

This commit is contained in:
Roey Darwish Dror
2020-06-19 10:34:45 +03:00
committed by GitHub
parent 63ae33c841
commit 4a4e779621
3 changed files with 40 additions and 6 deletions

View File

@@ -58,6 +58,8 @@
#yay_arguments = "--nodevel" #yay_arguments = "--nodevel"
#trizen_arguments = "--devel" #trizen_arguments = "--devel"
#enable_tlmgr = true #enable_tlmgr = true
emerge_sync_flags = "-q"
emerge_update_flags = "-uDNa --with-bdeps=y world"
#[windows] #[windows]
# Manually select Windows updates # Manually select Windows updates

View File

@@ -12,6 +12,18 @@ use std::{env, fs};
use structopt::StructOpt; use structopt::StructOpt;
use strum::{EnumIter, EnumString, EnumVariantNames, IntoEnumIterator, VariantNames}; 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 { macro_rules! check_deprecated {
($config:expr, $old:ident, $section:ident, $new:ident) => { ($config:expr, $old:ident, $section:ident, $new:ident) => {
if $config.$old.is_some() { if $config.$old.is_some() {
@@ -110,6 +122,8 @@ pub struct Linux {
trizen_arguments: Option<String>, trizen_arguments: Option<String>,
dnf_arguments: Option<String>, dnf_arguments: Option<String>,
enable_tlmgr: Option<bool>, enable_tlmgr: Option<bool>,
emerge_sync_flags: Option<String>,
emerge_update_flags: Option<String>,
} }
#[derive(Deserialize, Default, Debug)] #[derive(Deserialize, Default, Debug)]
@@ -553,4 +567,10 @@ impl Config {
!self.opt.disable_predefined_git_repos !self.opt.disable_predefined_git_repos
&& get_deprecated!(&self.config_file, predefined_git_repos, git, pull_predefined).unwrap_or(true) && 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);
} }

View File

@@ -95,7 +95,7 @@ impl Distribution {
Distribution::CentOS | Distribution::Fedora => upgrade_redhat(ctx), Distribution::CentOS | Distribution::Fedora => upgrade_redhat(ctx),
Distribution::ClearLinux => upgrade_clearlinux(&sudo, run_type), Distribution::ClearLinux => upgrade_clearlinux(&sudo, run_type),
Distribution::Debian => upgrade_debian(&sudo, cleanup, run_type, yes), 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::Suse => upgrade_suse(&sudo, run_type),
Distribution::Void => upgrade_void(&sudo, run_type), Distribution::Void => upgrade_void(&sudo, run_type),
Distribution::Solus => upgrade_solus(&sudo, run_type), Distribution::Solus => upgrade_solus(&sudo, run_type),
@@ -289,8 +289,10 @@ fn upgrade_void(sudo: &Option<PathBuf>, run_type: RunType) -> Result<()> {
Ok(()) Ok(())
} }
fn upgrade_gentoo(sudo: &Option<PathBuf>, run_type: RunType) -> Result<()> { fn upgrade_gentoo(ctx: &ExecutionContext) -> Result<()> {
if let Some(sudo) = &sudo { let run_type = ctx.run_type();
if let Some(sudo) = &ctx.sudo() {
if let Some(layman) = which("layman") { if let Some(layman) = which("layman") {
run_type.execute(&sudo).arg(layman).args(&["-s", "ALL"]).check_run()?; run_type.execute(&sudo).arg(layman).args(&["-s", "ALL"]).check_run()?;
} }
@@ -298,8 +300,13 @@ fn upgrade_gentoo(sudo: &Option<PathBuf>, run_type: RunType) -> Result<()> {
println!("Syncing portage"); println!("Syncing portage");
run_type run_type
.execute(&sudo) .execute(&sudo)
.arg("/usr/bin/emerge") .args(&["/usr/bin/emerge", "--sync"])
.args(&["-q", "--sync"]) .args(
ctx.config()
.emerge_sync_flags()
.map(|s| s.split_whitespace().collect())
.unwrap_or_else(|| vec!["-q"]),
)
.check_run()?; .check_run()?;
if let Some(eix_update) = which("eix-update") { if let Some(eix_update) = which("eix-update") {
@@ -309,7 +316,12 @@ fn upgrade_gentoo(sudo: &Option<PathBuf>, run_type: RunType) -> Result<()> {
run_type run_type
.execute(&sudo) .execute(&sudo)
.arg("/usr/bin/emerge") .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()?; .check_run()?;
} else { } else {
print_warning("No sudo detected. Skipping system upgrade"); print_warning("No sudo detected. Skipping system upgrade");