Add FreeBSD
This commit is contained in:
56
src/freebsd.rs
Normal file
56
src/freebsd.rs
Normal 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
|
||||
}
|
||||
}
|
||||
19
src/main.rs
19
src/main.rs
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user