Windows Update (fix #37)
This commit is contained in:
13
src/main.rs
13
src/main.rs
@@ -98,13 +98,15 @@ fn run() -> Result<(), Error> {
|
||||
#[cfg(windows)]
|
||||
report(&mut reports, powershell.update_modules(&mut terminal));
|
||||
|
||||
if !(matches.is_present("no_system")) {
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
if !(matches.is_present("no_system")) {
|
||||
report(&mut reports, linux::upgrade(&sudo, &mut terminal));
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
report(&mut reports, windows::run_chocolatey(&mut terminal));
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
report(&mut reports, unix::run_homebrew(&mut terminal));
|
||||
@@ -178,6 +180,13 @@ fn run() -> Result<(), Error> {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
{
|
||||
if !(matches.is_present("no_system")) {
|
||||
report(&mut reports, powershell.windows_update(&mut terminal));
|
||||
}
|
||||
}
|
||||
|
||||
if !reports.is_empty() {
|
||||
terminal.print_separator("Summary");
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ use failure::Error;
|
||||
use std::ffi::OsStr;
|
||||
use std::fmt::Debug;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::ExitStatus;
|
||||
use std::process::{ExitStatus, Output};
|
||||
use which as which_mod;
|
||||
|
||||
#[derive(Fail, Debug)]
|
||||
@@ -23,6 +23,12 @@ impl Check for ExitStatus {
|
||||
}
|
||||
}
|
||||
|
||||
impl Check for Output {
|
||||
fn check(self) -> Result<(), Error> {
|
||||
self.status.check()
|
||||
}
|
||||
}
|
||||
|
||||
pub trait PathExt
|
||||
where
|
||||
Self: Sized,
|
||||
|
||||
@@ -31,17 +31,49 @@ impl Powershell {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn has_command(powershell: &PathBuf, command: &str) -> bool {
|
||||
|| -> Result<(), failure::Error> {
|
||||
Command::new(&powershell)
|
||||
.args(&["-Command", &format!("Get-Command {}", command)])
|
||||
.output()?
|
||||
.check()?;
|
||||
Ok(())
|
||||
}().is_ok()
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn update_modules(&self, terminal: &mut Terminal) -> Option<(&'static str, bool)> {
|
||||
if let Some(powershell) = &self.path {
|
||||
terminal.print_separator("Powershell Module Update");
|
||||
terminal.print_separator("Powershell Modules Update");
|
||||
|
||||
let success = || -> Result<(), failure::Error> {
|
||||
Command::new(&powershell).arg("Update-Module").spawn()?.wait()?.check()?;
|
||||
Ok(())
|
||||
}().is_ok();
|
||||
|
||||
return Some(("Powershell Module Update", success));
|
||||
return Some(("Powershell Modules Update", success));
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn windows_update(&self, terminal: &mut Terminal) -> Option<(&'static str, bool)> {
|
||||
if let Some(powershell) = &self.path {
|
||||
if Self::has_command(&powershell, "Install-WindowsUpdate") {
|
||||
terminal.print_separator("Windows Update");
|
||||
|
||||
let success = || -> Result<(), failure::Error> {
|
||||
Command::new(&powershell)
|
||||
.args(&["-Command", "Install-WindowsUpdate -MicrosoftUpdate -AcceptAll -Verbose"])
|
||||
.spawn()?
|
||||
.wait()?
|
||||
.check()?;
|
||||
Ok(())
|
||||
}().is_ok();
|
||||
|
||||
return Some(("Windows Update", success));
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
|
||||
Reference in New Issue
Block a user