Add scripts for updating windows

This commit is contained in:
Manuel Thalmann 2024-08-01 02:59:32 +02:00
parent 5bb0cd41cc
commit a6985d7e1b
2 changed files with 58 additions and 11 deletions

View file

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