Add scripts for updating windows

This commit is contained in:
Manuel Thalmann 2024-08-01 02:59:32 +02:00
parent 286073fc82
commit 0aaa1e1c40
2 changed files with 58 additions and 11 deletions

View file

@ -4,10 +4,10 @@
. "$PSScriptRoot/../Scripts/Hooks.ps1"; . "$PSScriptRoot/../Scripts/Hooks.ps1";
. "$PSScriptRoot/../Scripts/PowerManagement.ps1"; . "$PSScriptRoot/../Scripts/PowerManagement.ps1";
. "$PSScriptRoot/../Scripts/SetupConfig.ps1"; . "$PSScriptRoot/../Scripts/SetupConfig.ps1";
. "$PSScriptRoot/../Scripts/Update.ps1";
. "$PSScriptRoot/../Scripts/Context.ps1"; . "$PSScriptRoot/../Scripts/Context.ps1";
. "$PSScriptRoot/../Software/Firefox/Install.ps1"; . "$PSScriptRoot/../Software/Firefox/Install.ps1";
. "$PSScriptRoot/Manage.ps1"; . "$PSScriptRoot/Manage.ps1";
. "$PSScriptRoot/Upgrade.ps1";
. "$PSScriptRoot/User/Install.ps1"; . "$PSScriptRoot/User/Install.ps1";
<# <#
@ -23,15 +23,9 @@ function Start-WindowsInstallation {
Starts the installation loop. Starts the installation loop.
#> #>
function Start-InstallationLoop { function Start-InstallationLoop {
. "$PSScriptRoot/../Scripts/Choco.ps1";
. "$PSScriptRoot/../Scripts/Hooks.ps1";
. "$PSScriptRoot/../Scripts/PowerManagement.ps1";
. "$PSScriptRoot/../Scripts/SetupConfig.ps1";
while (-not (Get-IsFinished)) { while (-not (Get-IsFinished)) {
if (-not (Get-Stage)) { if ($null -eq (Get-Stage)) {
Set-Stage [SetupStage]::Initialize; Set-Stage ([SetupStage]::Initialize);
break;
} elseif ((Get-Stage) -eq ([SetupStage]::Initialize)) { } elseif ((Get-Stage) -eq ([SetupStage]::Initialize)) {
if (-not ((Get-Command "choco") -and (Get-Command "refreshenv"))) { if (-not ((Get-Command "choco") -and (Get-Command "refreshenv"))) {
Invoke-Hook "Install-Chocolatey" -Fallback { Invoke-Hook "Install-Chocolatey" -Fallback {
@ -52,12 +46,30 @@ function Start-InstallationLoop {
return; return;
} }
Invoke-Hook "Install-PSModules" -Fallback {
Install-Module -AcceptLicense -Force PSWindowsUpdate;
};
if (Test-Path $env:PWSH_PATH) { if (Test-Path $env:PWSH_PATH) {
Remove-Item -Recurse $env:PWSH_PATH; attrib "-R" "$env:PWSH_PATH\*" /S /D;
Remove-Item -Recurse -Force $env:PWSH_PATH;
} else {
Set-Stage ([SetupStage]::Install);
} }
} else { } else {
$null = Import-Module PSWindowsUpdate;
Invoke-Hook "Invoke-WindowsUpdate" -Fallback {
Update-WindowsInstallation;
};
if ((Get-WURebootStatus -Silent)) {
Restart-Intermediate;
return;
}
switch (Get-Stage) { switch (Get-Stage) {
$null { ([SetupStage]::Install) {
} }
Default {} Default {}
} }
@ -73,6 +85,7 @@ function Invoke-WindowsInstallation([Context] $context) {
} }
function Start-OldWindowsInstallationScript([Context] $context) { function Start-OldWindowsInstallationScript([Context] $context) {
. "$PSScriptRoot/Upgrade.ps1";
$finished = $false; $finished = $false;
Remove-Item Env:\POSH_THEME -ErrorAction SilentlyContinue; Remove-Item Env:\POSH_THEME -ErrorAction SilentlyContinue;
$configPath = "$PSScriptRoot/../Config"; $configPath = "$PSScriptRoot/../Config";

View file

@ -0,0 +1,34 @@
<#
.SYNOPSIS
Updates the running Windows machine.
#>
function Update-WindowsInstallation {
<#
Runs the Windows update loop.
#>
function Start-UpdateLoop {
Write-Host "Preparing for Windows Update";
$null = Import-Module PSWindowsUpdate;
while (((Get-WindowsUpdate -IgnoreReboot).Count -gt 0)) {
Write-Host "There are updates available.";
Write-Host "Installing updates";
try {
$null = Install-WindowsUpdate -AcceptAll -IgnoreReboot -ErrorAction "SilentlyContinue";
}
catch { }
if ((Get-WURebootStatus -Silent)) {
Write-Information "A Reboot is Required!";
Write-Information "Windows will reboot now and the installation will be continued automatically.";
return;
}
} else {
Write-Information "Upgrading Windows finished successfully!";
return;
}
}
Start-UpdateLoop;
}