Add a flag to control Windows update acceptance policy (fix #310)

This commit is contained in:
Roey Darwish Dror
2020-01-30 20:42:49 +02:00
parent b91fa4e26c
commit 8c12707693
4 changed files with 19 additions and 3 deletions

View File

@@ -34,6 +34,9 @@
# Arguments to pass yay when updating packages
#yay_arguments = "--nodevel"
# Manually select Windows updates
# accept_all_windows_updates = false
# Do not set the terminal title
#set_title = false
# Commands to run before anything

View File

@@ -69,6 +69,7 @@ pub struct ConfigFile {
no_retry: Option<bool>,
run_in_tmux: Option<bool>,
cleanup: Option<bool>,
accept_all_windows_updates: Option<bool>,
only: Option<Vec<Step>>,
}
@@ -346,6 +347,12 @@ impl Config {
self.config_file.assume_yes.unwrap_or(self.opt.yes)
}
/// Whether to accept all Windows updates
#[allow(dead_code)]
pub fn accept_all_windows_updates(&self) -> bool {
self.config_file.accept_all_windows_updates.unwrap_or(true)
}
/// Extra yay arguments
#[cfg(target_os = "linux")]
pub fn yay_arguments(&self) -> &str {

View File

@@ -623,7 +623,10 @@ fn run() -> Result<()> {
execute(
&mut report,
"Windows update",
|| powershell::Powershell::windows_powershell().windows_update(run_type),
|| {
powershell::Powershell::windows_powershell()
.windows_update(run_type, config.accept_all_windows_updates())
},
config.no_retry(),
)?;
}

View File

@@ -65,7 +65,7 @@ impl Powershell {
}
#[cfg(windows)]
pub fn windows_update(&self, run_type: RunType) -> Result<()> {
pub fn windows_update(&self, run_type: RunType, accept_all_updates: bool) -> Result<()> {
let powershell = require_option(self.path.as_ref())?;
if !Self::has_module(&powershell, "PSWindowsUpdate") {
@@ -77,7 +77,10 @@ impl Powershell {
.execute(&powershell)
.args(&[
"-Command",
"Import-Module PSWindowsUpdate; Install-WindowsUpdate -MicrosoftUpdate -AcceptAll -Verbose",
&format!(
"Import-Module PSWindowsUpdate; Install-WindowsUpdate -MicrosoftUpdate {} -Verbose",
if accept_all_updates { "-AcceptAll" } else { "" }
),
])
.check_run()
}