Add FreeBSD

This commit is contained in:
Roey Darwish Dror
2018-11-12 11:13:43 +02:00
parent b14c948567
commit 1e73011a15
4 changed files with 77 additions and 1 deletions

View File

@@ -23,6 +23,7 @@ matrix:
- env: TARGET=armv7-unknown-linux-gnueabihf
- env: TARGET=x86_64-unknown-linux-gnu
- env: TARGET=x86_64-unknown-linux-musl
- env: TARGET=x86_64-unknown-freebsd
# OSX
- env: TARGET=x86_64-apple-darwin

View File

@@ -35,6 +35,7 @@ Just run `topgrade`. It will run the following steps:
* *Gentoo*: Run `layman -s ALL && emerge --sync -q && eix-update && emerge -uDNa world`
* *openSUSE*: Run `zypper refresh && zypper dist-upgrade`
* *Linux*: Run [etc-update](https://dev.gentoo.org/~zmedico/portage/doc/man/etc-update.1.html):
* *FreeBSD*: Upgrade and audit packages
* *Unix*: Run `brew update && brew upgrade`. This should handle both Homebrew and Linuxbrew
* *Unix*: Run `nix upgrade-nix && nix --upgrade`.
* *Windows*: Upgrade Powershell modules
@@ -79,6 +80,7 @@ Just run `topgrade`. It will run the following steps:
* *Linux*: Run [needrestart](https://github.com/liske/needrestart)
* *Windows*: Run Windows Update (You'll have to install [PSWindowsUpdate](https://marckean.com/2016/06/01/use-powershell-to-install-windows-updates/))
* *macOS*: Upgrade App Store applications
* *FreeBSD*: Run `freebsd-upgrade`
## Flags
* `-t/--tmux` - Topgrade will launch itself in a new tmux session. This flag has no effect if

56
src/freebsd.rs Normal file
View File

@@ -0,0 +1,56 @@
use super::executor::Executor;
use super::terminal::Terminal;
use super::utils::Check;
use failure;
use std::path::PathBuf;
#[must_use]
pub fn upgrade_freebsd(sudo: &Option<PathBuf>, terminal: &mut Terminal, dry_run: bool) -> Option<(&'static str, bool)> {
terminal.print_separator("FreeBSD Update");
if let Some(sudo) = sudo {
let success = || -> Result<(), failure::Error> {
Executor::new(sudo, dry_run)
.args(&["/usr/sbin/freebsd-update", "fetch", "install"])
.spawn()?
.wait()?
.check()?;
Ok(())
}().is_ok();
Some(("FreeBSD Update", success))
} else {
terminal.print_warning("No sudo or yay detected. Skipping system upgrade");
None
}
}
#[must_use]
pub fn upgrade_packages(
sudo: &Option<PathBuf>,
terminal: &mut Terminal,
dry_run: bool,
) -> Option<(&'static str, bool)> {
terminal.print_separator("FreeBSD Packages");
if let Some(sudo) = sudo {
let success = || -> Result<(), failure::Error> {
Executor::new(sudo, dry_run)
.args(&["/usr/sbin/pkg", "upgrade"])
.spawn()?
.wait()?
.check()?;
Executor::new("/usr/sbin/pkg", dry_run)
.arg("audit")
.spawn()?
.wait()?
.check()?;
Ok(())
}().is_ok();
Some(("FreeBSD Packages", success))
} else {
terminal.print_warning("No sudo or yay detected. Skipping package upgrade");
None
}
}

View File

@@ -27,6 +27,8 @@ extern crate lazy_static;
extern crate self_update;
extern crate walkdir;
#[cfg(target_os = "freebsd")]
mod freebsd;
#[cfg(target_os = "linux")]
mod linux;
#[cfg(target_os = "macos")]
@@ -132,7 +134,7 @@ fn run() -> Result<(), Error> {
let config = Config::read(&base_dirs)?;
let mut report = Report::new();
#[cfg(target_os = "linux")]
#[cfg(any(target_os = "freebsd", target_os = "linux"))]
let sudo = utils::which("sudo");
#[cfg(all(
@@ -200,6 +202,11 @@ fn run() -> Result<(), Error> {
|terminal| unix::run_homebrew(terminal, opt.dry_run),
&mut execution_context,
)?);
#[cfg(target_os = "freebsd")]
report.push_result(execute(
|terminal| freebsd::upgrade_packages(&sudo, terminal, opt.dry_run),
&mut execution_context,
)?);
#[cfg(unix)]
report.push_result(execute(
|terminal| unix::run_nix(terminal, opt.dry_run),
@@ -375,6 +382,16 @@ fn run() -> Result<(), Error> {
}
}
#[cfg(target_os = "freebsd")]
{
if !opt.no_system {
report.push_result(execute(
|terminal| freebsd::upgrade_freebsd(&sudo, terminal, opt.dry_run),
&mut execution_context,
)?);
}
}
#[cfg(windows)]
{
if !opt.no_system {