2019-10-03 08:12:43 +03:00
|
|
|
use crate::config::Config;
|
2018-12-15 21:52:21 +02:00
|
|
|
use crate::error::{Error, ErrorKind};
|
2019-11-04 22:49:22 +02:00
|
|
|
use crate::executor::{ExecutorExitStatus, RunType};
|
2018-12-15 21:52:21 +02:00
|
|
|
use crate::terminal::{print_separator, print_warning};
|
2019-09-28 20:26:03 +03:00
|
|
|
use crate::utils::{require, require_option, which, PathExt};
|
2018-12-11 16:43:26 +02:00
|
|
|
use failure::ResultExt;
|
2019-05-16 15:29:35 +03:00
|
|
|
use ini::Ini;
|
2019-08-15 09:15:35 +03:00
|
|
|
use log::debug;
|
2019-05-07 16:21:51 +03:00
|
|
|
use serde::Deserialize;
|
2019-08-15 09:15:35 +03:00
|
|
|
use std::env::var_os;
|
|
|
|
|
use std::ffi::OsString;
|
2019-09-28 20:26:03 +03:00
|
|
|
use std::path::{Path, PathBuf};
|
2018-10-02 11:36:10 +03:00
|
|
|
use walkdir::WalkDir;
|
2018-06-07 16:19:11 +03:00
|
|
|
|
2019-05-07 16:21:51 +03:00
|
|
|
static OS_RELEASE_PATH: &str = "/etc/os-release";
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
|
|
|
#[serde(rename_all = "UPPERCASE")]
|
|
|
|
|
struct OsRelease {
|
|
|
|
|
id_like: Option<String>,
|
|
|
|
|
id: String,
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-14 15:25:50 +03:00
|
|
|
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
2018-06-07 16:19:11 +03:00
|
|
|
pub enum Distribution {
|
|
|
|
|
Arch,
|
|
|
|
|
CentOS,
|
|
|
|
|
Fedora,
|
|
|
|
|
Debian,
|
2018-10-21 15:08:36 +03:00
|
|
|
Gentoo,
|
2019-05-07 16:21:51 +03:00
|
|
|
Suse,
|
2018-11-20 14:38:23 +02:00
|
|
|
Void,
|
2019-03-21 10:36:40 -07:00
|
|
|
Solus,
|
2019-08-22 19:49:12 +02:00
|
|
|
Exherbo,
|
2018-06-07 16:19:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Distribution {
|
2019-05-16 15:29:35 +03:00
|
|
|
fn parse_os_release(os_release: &ini::Ini) -> Result<Self, Error> {
|
2019-05-16 15:37:35 +03:00
|
|
|
let section = os_release.general_section();
|
2019-05-16 15:29:35 +03:00
|
|
|
let id = section.get("ID").map(String::as_str);
|
2019-09-05 21:04:07 +03:00
|
|
|
let id_like: Option<Vec<&str>> = section
|
|
|
|
|
.get("ID_LIKE")
|
|
|
|
|
.map(|s| String::as_str(s).split_whitespace().collect());
|
|
|
|
|
|
|
|
|
|
if let Some(id_like) = id_like {
|
|
|
|
|
if id_like.contains(&"debian") || id_like.contains(&"ubuntu") {
|
|
|
|
|
return Ok(Distribution::Debian);
|
|
|
|
|
} else if id_like.contains(&"suse") {
|
|
|
|
|
return Ok(Distribution::Suse);
|
|
|
|
|
} else if id_like.contains(&"arch") || id_like.contains(&"archlinux") {
|
|
|
|
|
return Ok(Distribution::Arch);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ok(match id {
|
|
|
|
|
Some("centos") | Some("ol") => Distribution::CentOS,
|
|
|
|
|
Some("fedora") => Distribution::Fedora,
|
|
|
|
|
Some("void") => Distribution::Void,
|
|
|
|
|
Some("debian") => Distribution::Debian,
|
2019-09-28 22:09:26 +03:00
|
|
|
Some("arch") | Some("anarchy") => Distribution::Arch,
|
2019-09-05 21:04:07 +03:00
|
|
|
Some("solus") => Distribution::Solus,
|
|
|
|
|
Some("gentoo") => Distribution::Gentoo,
|
|
|
|
|
Some("exherbo") => Distribution::Exherbo,
|
2019-09-28 15:45:05 +03:00
|
|
|
_ => return Err(ErrorKind::UnknownLinuxDistribution.into()),
|
2019-05-16 15:29:35 +03:00
|
|
|
})
|
2019-05-07 16:21:51 +03:00
|
|
|
}
|
2019-03-21 10:36:40 -07:00
|
|
|
|
2019-05-07 16:21:51 +03:00
|
|
|
pub fn detect() -> Result<Self, Error> {
|
|
|
|
|
if PathBuf::from(OS_RELEASE_PATH).exists() {
|
2019-05-16 15:29:35 +03:00
|
|
|
let os_release = Ini::load_from_file(OS_RELEASE_PATH).context(ErrorKind::UnknownLinuxDistribution)?;
|
2019-05-14 15:25:50 +03:00
|
|
|
|
|
|
|
|
return Self::parse_os_release(&os_release);
|
2019-04-14 11:25:40 +03:00
|
|
|
}
|
|
|
|
|
|
2019-09-28 15:45:05 +03:00
|
|
|
Err(ErrorKind::UnknownLinuxDistribution.into())
|
2018-06-07 16:19:11 +03:00
|
|
|
}
|
2018-10-02 10:46:38 +03:00
|
|
|
|
|
|
|
|
#[must_use]
|
2019-10-03 08:12:43 +03:00
|
|
|
pub fn upgrade(self, sudo: &Option<PathBuf>, run_type: RunType, config: &Config) -> Result<(), Error> {
|
2018-12-05 11:34:08 +02:00
|
|
|
print_separator("System update");
|
2018-10-02 10:46:38 +03:00
|
|
|
|
2019-10-03 08:12:43 +03:00
|
|
|
let yes = config.yes();
|
|
|
|
|
let cleanup = config.cleanup();
|
|
|
|
|
|
2019-02-11 14:10:06 +02:00
|
|
|
match self {
|
2019-10-03 08:12:43 +03:00
|
|
|
Distribution::Arch => upgrade_arch_linux(&sudo, cleanup, run_type, yes, &config.yay_arguments()),
|
2019-09-28 20:26:03 +03:00
|
|
|
Distribution::CentOS | Distribution::Fedora => upgrade_redhat(&sudo, run_type, yes),
|
2019-09-28 15:45:05 +03:00
|
|
|
Distribution::Debian => upgrade_debian(&sudo, cleanup, run_type, yes),
|
2018-12-31 13:26:17 +02:00
|
|
|
Distribution::Gentoo => upgrade_gentoo(&sudo, run_type),
|
2019-05-07 16:21:51 +03:00
|
|
|
Distribution::Suse => upgrade_suse(&sudo, run_type),
|
2018-12-31 13:26:17 +02:00
|
|
|
Distribution::Void => upgrade_void(&sudo, run_type),
|
2019-03-21 10:36:40 -07:00
|
|
|
Distribution::Solus => upgrade_solus(&sudo, run_type),
|
2019-08-22 19:49:12 +02:00
|
|
|
Distribution::Exherbo => upgrade_exherbo(&sudo, cleanup, run_type),
|
2019-02-11 14:10:06 +02:00
|
|
|
}
|
2018-10-02 10:46:38 +03:00
|
|
|
}
|
2018-10-02 11:36:10 +03:00
|
|
|
|
|
|
|
|
pub fn show_summary(self) {
|
|
|
|
|
if let Distribution::Arch = self {
|
|
|
|
|
show_pacnew();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn show_pacnew() {
|
|
|
|
|
let mut iter = WalkDir::new("/etc")
|
|
|
|
|
.into_iter()
|
2019-04-14 11:35:18 +03:00
|
|
|
.filter_map(Result::ok)
|
2018-10-02 11:36:10 +03:00
|
|
|
.filter(|f| {
|
|
|
|
|
f.path()
|
|
|
|
|
.extension()
|
|
|
|
|
.filter(|ext| ext == &"pacnew" || ext == &"pacsave")
|
|
|
|
|
.is_some()
|
2018-12-11 16:00:19 +02:00
|
|
|
})
|
|
|
|
|
.peekable();
|
2018-10-02 11:36:10 +03:00
|
|
|
|
|
|
|
|
if iter.peek().is_some() {
|
|
|
|
|
println!("\nPacman backup configuration files found:");
|
|
|
|
|
|
|
|
|
|
for entry in iter {
|
|
|
|
|
println!("{}", entry.path().display());
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-06-07 16:19:11 +03:00
|
|
|
}
|
2018-06-12 21:28:32 +03:00
|
|
|
|
2019-10-03 08:12:43 +03:00
|
|
|
fn upgrade_arch_linux(
|
|
|
|
|
sudo: &Option<PathBuf>,
|
|
|
|
|
cleanup: bool,
|
|
|
|
|
run_type: RunType,
|
|
|
|
|
yes: bool,
|
|
|
|
|
yay_arguments: &str,
|
|
|
|
|
) -> Result<(), Error> {
|
2019-07-15 11:09:13 +03:00
|
|
|
let pacman = which("powerpill").unwrap_or_else(|| PathBuf::from("/usr/bin/pacman"));
|
2019-07-15 09:40:12 +03:00
|
|
|
|
2019-08-15 09:15:35 +03:00
|
|
|
let path = {
|
|
|
|
|
let mut path = OsString::from("/usr/bin:");
|
|
|
|
|
path.push(var_os("PATH").unwrap());
|
|
|
|
|
path
|
|
|
|
|
};
|
|
|
|
|
debug!("Running Arch update with path: {:?}", path);
|
|
|
|
|
|
2018-06-17 14:17:36 +03:00
|
|
|
if let Some(yay) = which("yay") {
|
2019-10-07 20:18:11 +03:00
|
|
|
run_type
|
|
|
|
|
.execute(&yay)
|
|
|
|
|
.arg("-Pw")
|
|
|
|
|
.spawn()
|
|
|
|
|
.and_then(|mut p| p.wait())
|
|
|
|
|
.ok();
|
|
|
|
|
|
2019-09-28 15:45:05 +03:00
|
|
|
let mut command = run_type.execute(yay);
|
|
|
|
|
|
|
|
|
|
command
|
2019-07-15 09:40:12 +03:00
|
|
|
.arg("--pacman")
|
|
|
|
|
.arg(pacman)
|
|
|
|
|
.arg("-Syu")
|
2019-10-03 08:12:43 +03:00
|
|
|
.args(yay_arguments.split_whitespace())
|
2019-09-28 15:45:05 +03:00
|
|
|
.env("PATH", path);
|
|
|
|
|
|
|
|
|
|
if yes {
|
|
|
|
|
command.arg("--noconfirm");
|
|
|
|
|
}
|
|
|
|
|
command.check_run()?;
|
2018-07-10 07:29:41 +03:00
|
|
|
} else if let Some(sudo) = &sudo {
|
2019-09-28 15:45:05 +03:00
|
|
|
let mut command = run_type.execute(&sudo);
|
|
|
|
|
command.arg(pacman).arg("-Syu").env("PATH", path);
|
|
|
|
|
if yes {
|
|
|
|
|
command.arg("--noconfirm");
|
|
|
|
|
}
|
|
|
|
|
command.check_run()?;
|
2018-06-12 21:28:32 +03:00
|
|
|
} else {
|
2019-09-08 14:40:21 +03:00
|
|
|
print_warning("Neither sudo nor yay detected. Skipping system upgrade");
|
2018-06-12 21:28:32 +03:00
|
|
|
}
|
|
|
|
|
|
2018-12-23 10:47:45 +02:00
|
|
|
if cleanup {
|
|
|
|
|
if let Some(sudo) = &sudo {
|
2018-12-31 22:00:34 +02:00
|
|
|
run_type.execute(&sudo).args(&["/usr/bin/pacman", "-Scc"]).check_run()?;
|
2018-12-23 10:47:45 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-12 21:28:32 +03:00
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-28 20:26:03 +03:00
|
|
|
fn upgrade_redhat(sudo: &Option<PathBuf>, run_type: RunType, yes: bool) -> Result<(), Error> {
|
2018-06-12 21:28:32 +03:00
|
|
|
if let Some(sudo) = &sudo {
|
2019-09-28 15:45:05 +03:00
|
|
|
let mut command = run_type.execute(&sudo);
|
2019-09-28 20:26:03 +03:00
|
|
|
command
|
|
|
|
|
.arg(
|
|
|
|
|
Path::new("/usr/bin/dnf")
|
|
|
|
|
.if_exists()
|
|
|
|
|
.unwrap_or_else(|| Path::new("/usr/bin/yum")),
|
|
|
|
|
)
|
|
|
|
|
.arg("upgrade");
|
2019-09-28 15:45:05 +03:00
|
|
|
if yes {
|
|
|
|
|
command.arg("-y");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
command.check_run()?;
|
2018-06-12 21:28:32 +03:00
|
|
|
} else {
|
2018-12-05 11:34:08 +02:00
|
|
|
print_warning("No sudo detected. Skipping system upgrade");
|
2018-11-03 22:57:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-07 16:21:51 +03:00
|
|
|
fn upgrade_suse(sudo: &Option<PathBuf>, run_type: RunType) -> Result<(), Error> {
|
2018-11-03 22:57:09 +02:00
|
|
|
if let Some(sudo) = &sudo {
|
2018-12-31 13:26:17 +02:00
|
|
|
run_type
|
|
|
|
|
.execute(&sudo)
|
2018-11-03 22:57:09 +02:00
|
|
|
.args(&["/usr/bin/zypper", "refresh"])
|
2018-12-31 22:00:34 +02:00
|
|
|
.check_run()?;
|
2018-11-03 22:57:09 +02:00
|
|
|
|
2018-12-31 13:26:17 +02:00
|
|
|
run_type
|
|
|
|
|
.execute(&sudo)
|
2018-11-03 22:57:09 +02:00
|
|
|
.args(&["/usr/bin/zypper", "dist-upgrade"])
|
2018-12-31 22:00:34 +02:00
|
|
|
.check_run()?;
|
2018-11-03 22:57:09 +02:00
|
|
|
} else {
|
2018-12-05 11:34:08 +02:00
|
|
|
print_warning("No sudo detected. Skipping system upgrade");
|
2018-11-20 14:38:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-31 13:26:17 +02:00
|
|
|
fn upgrade_void(sudo: &Option<PathBuf>, run_type: RunType) -> Result<(), Error> {
|
2018-11-20 14:38:23 +02:00
|
|
|
if let Some(sudo) = &sudo {
|
2019-07-01 09:43:53 +03:00
|
|
|
for _ in 0..2 {
|
|
|
|
|
run_type
|
|
|
|
|
.execute(&sudo)
|
|
|
|
|
.args(&["/usr/bin/xbps-install", "-Su"])
|
|
|
|
|
.check_run()?;
|
|
|
|
|
}
|
2018-11-20 14:38:23 +02:00
|
|
|
} else {
|
2018-12-05 11:34:08 +02:00
|
|
|
print_warning("No sudo detected. Skipping system upgrade");
|
2018-06-12 21:28:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-31 13:26:17 +02:00
|
|
|
fn upgrade_gentoo(sudo: &Option<PathBuf>, run_type: RunType) -> Result<(), Error> {
|
2018-10-21 15:08:36 +03:00
|
|
|
if let Some(sudo) = &sudo {
|
|
|
|
|
if let Some(layman) = which("layman") {
|
2018-12-31 22:00:34 +02:00
|
|
|
run_type.execute(&sudo).arg(layman).args(&["-s", "ALL"]).check_run()?;
|
2018-10-21 15:08:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
println!("Syncing portage");
|
2018-12-31 13:26:17 +02:00
|
|
|
run_type
|
|
|
|
|
.execute(&sudo)
|
2018-10-21 15:08:36 +03:00
|
|
|
.arg("/usr/bin/emerge")
|
|
|
|
|
.args(&["-q", "--sync"])
|
2018-12-31 22:00:34 +02:00
|
|
|
.check_run()?;
|
2018-10-21 15:08:36 +03:00
|
|
|
|
|
|
|
|
if let Some(eix_update) = which("eix-update") {
|
2018-12-31 22:00:34 +02:00
|
|
|
run_type.execute(&sudo).arg(eix_update).check_run()?;
|
2018-10-21 15:08:36 +03:00
|
|
|
}
|
|
|
|
|
|
2018-12-31 13:26:17 +02:00
|
|
|
run_type
|
|
|
|
|
.execute(&sudo)
|
2018-10-21 15:08:36 +03:00
|
|
|
.arg("/usr/bin/emerge")
|
|
|
|
|
.args(&["-uDNa", "world"])
|
2018-12-31 22:00:34 +02:00
|
|
|
.check_run()?;
|
2018-10-21 15:08:36 +03:00
|
|
|
} else {
|
2018-12-05 11:34:08 +02:00
|
|
|
print_warning("No sudo detected. Skipping system upgrade");
|
2018-10-21 15:08:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-28 15:45:05 +03:00
|
|
|
fn upgrade_debian(sudo: &Option<PathBuf>, cleanup: bool, run_type: RunType, yes: bool) -> Result<(), Error> {
|
2018-06-12 21:28:32 +03:00
|
|
|
if let Some(sudo) = &sudo {
|
2019-06-24 13:34:30 +03:00
|
|
|
let apt = which("apt-fast").unwrap_or_else(|| PathBuf::from("/usr/bin/apt"));
|
|
|
|
|
run_type.execute(&sudo).arg(&apt).arg("update").check_run()?;
|
2019-09-28 15:45:05 +03:00
|
|
|
let mut command = run_type.execute(&sudo);
|
|
|
|
|
command.arg(&apt).arg("dist-upgrade").check_run()?;
|
|
|
|
|
|
|
|
|
|
if yes {
|
|
|
|
|
command.arg("-y");
|
|
|
|
|
}
|
2018-12-16 23:22:59 -08:00
|
|
|
|
|
|
|
|
if cleanup {
|
2019-06-24 13:34:30 +03:00
|
|
|
run_type.execute(&sudo).arg(&apt).arg("clean").check_run()?;
|
2018-12-16 23:22:59 -08:00
|
|
|
|
2019-06-24 13:34:30 +03:00
|
|
|
run_type.execute(&sudo).arg(&apt).arg("autoremove").check_run()?;
|
2018-12-16 23:22:59 -08:00
|
|
|
}
|
2018-06-12 21:28:32 +03:00
|
|
|
} else {
|
2018-12-05 11:34:08 +02:00
|
|
|
print_warning("No sudo detected. Skipping system upgrade");
|
2018-06-12 21:28:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
2018-06-28 12:16:54 +03:00
|
|
|
|
2019-03-21 10:36:40 -07:00
|
|
|
fn upgrade_solus(sudo: &Option<PathBuf>, run_type: RunType) -> Result<(), Error> {
|
|
|
|
|
if let Some(sudo) = &sudo {
|
2019-03-21 13:10:54 -07:00
|
|
|
run_type
|
|
|
|
|
.execute(&sudo)
|
|
|
|
|
.args(&["/usr/bin/eopkg", "upgrade"])
|
|
|
|
|
.check_run()?;
|
2019-03-21 10:36:40 -07:00
|
|
|
} else {
|
|
|
|
|
print_warning("No sudo detected. Skipping system upgrade");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-22 19:49:12 +02:00
|
|
|
fn upgrade_exherbo(sudo: &Option<PathBuf>, cleanup: bool, run_type: RunType) -> Result<(), Error> {
|
|
|
|
|
if let Some(sudo) = &sudo {
|
|
|
|
|
run_type.execute(&sudo).args(&["/usr/bin/cave", "sync"]).check_run()?;
|
|
|
|
|
|
|
|
|
|
run_type
|
|
|
|
|
.execute(&sudo)
|
|
|
|
|
.args(&["/usr/bin/cave", "resolve", "world", "-c1", "-Cs", "-km", "-Km", "-x"])
|
|
|
|
|
.check_run()?;
|
|
|
|
|
|
|
|
|
|
if cleanup {
|
|
|
|
|
run_type
|
|
|
|
|
.execute(&sudo)
|
|
|
|
|
.args(&["/usr/bin/cave", "purge", "-x"])
|
|
|
|
|
.check_run()?;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
run_type
|
|
|
|
|
.execute(&sudo)
|
|
|
|
|
.args(&["/usr/bin/cave", "fix-linkage", "-x", "--", "-Cs"])
|
|
|
|
|
.check_run()?;
|
|
|
|
|
|
|
|
|
|
run_type
|
|
|
|
|
.execute(&sudo)
|
|
|
|
|
.args(&["/usr/bin/eclectic", "config", "interactive"])
|
|
|
|
|
.check_run()?;
|
|
|
|
|
} else {
|
|
|
|
|
print_warning("No sudo detected. Skipping system upgrade");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-11 14:10:06 +02:00
|
|
|
pub fn run_needrestart(sudo: Option<&PathBuf>, run_type: RunType) -> Result<(), Error> {
|
|
|
|
|
let sudo = require_option(sudo)?;
|
|
|
|
|
let needrestart = require("needrestart")?;
|
2018-06-28 12:16:54 +03:00
|
|
|
|
2019-02-11 14:10:06 +02:00
|
|
|
print_separator("Check for needed restarts");
|
2018-06-28 12:16:54 +03:00
|
|
|
|
2019-02-11 14:10:06 +02:00
|
|
|
run_type.execute(&sudo).arg(needrestart).check_run()?;
|
2018-08-19 14:45:23 +03:00
|
|
|
|
2019-02-11 14:10:06 +02:00
|
|
|
Ok(())
|
2018-06-28 12:16:54 +03:00
|
|
|
}
|
|
|
|
|
|
2018-08-19 14:45:23 +03:00
|
|
|
#[must_use]
|
2019-02-25 15:10:28 +02:00
|
|
|
pub fn run_fwupdmgr(run_type: RunType) -> Result<(), Error> {
|
|
|
|
|
let fwupdmgr = require("fwupdmgr")?;
|
|
|
|
|
|
|
|
|
|
print_separator("Firmware upgrades");
|
2018-08-19 14:45:23 +03:00
|
|
|
|
2019-02-25 15:10:28 +02:00
|
|
|
run_type.execute(&fwupdmgr).arg("refresh").check_run()?;
|
2019-11-04 22:49:22 +02:00
|
|
|
let exit_status = run_type.execute(&fwupdmgr).arg("get-updates").spawn()?.wait()?;
|
|
|
|
|
|
|
|
|
|
if let ExecutorExitStatus::Wet(e) = exit_status {
|
|
|
|
|
if !(e.success() || e.code().map(|c| c == 2).unwrap_or(false)) {
|
|
|
|
|
return Err(ErrorKind::ProcessFailed(e).into());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ok(())
|
2018-06-28 12:16:54 +03:00
|
|
|
}
|
|
|
|
|
|
2018-08-19 14:45:23 +03:00
|
|
|
#[must_use]
|
2019-02-25 15:10:28 +02:00
|
|
|
pub fn flatpak_update(run_type: RunType) -> Result<(), Error> {
|
|
|
|
|
let flatpak = require("flatpak")?;
|
|
|
|
|
print_separator("Flatpak User Packages");
|
|
|
|
|
|
|
|
|
|
run_type
|
|
|
|
|
.execute(&flatpak)
|
|
|
|
|
.args(&["update", "--user", "-y"])
|
|
|
|
|
.check_run()?;
|
|
|
|
|
run_type
|
|
|
|
|
.execute(&flatpak)
|
|
|
|
|
.args(&["update", "--system", "-y"])
|
|
|
|
|
.check_run()
|
2018-10-02 14:30:10 +03:00
|
|
|
}
|
|
|
|
|
|
2018-08-19 14:45:23 +03:00
|
|
|
#[must_use]
|
2019-02-25 15:10:28 +02:00
|
|
|
pub fn run_snap(sudo: Option<&PathBuf>, run_type: RunType) -> Result<(), Error> {
|
|
|
|
|
let sudo = require_option(sudo)?;
|
|
|
|
|
let snap = require("snap")?;
|
|
|
|
|
|
2019-09-10 22:59:08 +03:00
|
|
|
if !PathBuf::from("/var/snapd.socket").exists() && !PathBuf::from("/run/snapd.socket").exists() {
|
2019-09-28 15:45:05 +03:00
|
|
|
return Err(ErrorKind::SkipStep.into());
|
2018-08-19 14:45:23 +03:00
|
|
|
}
|
2019-02-25 15:10:28 +02:00
|
|
|
print_separator("snap");
|
2018-08-19 14:45:23 +03:00
|
|
|
|
2019-05-15 10:59:05 +03:00
|
|
|
run_type.execute(sudo).arg(snap).arg("refresh").check_run()
|
2018-06-28 12:16:54 +03:00
|
|
|
}
|
2018-10-02 13:25:02 +03:00
|
|
|
|
2019-05-15 11:34:20 +02:00
|
|
|
#[must_use]
|
|
|
|
|
pub fn run_rpi_update(sudo: Option<&PathBuf>, run_type: RunType) -> Result<(), Error> {
|
|
|
|
|
let sudo = require_option(sudo)?;
|
|
|
|
|
let rpi_update = require("rpi-update")?;
|
|
|
|
|
|
|
|
|
|
print_separator("rpi-update");
|
|
|
|
|
|
|
|
|
|
run_type.execute(sudo).arg(rpi_update).check_run()
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-15 12:08:15 +02:00
|
|
|
#[must_use]
|
|
|
|
|
pub fn run_pihole_update(sudo: Option<&PathBuf>, run_type: RunType) -> Result<(), Error> {
|
|
|
|
|
let sudo = require_option(sudo)?;
|
|
|
|
|
let pihole = require("pihole")?;
|
|
|
|
|
|
|
|
|
|
print_separator("pihole");
|
|
|
|
|
|
|
|
|
|
run_type.execute(sudo).arg(pihole).arg("-up").check_run()
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 13:25:02 +03:00
|
|
|
#[must_use]
|
2019-02-25 15:10:28 +02:00
|
|
|
pub fn run_etc_update(sudo: Option<&PathBuf>, run_type: RunType) -> Result<(), Error> {
|
|
|
|
|
let sudo = require_option(sudo)?;
|
2019-06-02 08:46:02 +03:00
|
|
|
let etc_update = require("etc-update")?;
|
2019-02-25 15:10:28 +02:00
|
|
|
print_separator("etc-update");
|
2018-10-02 13:25:02 +03:00
|
|
|
|
2019-05-15 10:59:05 +03:00
|
|
|
run_type.execute(sudo).arg(etc_update).check_run()
|
2018-10-02 13:25:02 +03:00
|
|
|
}
|
2019-05-14 15:25:50 +03:00
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
mod tests {
|
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
|
|
fn test_template(os_release_file: &str, expected_distribution: Distribution) {
|
2019-05-16 15:29:35 +03:00
|
|
|
let os_release = Ini::load_from_str(os_release_file).unwrap();
|
2019-05-14 15:25:50 +03:00
|
|
|
assert_eq!(
|
|
|
|
|
Distribution::parse_os_release(&os_release).unwrap(),
|
|
|
|
|
expected_distribution
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_arch_linux() {
|
|
|
|
|
test_template(&include_str!("os_release/arch"), Distribution::Arch);
|
2019-08-17 20:58:54 +03:00
|
|
|
test_template(&include_str!("os_release/arch32"), Distribution::Arch);
|
2019-05-14 15:25:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_centos() {
|
|
|
|
|
test_template(&include_str!("os_release/centos"), Distribution::CentOS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_debian() {
|
|
|
|
|
test_template(&include_str!("os_release/debian"), Distribution::Debian);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_ubuntu() {
|
|
|
|
|
test_template(&include_str!("os_release/ubuntu"), Distribution::Debian);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_mint() {
|
|
|
|
|
test_template(&include_str!("os_release/mint"), Distribution::Debian);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_opensuse() {
|
|
|
|
|
test_template(&include_str!("os_release/opensuse"), Distribution::Suse);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_oraclelinux() {
|
|
|
|
|
test_template(&include_str!("os_release/oracle"), Distribution::CentOS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_fedora() {
|
|
|
|
|
test_template(&include_str!("os_release/fedora"), Distribution::Fedora);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_antergos() {
|
|
|
|
|
test_template(&include_str!("os_release/antergos"), Distribution::Arch);
|
|
|
|
|
}
|
2019-05-16 13:38:00 +02:00
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_manjaro() {
|
|
|
|
|
test_template(&include_str!("os_release/manjaro"), Distribution::Arch);
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-10 11:51:39 +02:00
|
|
|
#[test]
|
|
|
|
|
fn test_anarchy() {
|
|
|
|
|
test_template(&include_str!("os_release/anarchy"), Distribution::Arch);
|
|
|
|
|
}
|
2019-08-14 14:34:46 +03:00
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_gentoo() {
|
|
|
|
|
test_template(&include_str!("os_release/gentoo"), Distribution::Gentoo);
|
|
|
|
|
}
|
2019-08-22 19:49:12 +02:00
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_exherbo() {
|
|
|
|
|
test_template(&include_str!("os_release/exherbo"), Distribution::Exherbo);
|
|
|
|
|
}
|
2019-05-14 15:25:50 +03:00
|
|
|
}
|