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 # Arguments to pass yay when updating packages
#yay_arguments = "--nodevel" #yay_arguments = "--nodevel"
# Manually select Windows updates
# accept_all_windows_updates = false
# Do not set the terminal title # Do not set the terminal title
#set_title = false #set_title = false
# Commands to run before anything # Commands to run before anything

View File

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

View File

@@ -623,7 +623,10 @@ fn run() -> Result<()> {
execute( execute(
&mut report, &mut report,
"Windows update", "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(), config.no_retry(),
)?; )?;
} }

View File

@@ -65,7 +65,7 @@ impl Powershell {
} }
#[cfg(windows)] #[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())?; let powershell = require_option(self.path.as_ref())?;
if !Self::has_module(&powershell, "PSWindowsUpdate") { if !Self::has_module(&powershell, "PSWindowsUpdate") {
@@ -77,7 +77,10 @@ impl Powershell {
.execute(&powershell) .execute(&powershell)
.args(&[ .args(&[
"-Command", "-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() .check_run()
} }