From 52834fcd92dd48830ce26af5c710341894ca0527 Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Wed, 21 Jun 2023 22:04:18 +0200 Subject: [PATCH] Rearrange installation scripts --- scripts/Windows/OS/Install.ps1 | 8 ++++++-- scripts/Windows/OS/Setup.ps1 | 25 ------------------------- scripts/Windows/OS/Upgrade.ps1 | 20 ++++++++++++++++++++ scripts/Windows/Scripts/Context.ps1 | 1 + 4 files changed, 27 insertions(+), 27 deletions(-) delete mode 100644 scripts/Windows/OS/Setup.ps1 create mode 100644 scripts/Windows/OS/Upgrade.ps1 diff --git a/scripts/Windows/OS/Install.ps1 b/scripts/Windows/OS/Install.ps1 index 5c4ca19e..cadb2d2b 100644 --- a/scripts/Windows/OS/Install.ps1 +++ b/scripts/Windows/OS/Install.ps1 @@ -1,4 +1,8 @@ . "$PSScriptRoot/Manage.ps1"; -$context = [Context]::new(); -Invoke-WindowsRestore $context; +function Invoke-WindowsInstallation([Context] $context) +{ + . "$PSScriptRoot/../Scripts/Prerequisites.ps1"; + Invoke-Upgrade $context; + Invoke-WindowsRestore $context; +} diff --git a/scripts/Windows/OS/Setup.ps1 b/scripts/Windows/OS/Setup.ps1 deleted file mode 100644 index b522c5ca..00000000 --- a/scripts/Windows/OS/Setup.ps1 +++ /dev/null @@ -1,25 +0,0 @@ -Import-Module PSWindowsUpdate; -Import-Module ScheduledTasks; - -$installerPath = "$PSScriptRoot/Install.ps1"; -$setupPath = "$($MyInvocation.MyCommand.Path)"; - -Install-WindowsUpdate -AcceptAll -IgnoreReboot; - -if ((Get-WindowsUpdate).Count -gt 0) -{ - $nextScript = "$setupPath"; -} -else -{ - $nextScript = "$installerPath"; -} - -if ((Get-WURebootStatus).RebootRequired) -{ - New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\RunOnce" -Name "PortValhalla" -Value "pwsh `"$nextScript`"" -PropertyType ExpandString; -} -else -{ - . "$nextScript"; -} diff --git a/scripts/Windows/OS/Upgrade.ps1 b/scripts/Windows/OS/Upgrade.ps1 new file mode 100644 index 00000000..cdfae50c --- /dev/null +++ b/scripts/Windows/OS/Upgrade.ps1 @@ -0,0 +1,20 @@ +function Invoke-Upgrade([Context] $context) +{ + $null = Import-Module PSWindowsUpdate; + $null = Install-WindowsUpdate -AcceptAll -IgnoreReboot; + + if ((Get-WURebootStatus).RebootRequired) + { + $null = New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\RunOnce" -Name "PortValhalla" -Value "pwsh `"$($context.EntryPoint)`"" -PropertyType ExpandString; + exit; + } + elseif ((Get-WindowsUpdate).Count -gt 0) + { + $null = Invoke-Upgrade $context; + return; + } + else + { + return; + } +} diff --git a/scripts/Windows/Scripts/Context.ps1 b/scripts/Windows/Scripts/Context.ps1 index f496bffb..413d8595 100644 --- a/scripts/Windows/Scripts/Context.ps1 +++ b/scripts/Windows/Scripts/Context.ps1 @@ -1,4 +1,5 @@ class Context { + [string]$EntryPoint; [string]$RootDir; [string]$BackupName; [string] BackupRoot() {