committed by
GitHub
parent
ab318905a1
commit
fb38b792a4
@@ -60,6 +60,7 @@ pub struct ConfigFile {
|
|||||||
ssh_arguments: Option<String>,
|
ssh_arguments: Option<String>,
|
||||||
git_arguments: Option<String>,
|
git_arguments: Option<String>,
|
||||||
set_title: Option<bool>,
|
set_title: Option<bool>,
|
||||||
|
assume_yes: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ConfigFile {
|
impl ConfigFile {
|
||||||
@@ -154,6 +155,10 @@ pub struct CommandLineArgs {
|
|||||||
/// Prompt for a key before exiting
|
/// Prompt for a key before exiting
|
||||||
#[structopt(short = "k", long = "keep")]
|
#[structopt(short = "k", long = "keep")]
|
||||||
keep_at_end: bool,
|
keep_at_end: bool,
|
||||||
|
|
||||||
|
/// Say yes to package manager's prompt (experimental)
|
||||||
|
#[structopt(short = "y", long = "yes")]
|
||||||
|
yes: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Represents the application configuration
|
/// Represents the application configuration
|
||||||
@@ -275,4 +280,10 @@ impl Config {
|
|||||||
pub fn set_title(&self) -> bool {
|
pub fn set_title(&self) -> bool {
|
||||||
self.config_file.set_title.unwrap_or(true)
|
self.config_file.set_title.unwrap_or(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Whether to say yes to package managers
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub fn yes(&self) -> bool {
|
||||||
|
self.config_file.assume_yes.unwrap_or(self.opt.yes)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -158,7 +158,7 @@ fn run() -> Result<(), Error> {
|
|||||||
execute(
|
execute(
|
||||||
&mut report,
|
&mut report,
|
||||||
"System update",
|
"System update",
|
||||||
|| distribution.upgrade(&sudo, config.cleanup(), run_type),
|
|| distribution.upgrade(&sudo, config.cleanup(), run_type, config.yes()),
|
||||||
config.no_retry(),
|
config.no_retry(),
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,11 +56,11 @@ impl Distribution {
|
|||||||
Some("fedora") => Distribution::Fedora,
|
Some("fedora") => Distribution::Fedora,
|
||||||
Some("void") => Distribution::Void,
|
Some("void") => Distribution::Void,
|
||||||
Some("debian") => Distribution::Debian,
|
Some("debian") => Distribution::Debian,
|
||||||
Some("arch") | Some("anarchy") => Distribution::Arch,
|
Some("arch") | Some("ana") => Distribution::Arch,
|
||||||
Some("solus") => Distribution::Solus,
|
Some("solus") => Distribution::Solus,
|
||||||
Some("gentoo") => Distribution::Gentoo,
|
Some("gentoo") => Distribution::Gentoo,
|
||||||
Some("exherbo") => Distribution::Exherbo,
|
Some("exherbo") => Distribution::Exherbo,
|
||||||
_ => Err(ErrorKind::UnknownLinuxDistribution)?,
|
_ => return Err(ErrorKind::UnknownLinuxDistribution.into()),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,18 +71,18 @@ impl Distribution {
|
|||||||
return Self::parse_os_release(&os_release);
|
return Self::parse_os_release(&os_release);
|
||||||
}
|
}
|
||||||
|
|
||||||
Err(ErrorKind::UnknownLinuxDistribution)?
|
Err(ErrorKind::UnknownLinuxDistribution.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn upgrade(self, sudo: &Option<PathBuf>, cleanup: bool, run_type: RunType) -> Result<(), Error> {
|
pub fn upgrade(self, sudo: &Option<PathBuf>, cleanup: bool, run_type: RunType, yes: bool) -> Result<(), Error> {
|
||||||
print_separator("System update");
|
print_separator("System update");
|
||||||
|
|
||||||
match self {
|
match self {
|
||||||
Distribution::Arch => upgrade_arch_linux(&sudo, cleanup, run_type),
|
Distribution::Arch => upgrade_arch_linux(&sudo, cleanup, run_type, yes),
|
||||||
Distribution::CentOS => upgrade_redhat(&sudo, run_type),
|
Distribution::CentOS => upgrade_redhat(&sudo, run_type, yes, false),
|
||||||
Distribution::Fedora => upgrade_fedora(&sudo, run_type),
|
Distribution::Fedora => upgrade_redhat(&sudo, run_type, yes, true),
|
||||||
Distribution::Debian => upgrade_debian(&sudo, cleanup, run_type),
|
Distribution::Debian => upgrade_debian(&sudo, cleanup, run_type, yes),
|
||||||
Distribution::Gentoo => upgrade_gentoo(&sudo, run_type),
|
Distribution::Gentoo => upgrade_gentoo(&sudo, run_type),
|
||||||
Distribution::Suse => upgrade_suse(&sudo, run_type),
|
Distribution::Suse => upgrade_suse(&sudo, run_type),
|
||||||
Distribution::Void => upgrade_void(&sudo, run_type),
|
Distribution::Void => upgrade_void(&sudo, run_type),
|
||||||
@@ -119,7 +119,7 @@ pub fn show_pacnew() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn upgrade_arch_linux(sudo: &Option<PathBuf>, cleanup: bool, run_type: RunType) -> Result<(), Error> {
|
fn upgrade_arch_linux(sudo: &Option<PathBuf>, cleanup: bool, run_type: RunType, yes: bool) -> Result<(), Error> {
|
||||||
let pacman = which("powerpill").unwrap_or_else(|| PathBuf::from("/usr/bin/pacman"));
|
let pacman = which("powerpill").unwrap_or_else(|| PathBuf::from("/usr/bin/pacman"));
|
||||||
|
|
||||||
let path = {
|
let path = {
|
||||||
@@ -130,21 +130,26 @@ fn upgrade_arch_linux(sudo: &Option<PathBuf>, cleanup: bool, run_type: RunType)
|
|||||||
debug!("Running Arch update with path: {:?}", path);
|
debug!("Running Arch update with path: {:?}", path);
|
||||||
|
|
||||||
if let Some(yay) = which("yay") {
|
if let Some(yay) = which("yay") {
|
||||||
run_type
|
let mut command = run_type.execute(yay);
|
||||||
.execute(yay)
|
|
||||||
|
command
|
||||||
.arg("--pacman")
|
.arg("--pacman")
|
||||||
.arg(pacman)
|
.arg(pacman)
|
||||||
.arg("-Syu")
|
.arg("-Syu")
|
||||||
.arg("--devel")
|
.arg("--devel")
|
||||||
.env("PATH", path)
|
.env("PATH", path);
|
||||||
.check_run()?;
|
|
||||||
|
if yes {
|
||||||
|
command.arg("--noconfirm");
|
||||||
|
}
|
||||||
|
command.check_run()?;
|
||||||
} else if let Some(sudo) = &sudo {
|
} else if let Some(sudo) = &sudo {
|
||||||
run_type
|
let mut command = run_type.execute(&sudo);
|
||||||
.execute(&sudo)
|
command.arg(pacman).arg("-Syu").env("PATH", path);
|
||||||
.arg(pacman)
|
if yes {
|
||||||
.arg("-Syu")
|
command.arg("--noconfirm");
|
||||||
.env("PATH", path)
|
}
|
||||||
.check_run()?;
|
command.check_run()?;
|
||||||
} else {
|
} else {
|
||||||
print_warning("Neither sudo nor yay detected. Skipping system upgrade");
|
print_warning("Neither sudo nor yay detected. Skipping system upgrade");
|
||||||
}
|
}
|
||||||
@@ -158,9 +163,15 @@ fn upgrade_arch_linux(sudo: &Option<PathBuf>, cleanup: bool, run_type: RunType)
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn upgrade_redhat(sudo: &Option<PathBuf>, run_type: RunType) -> Result<(), Error> {
|
fn upgrade_redhat(sudo: &Option<PathBuf>, run_type: RunType, yes: bool, dnf: bool) -> Result<(), Error> {
|
||||||
if let Some(sudo) = &sudo {
|
if let Some(sudo) = &sudo {
|
||||||
run_type.execute(&sudo).args(&["/usr/bin/yum", "upgrade"]).check_run()?;
|
let mut command = run_type.execute(&sudo);
|
||||||
|
command.args(&[if dnf { "/usr/bin/dnf" } else { "/usr/bin/yum" }, "upgrade"]);
|
||||||
|
if yes {
|
||||||
|
command.arg("-y");
|
||||||
|
}
|
||||||
|
|
||||||
|
command.check_run()?;
|
||||||
} else {
|
} else {
|
||||||
print_warning("No sudo detected. Skipping system upgrade");
|
print_warning("No sudo detected. Skipping system upgrade");
|
||||||
}
|
}
|
||||||
@@ -201,16 +212,6 @@ fn upgrade_void(sudo: &Option<PathBuf>, run_type: RunType) -> Result<(), Error>
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn upgrade_fedora(sudo: &Option<PathBuf>, run_type: RunType) -> Result<(), Error> {
|
|
||||||
if let Some(sudo) = &sudo {
|
|
||||||
run_type.execute(&sudo).args(&["/usr/bin/dnf", "upgrade"]).check_run()?;
|
|
||||||
} else {
|
|
||||||
print_warning("No sudo detected. Skipping system upgrade");
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn upgrade_gentoo(sudo: &Option<PathBuf>, run_type: RunType) -> Result<(), Error> {
|
fn upgrade_gentoo(sudo: &Option<PathBuf>, run_type: RunType) -> Result<(), Error> {
|
||||||
if let Some(sudo) = &sudo {
|
if let Some(sudo) = &sudo {
|
||||||
if let Some(layman) = which("layman") {
|
if let Some(layman) = which("layman") {
|
||||||
@@ -240,11 +241,16 @@ fn upgrade_gentoo(sudo: &Option<PathBuf>, run_type: RunType) -> Result<(), Error
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn upgrade_debian(sudo: &Option<PathBuf>, cleanup: bool, run_type: RunType) -> Result<(), Error> {
|
fn upgrade_debian(sudo: &Option<PathBuf>, cleanup: bool, run_type: RunType, yes: bool) -> Result<(), Error> {
|
||||||
if let Some(sudo) = &sudo {
|
if let Some(sudo) = &sudo {
|
||||||
let apt = which("apt-fast").unwrap_or_else(|| PathBuf::from("/usr/bin/apt"));
|
let apt = which("apt-fast").unwrap_or_else(|| PathBuf::from("/usr/bin/apt"));
|
||||||
run_type.execute(&sudo).arg(&apt).arg("update").check_run()?;
|
run_type.execute(&sudo).arg(&apt).arg("update").check_run()?;
|
||||||
run_type.execute(&sudo).arg(&apt).arg("dist-upgrade").check_run()?;
|
let mut command = run_type.execute(&sudo);
|
||||||
|
command.arg(&apt).arg("dist-upgrade").check_run()?;
|
||||||
|
|
||||||
|
if yes {
|
||||||
|
command.arg("-y");
|
||||||
|
}
|
||||||
|
|
||||||
if cleanup {
|
if cleanup {
|
||||||
run_type.execute(&sudo).arg(&apt).arg("clean").check_run()?;
|
run_type.execute(&sudo).arg(&apt).arg("clean").check_run()?;
|
||||||
@@ -345,7 +351,7 @@ pub fn run_snap(sudo: Option<&PathBuf>, run_type: RunType) -> Result<(), Error>
|
|||||||
let snap = require("snap")?;
|
let snap = require("snap")?;
|
||||||
|
|
||||||
if !PathBuf::from("/var/snapd.socket").exists() && !PathBuf::from("/run/snapd.socket").exists() {
|
if !PathBuf::from("/var/snapd.socket").exists() && !PathBuf::from("/run/snapd.socket").exists() {
|
||||||
Err(ErrorKind::SkipStep)?;
|
return Err(ErrorKind::SkipStep.into());
|
||||||
}
|
}
|
||||||
print_separator("snap");
|
print_separator("snap");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user