diff --git a/README.md b/README.md index cdb49002..8defe9ca 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ Just run `topgrade`. It will run the following steps: * *CentOS/RHEL*: Run `yum upgrade` * *Fedora* - Run `dnf upgrade` * *Debian/Ubuntu*: Run `apt update && apt dist-upgrade` + * *Gentoo*: Run `layman -s ALL && emerge --sync -q && eix-update && emerge -uDNa world` * *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 * *Unix*: Run `nix upgrade-nix && nix --upgrade`. diff --git a/src/linux.rs b/src/linux.rs index 5fb267f3..faad97fa 100644 --- a/src/linux.rs +++ b/src/linux.rs @@ -13,6 +13,7 @@ pub enum Distribution { Fedora, Debian, Ubuntu, + Gentoo, } #[derive(Debug, Fail)] @@ -47,6 +48,10 @@ impl Distribution { return Ok(Distribution::Debian); } + if PathBuf::from("/etc/gentoo-release").exists() { + return Ok(Distribution::Gentoo); + } + Err(UnknownLinuxDistribution.into()) } @@ -64,6 +69,7 @@ impl Distribution { Distribution::CentOS => upgrade_redhat(&sudo, terminal, dry_run), Distribution::Fedora => upgrade_fedora(&sudo, terminal, dry_run), Distribution::Ubuntu | Distribution::Debian => upgrade_debian(&sudo, terminal, dry_run), + Distribution::Gentoo => upgrade_gentoo(&sudo, terminal, dry_run), }; Some(("System update", success.is_ok())) @@ -151,6 +157,42 @@ fn upgrade_fedora(sudo: &Option, terminal: &mut Terminal, dry_run: bool Ok(()) } +fn upgrade_gentoo(sudo: &Option, terminal: &mut Terminal, dry_run: bool) -> Result<(), failure::Error> { + if let Some(sudo) = &sudo { + if let Some(layman) = which("layman") { + Executor::new(&sudo, dry_run) + .arg(layman) + .args(&["-s", "ALL"]) + .spawn()? + .wait()? + .check()?; + } + + println!("Syncing portage"); + Executor::new(&sudo, dry_run) + .arg("/usr/bin/emerge") + .args(&["-q", "--sync"]) + .spawn()? + .wait()? + .check()?; + + if let Some(eix_update) = which("eix-update") { + Executor::new(&sudo, dry_run).arg(eix_update).spawn()?.wait()?.check()?; + } + + Executor::new(&sudo, dry_run) + .arg("/usr/bin/emerge") + .args(&["-uDNa", "world"]) + .spawn()? + .wait()? + .check()?; + } else { + terminal.print_warning("No sudo detected. Skipping system upgrade"); + } + + Ok(()) +} + fn upgrade_debian(sudo: &Option, terminal: &mut Terminal, dry_run: bool) -> Result<(), failure::Error> { if let Some(sudo) = &sudo { Executor::new(&sudo, dry_run)