From ab490a401dbe272d24dbd0274ac2f59a10a85831 Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Fri, 16 Aug 2024 15:21:41 +0200 Subject: [PATCH] Allow running live scripts in debug mode --- scripts/Common/Scripts/Config.ps1 | 8 ++++++++ scripts/Windows/OS/Install.ps1 | 33 ++++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) 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 f0da07ee..34697e60 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/Windows/Scripts/Prerequisites.ps1"; @@ -73,7 +74,37 @@ $null = New-Module { 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; }