From 372ff26ded5bf0a6c2930b6d9a3c881ff2651730 Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Wed, 21 Aug 2024 23:21:32 +0200 Subject: [PATCH] Execute the entire installer using live scripts --- scripts/Windows/OS/Install.ps1 | 127 +++++++++++++++++---------------- 1 file changed, 66 insertions(+), 61 deletions(-) diff --git a/scripts/Windows/OS/Install.ps1 b/scripts/Windows/OS/Install.ps1 index b4d05946..f8def2ff 100644 --- a/scripts/Windows/OS/Install.ps1 +++ b/scripts/Windows/OS/Install.ps1 @@ -46,6 +46,68 @@ $null = New-Module { break; } ([SetupStage]::Initialize) { + if (-not ((Test-Command "choco") -and (Test-Command "refreshenv"))) { + Invoke-Hook "Install-Chocolatey" -Fallback { + # Install chocolatey + [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; + Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')); + Import-Module $env:ChocolateyInstall/helpers/chocolateyProfile.psm1; + refreshenv; + }; + + continue; + } + + + if (-not (Test-ChocoPackage "powershell-core")) { + Invoke-Hook "Install-PowerShellCore" -Fallback { + choco install -y powershell-core --install-arguments='"ADD_FILE_CONTEXT_MENU_RUNPOWERSHELL=1 ADD_EXPLORER_CONTEXT_MENU_OPENPOWERSHELL=1 REGISTER_MANIFEST=1 USER_MU=1 ENABLE_MU=1"'; + }; + + Restart-Intermediate; + return; + } + + if ($env:PWSH_PATH -and (Test-Path $env:PWSH_PATH)) { + attrib "-R" "$env:PWSH_PATH\*" /S /D; + Remove-Item -Recurse -Force $env:PWSH_PATH; + continue; + } + + if ($env:DEBUG) { + if ( + (Get-Item $env:INSTALLER_SCRIPT).IsReadOnly -and + (Test-Qemu) -and + ($Host.UI.PromptForChoice( + "Confirm", + "Do you wish to swap to live scripts?", + [ChoiceDescription[]]@( + [ChoiceDescription]::new("&No", "Use scripts stored in the virtual machine"), + [ChoiceDescription]::new("&Yes", "Use live scripts stored on the host")), + 0) -eq 1)) { + Install-ChocoPackage winfsp qemu-guest-agent; + Get-Service VirtioFsSvc | Start-Service -PassThru | Set-Service -StartupType Automatic; + + while (-not (Test-Path Z:\)) { + Start-Sleep 0.1; + } + + foreach ($name in @("CONFIG_MODULE", "INSTALLER_SCRIPT")) { + $variable = Get-Item "Env:\$name"; + + $path = Join-Path ` + "Z:\Repositories\PortValhalla" ` + ([System.IO.Path]::GetRelativePath("$PSScriptRoot/../../..", $variable.Value)); + + Set-Item "Env:\$name" $path; + Write-Host "The new value of ``$name`` is ``$path``"; + } + + Restart-Intermediate; + exit; + } + } + if ($env:DEBUG) { & { $sys32 = "$env:WINDIR/System32"; @@ -60,18 +122,6 @@ $null = New-Module { }; } - if (-not ((Test-Command "choco") -and (Test-Command "refreshenv"))) { - Invoke-Hook "Install-Chocolatey" -Fallback { - # Install chocolatey - [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; - Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')); - Import-Module $env:ChocolateyInstall/helpers/chocolateyProfile.psm1; - refreshenv; - }; - - continue; - } - if (-not (Test-Command "gsudo")) { Install-ChocoPackage gsudo; refreshenv; @@ -84,51 +134,6 @@ $null = New-Module { continue; } - if (-not (Test-ChocoPackage "powershell-core")) { - Invoke-Hook "Install-PowerShellCore" -Fallback { - choco install -y powershell-core --install-arguments='"ADD_FILE_CONTEXT_MENU_RUNPOWERSHELL=1 ADD_EXPLORER_CONTEXT_MENU_OPENPOWERSHELL=1 REGISTER_MANIFEST=1 USER_MU=1 ENABLE_MU=1"'; - }; - - if ($env:DEBUG) { - if ( - (Test-Qemu) -and - ($Host.UI.PromptForChoice( - "Confirm", - "Do you wish to swap to live scripts?", - [ChoiceDescription[]]@( - [ChoiceDescription]::new("&No", "Use scripts stored in the virtual machine"), - [ChoiceDescription]::new("&Yes", "Use live scripts stored on the host")), - 0) -eq 1)) { - Install-ChocoPackage winfsp qemu-guest-agent; - Get-Service VirtioFsSvc | Start-Service -PassThru | Set-Service -StartupType Automatic; - - while (-not (Test-Path Z:\)) { - Start-Sleep 0.1; - } - - foreach ($name in @("CONFIG_MODULE", "INSTALLER_SCRIPT")) { - $variable = Get-Item "Env:\$name"; - - $path = Join-Path ` - "Z:\Repositories\PortValhalla" ` - ([System.IO.Path]::GetRelativePath("$PSScriptRoot/../../..", $variable.Value)); - - Set-Item "Env:\$name" $path; - Write-Host "The new value of ``$name`` is ``$path``"; - } - } - } - - Restart-Intermediate; - return; - } - - if ($env:PWSH_PATH -and (Test-Path $env:PWSH_PATH)) { - attrib "-R" "$env:PWSH_PATH\*" /S /D; - Remove-Item -Recurse -Force $env:PWSH_PATH; - continue; - } - if (-not (Test-Winget)) { . "$PSScriptRoot/../Software/winget/Manage.ps1"; continue; @@ -593,13 +598,13 @@ $null = New-Module { foreach ($group in Get-UserConfig -UserName $name "groups") { Add-LocalGroupMember -Member $name -Name "$group"; } + + if (-not $msAccount) { + net user $name /logonpasswordchg:yes; + } } } } - - if (-not $msAccount) { - net user $name /logonpasswordchg:yes; - } } Set-IsFinished $true;