diff --git a/scripts/Common/Scripts/Config.ps1 b/scripts/Common/Scripts/Config.ps1 index f27ac1a1..f028ea2a 100644 --- a/scripts/Common/Scripts/Config.ps1 +++ b/scripts/Common/Scripts/Config.ps1 @@ -280,6 +280,14 @@ $null = New-Module { Get-Config "valhalla.software.$Name"; } + <# + .SYNOPSIS + Checks whether the running system is a QEMU virtual machine. + #> + function Test-Qemu { + ((Get-WmiObject win32_computersystem).Manufacturer) -eq "QEMU"; + } + <# .SYNOPSIS Checks whether the current user is the setup user. diff --git a/scripts/Windows/OS/Install.ps1 b/scripts/Windows/OS/Install.ps1 index 49948a57..3ff67eb2 100644 --- a/scripts/Windows/OS/Install.ps1 +++ b/scripts/Windows/OS/Install.ps1 @@ -1,4 +1,5 @@ #!/bin/pwsh +using namespace System.Management.Automation.Host; using namespace System.Security.Principal; . "$PSScriptRoot/../Scripts/Prerequisites.ps1"; @@ -77,6 +78,36 @@ $null = New-Module { 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; }