From 6b35ce6f39bffe32dc558baee0b09e6b182c8969 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 afabab06..ac4de18b 100644 --- a/scripts/Windows/OS/Install.ps1 +++ b/scripts/Windows/OS/Install.ps1 @@ -49,6 +49,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"; @@ -63,18 +125,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; @@ -87,51 +137,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; @@ -596,13 +601,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;