diff --git a/config.example.toml b/config.example.toml index e171263a..7ee2c947 100644 --- a/config.example.toml +++ b/config.example.toml @@ -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 diff --git a/src/config.rs b/src/config.rs index a6174bb2..76d38eec 100644 --- a/src/config.rs +++ b/src/config.rs @@ -235,10 +235,20 @@ pub struct Vagrant { always_suspend: Option, } +#[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, + updates_auto_reboot: Option, self_rename: Option, open_remotes_in_new_terminal: Option, wsl_update_pre_release: Option, @@ -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 diff --git a/src/steps/powershell.rs b/src/steps/powershell.rs index 75a11708..cf5d930f 100644 --- a/src/steps/powershell.rs +++ b/src/steps/powershell.rs @@ -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