2018-11-12 11:13:43 +02:00
|
|
|
use super::executor::Executor;
|
2018-12-05 11:34:08 +02:00
|
|
|
use super::terminal::{print_separator, print_warning};
|
2018-11-12 11:13:43 +02:00
|
|
|
use super::utils::Check;
|
|
|
|
|
use failure;
|
|
|
|
|
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]
|
2018-12-05 11:34:08 +02:00
|
|
|
pub fn upgrade_freebsd(sudo: &Option<PathBuf>, dry_run: bool) -> Option<(&'static str, bool)> {
|
|
|
|
|
print_separator("FreeBSD Update");
|
2018-11-12 11:13:43 +02:00
|
|
|
|
|
|
|
|
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(())
|
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]
|
2018-12-05 11:34:08 +02:00
|
|
|
pub fn upgrade_packages(sudo: &Option<PathBuf>, dry_run: bool) -> Option<(&'static str, bool)> {
|
|
|
|
|
print_separator("FreeBSD Packages");
|
2018-11-12 11:13:43 +02:00
|
|
|
|
|
|
|
|
if let Some(sudo) = sudo {
|
|
|
|
|
let success = || -> Result<(), failure::Error> {
|
|
|
|
|
Executor::new(sudo, dry_run)
|
|
|
|
|
.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-11-15 15:54:24 +02:00
|
|
|
pub fn audit_packages(sudo: &Option<PathBuf>) -> Result<(), failure::Error> {
|
|
|
|
|
if let Some(sudo) = sudo {
|
|
|
|
|
println!();
|
|
|
|
|
Command::new(sudo)
|
|
|
|
|
.args(&["/usr/sbin/pkg", "audit", "-Fr"])
|
|
|
|
|
.spawn()?
|
|
|
|
|
.wait()?;
|
|
|
|
|
}
|
2018-11-15 11:37:08 +02:00
|
|
|
Ok(())
|
|
|
|
|
}
|