Gentoo support

This commit is contained in:
Roey Darwish Dror
2018-10-21 15:08:36 +03:00
parent 78396fc438
commit ba7192c21d
2 changed files with 43 additions and 0 deletions

View File

@@ -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`.

View File

@@ -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<PathBuf>, terminal: &mut Terminal, dry_run: bool
Ok(())
}
fn upgrade_gentoo(sudo: &Option<PathBuf>, 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<PathBuf>, terminal: &mut Terminal, dry_run: bool) -> Result<(), failure::Error> {
if let Some(sudo) = &sudo {
Executor::new(&sudo, dry_run)