windows update, use explicit reboot policy (#1143)
This commit is contained in:
@@ -213,6 +213,10 @@
|
||||
# Manually select Windows updates
|
||||
# accept_all_updates = false
|
||||
|
||||
# Controls whether to automatically reboot the computer when updates are
|
||||
# installed that request it. (default: "no", allowed values: "yes", "no", "ask")
|
||||
# updates_auto_reboot = "yes"
|
||||
|
||||
# open_remotes_in_new_terminal = true
|
||||
|
||||
# wsl_update_pre_release = true
|
||||
|
||||
@@ -235,10 +235,20 @@ pub struct Vagrant {
|
||||
always_suspend: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Default, Debug, Copy, Clone)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum UpdatesAutoReboot {
|
||||
Yes,
|
||||
#[default]
|
||||
No,
|
||||
Ask,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Default, Debug, Merge)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct Windows {
|
||||
accept_all_updates: Option<bool>,
|
||||
updates_auto_reboot: Option<UpdatesAutoReboot>,
|
||||
self_rename: Option<bool>,
|
||||
open_remotes_in_new_terminal: Option<bool>,
|
||||
wsl_update_pre_release: Option<bool>,
|
||||
@@ -1219,6 +1229,15 @@ impl Config {
|
||||
.unwrap_or(true)
|
||||
}
|
||||
|
||||
/// Whether to auto reboot for Windows updates that require it
|
||||
pub fn windows_updates_auto_reboot(&self) -> UpdatesAutoReboot {
|
||||
self.config_file
|
||||
.windows
|
||||
.as_ref()
|
||||
.and_then(|windows| windows.updates_auto_reboot)
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
/// Whether to self rename the Topgrade executable during the run
|
||||
pub fn self_rename(&self) -> bool {
|
||||
self.config_file
|
||||
|
||||
@@ -156,6 +156,7 @@ impl Powershell {
|
||||
#[cfg(windows)]
|
||||
mod windows {
|
||||
use super::*;
|
||||
use crate::config::UpdatesAutoReboot;
|
||||
|
||||
pub fn supports_windows_update(powershell: &Powershell) -> bool {
|
||||
powershell
|
||||
@@ -174,6 +175,11 @@ mod windows {
|
||||
if ctx.config().accept_all_windows_updates() {
|
||||
command_str.push_str(" -AcceptAll");
|
||||
}
|
||||
match ctx.config().windows_updates_auto_reboot() {
|
||||
UpdatesAutoReboot::Yes => command_str.push_str(" -AutoReboot"),
|
||||
UpdatesAutoReboot::No => command_str.push_str(" -IgnoreReboot"),
|
||||
UpdatesAutoReboot::Ask => (), // Prompting is the default for Install-WindowsUpdate
|
||||
}
|
||||
|
||||
// Pass the command string using the -Command flag
|
||||
powershell
|
||||
|
||||
Reference in New Issue
Block a user