Files
topgrade/src/steps/os/freebsd.rs

67 lines
1.8 KiB
Rust
Raw Normal View History

2018-12-15 21:52:21 +02:00
use crate::error::{Error, ErrorKind};
use crate::executor::Executor;
use crate::terminal::{print_separator, print_warning};
use crate::utils::Check;
2018-12-11 16:43:26 +02:00
use failure::ResultExt;
2018-11-12 11:13:43 +02:00
use std::path::PathBuf;
2018-11-15 11:37:08 +02:00
use std::process::Command;
2018-11-12 11:13:43 +02:00
#[must_use]
pub fn upgrade_freebsd(sudo: &Option<PathBuf>, run_type: RunType) -> Option<(&'static str, bool)> {
2018-12-05 11:34:08 +02:00
print_separator("FreeBSD Update");
2018-11-12 11:13:43 +02:00
if let Some(sudo) = sudo {
2018-12-11 16:43:26 +02:00
let success = || -> Result<(), Error> {
2018-12-31 13:34:56 +02:00
run_type
.execute(sudo)
2018-11-12 11:13:43 +02:00
.args(&["/usr/sbin/freebsd-update", "fetch", "install"])
.spawn()?
.wait()?
.check()?;
Ok(())
2018-12-11 16:00:19 +02:00
}()
.is_ok();
2018-11-12 11:13:43 +02:00
Some(("FreeBSD Update", success))
} else {
2018-12-05 11:34:08 +02:00
print_warning("No sudo or yay detected. Skipping system upgrade");
2018-11-12 11:13:43 +02:00
None
}
}
#[must_use]
pub fn upgrade_packages(sudo: &Option<PathBuf>, run_type: RunType) -> Option<(&'static str, bool)> {
2018-12-05 11:34:08 +02:00
print_separator("FreeBSD Packages");
2018-11-12 11:13:43 +02:00
if let Some(sudo) = sudo {
2018-12-11 16:43:26 +02:00
let success = || -> Result<(), Error> {
2018-12-31 13:34:56 +02:00
run_type
.execute(sudo)
2018-11-12 11:13:43 +02:00
.args(&["/usr/sbin/pkg", "upgrade"])
.spawn()?
.wait()?
.check()?;
Ok(())
2018-12-11 16:00:19 +02:00
}()
.is_ok();
2018-11-12 11:13:43 +02:00
Some(("FreeBSD Packages", success))
} else {
2018-12-05 11:34:08 +02:00
print_warning("No sudo or yay detected. Skipping package upgrade");
2018-11-12 11:13:43 +02:00
None
}
}
2018-11-15 11:37:08 +02:00
2018-12-11 16:43:26 +02:00
pub fn audit_packages(sudo: &Option<PathBuf>) -> Result<(), Error> {
2018-11-15 15:54:24 +02:00
if let Some(sudo) = sudo {
println!();
Command::new(sudo)
.args(&["/usr/sbin/pkg", "audit", "-Fr"])
2018-12-11 16:43:26 +02:00
.spawn()
.context(ErrorKind::ProcessExecution)?
.wait()
.context(ErrorKind::ProcessExecution)?;
2018-11-15 15:54:24 +02:00
}
2018-11-15 11:37:08 +02:00
Ok(())
}