Allow running live scripts in debug mode

This commit is contained in:
Manuel Thalmann 2024-08-16 15:21:41 +02:00
parent 5d37181875
commit ab490a401d
2 changed files with 40 additions and 1 deletions

View file

@ -280,6 +280,14 @@ $null = New-Module {
Get-Config "valhalla.software.$Name"; 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 .SYNOPSIS
Checks whether the current user is the setup user. Checks whether the current user is the setup user.

View file

@ -1,4 +1,5 @@
#!/bin/pwsh #!/bin/pwsh
using namespace System.Management.Automation.Host;
using namespace System.Security.Principal; using namespace System.Security.Principal;
. "$PSScriptRoot/../../../scripts/Windows/Scripts/Prerequisites.ps1"; . "$PSScriptRoot/../../../scripts/Windows/Scripts/Prerequisites.ps1";
@ -73,7 +74,37 @@ $null = New-Module {
Invoke-Hook "Install-PowerShellCore" -Fallback { 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"'; 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; Restart-Intermediate;
return; return;
} }