From e9e743ab4548191289643cf64e182734d45999a1 Mon Sep 17 00:00:00 2001 From: Roey Darwish Dror Date: Tue, 2 Oct 2018 13:25:02 +0300 Subject: [PATCH] Run etc-update (fix #72) --- README.md | 3 ++- src/linux.rs | 23 +++++++++++++++++++++++ src/main.rs | 4 ++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f34bee5d..9f1069a5 100644 --- a/README.md +++ b/README.md @@ -27,11 +27,12 @@ distribution which ships the latest version of Rust, such as Arch Linux. ## Usage Just run `topgrade`. It will run the following steps: -* Run the system package manager: +* *Linux*: Run the system package manager: * *Arch*: Run [yay](https://github.com/Jguer/yay) or fall back to pacman * *CentOS/RHEL*: Run `yum upgrade` * *Fedora* - Run `dnf upgrade` * *Debian/Ubuntu*: Run `apt update && apt dist-upgrade` +* *Linux*: Run [etc-update](https://dev.gentoo.org/~zmedico/portage/doc/man/etc-update.1.html): * *Unix*: Run `brew update && brew upgrade`. This should handle both Homebrew and Linuxbrew * *Windows*: Upgrade Powershell modules * *Windows*: Upgrade all [Chocolatey](https://chocolatey.org/) packages diff --git a/src/linux.rs b/src/linux.rs index 22018b91..371d349b 100644 --- a/src/linux.rs +++ b/src/linux.rs @@ -263,3 +263,26 @@ pub fn run_snap(sudo: &Option, terminal: &mut Terminal, dry_run: bool) None } + +#[must_use] +pub fn run_etc_update(sudo: &Option, terminal: &mut Terminal, dry_run: bool) -> Option<(&'static str, bool)> { + if let Some(sudo) = sudo { + if let Some(etc_update) = which("etc-update") { + terminal.print_separator("etc-update"); + + let success = || -> Result<(), failure::Error> { + Executor::new(&sudo, dry_run) + .arg(&etc_update.to_str().unwrap()) + .spawn()? + .wait()? + .check()?; + + Ok(()) + }().is_ok(); + + return Some(("snap", success)); + } + } + + None +} diff --git a/src/main.rs b/src/main.rs index a6c4862e..9cc63ade 100644 --- a/src/main.rs +++ b/src/main.rs @@ -126,6 +126,10 @@ fn run() -> Result<(), Error> { println!("Error detecting current distribution: {}", e); } } + report.push_result(execute( + |terminal| linux::run_etc_update(&sudo, terminal, opt.dry_run), + &mut terminal, + )); } }