From 3e08fda765b84c70e8652f5c496521d9a844cd32 Mon Sep 17 00:00:00 2001 From: Roey Darwish Dror Date: Fri, 15 May 2020 21:10:01 +0300 Subject: [PATCH] Add Trizen support (fix #271) (#409) --- config.example.toml | 1 + src/config.rs | 12 ++++++++++++ src/steps/os/linux.rs | 37 ++++++++++++++++++++++++++++--------- 3 files changed, 41 insertions(+), 9 deletions(-) diff --git a/config.example.toml b/config.example.toml index da85953c..a4225412 100644 --- a/config.example.toml +++ b/config.example.toml @@ -57,3 +57,4 @@ #[linux] # Arguments to pass yay when updating packages #yay_arguments = "--nodevel" +#trizen_arguments = "--devel" diff --git a/src/config.rs b/src/config.rs index 96e1b9b1..316a825b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -58,6 +58,7 @@ pub struct Brew { #[derive(Deserialize, Default, Debug)] pub struct Linux { yay_arguments: Option, + trizen_arguments: Option, dnf_arguments: Option, } @@ -407,6 +408,17 @@ impl Config { self.config_file.notify_each_step.unwrap_or(false) } + /// Extra trizen arguments + #[allow(dead_code)] + pub fn trizen_arguments(&self) -> &str { + &self + .config_file + .linux + .as_ref() + .and_then(|s| s.trizen_arguments.as_deref()) + .unwrap_or("") + } + /// Extra yay arguments #[allow(dead_code)] pub fn yay_arguments(&self) -> &str { diff --git a/src/steps/os/linux.rs b/src/steps/os/linux.rs index 69fb3c2f..f1acebad 100644 --- a/src/steps/os/linux.rs +++ b/src/steps/os/linux.rs @@ -87,7 +87,7 @@ impl Distribution { let cleanup = ctx.config().cleanup(); match self { - Distribution::Arch => upgrade_arch_linux(&sudo, cleanup, run_type, yes, &ctx.config().yay_arguments()), + Distribution::Arch => upgrade_arch_linux(ctx), Distribution::CentOS | Distribution::Fedora => upgrade_redhat(ctx), Distribution::ClearLinux => upgrade_clearlinux(&sudo, run_type), Distribution::Debian => upgrade_debian(&sudo, cleanup, run_type, yes), @@ -128,14 +128,12 @@ pub fn show_pacnew() { } } -fn upgrade_arch_linux( - sudo: &Option, - cleanup: bool, - run_type: RunType, - yes: bool, - yay_arguments: &str, -) -> Result<()> { +fn upgrade_arch_linux(ctx: &ExecutionContext) -> Result<()> { let pacman = which("powerpill").unwrap_or_else(|| PathBuf::from("/usr/bin/pacman")); + let yes = ctx.config().yes(); + let sudo = ctx.sudo(); + let run_type = ctx.run_type(); + let cleanup = ctx.config().cleanup(); let path = { let mut path = OsString::from("/usr/bin:"); @@ -158,7 +156,7 @@ fn upgrade_arch_linux( .arg("--pacman") .arg(&pacman) .arg("-Syu") - .args(yay_arguments.split_whitespace()) + .args(ctx.config().yay_arguments().split_whitespace()) .env("PATH", path); if yes { @@ -174,6 +172,27 @@ fn upgrade_arch_linux( } command.check_run()?; } + } else if let Some(trizen) = which("trizen") { + let mut command = run_type.execute(&trizen); + + command + .arg("-Syu") + .args(ctx.config().trizen_arguments().split_whitespace()) + .env("PATH", path); + + if yes { + command.arg("--noconfirm"); + } + command.check_run()?; + + if cleanup { + let mut command = run_type.execute(&trizen); + command.arg("-Sc"); + if yes { + command.arg("--noconfirm"); + } + command.check_run()?; + } } else if let Some(sudo) = &sudo { let mut command = run_type.execute(&sudo); command.arg(&pacman).arg("-Syu").env("PATH", path);