Remove WSL after operation

This commit is contained in:
Manuel Thalmann 2024-08-24 16:52:41 +02:00
parent 14dc6e5c28
commit 7eb0c61cf6
3 changed files with 29 additions and 2 deletions
scripts/Common/Scripts

View file

@ -0,0 +1,7 @@
<#
.SYNOPSIS
Gets the name of the WSL distribution used for reading configuration values.
#>
function Get-DistributionName {
return "ValhallaUbuntu";
}

View file

@ -1,4 +1,5 @@
. "$PSScriptRoot/Config.ps1";
. "$PSScriptRoot/Constants.ps1";
. "$PSScriptRoot/../Types/OneShotTask.ps1";
. "$PSScriptRoot/../../Windows/Scripts/PowerManagement.ps1";
. "$PSScriptRoot/../../Windows/Scripts/Registry.ps1";
@ -25,9 +26,12 @@ $null = New-Module {
function Start-Operation {
param(
[switch] $NonInteractive,
[switch] $NoImplicitCleanup,
[scriptblock] $Action
)
$cleanup = { };
if (-not $Global:InOperation) {
if ($env:DEBUG) {
Set-PSDebug -Trace 1;
@ -46,9 +50,16 @@ $null = New-Module {
}
New-Alias -Force "sudo" gsudo;
if (-not $NoImplicitCleanup.IsPresent) {
$cleanup = {
Clear-OperationResources;
};
}
}
& $Action;
& $cleanup;
}
<#
@ -174,4 +185,12 @@ $null = New-Module {
Write-EventLog -LogName $logName -Source $logName -EventId $oneShotTrigger -Message "The OneShot task ``$(Get-OneShotTask)`` finished.";
}
}
<#
.SYNOPSIS
Clears resources allocated during the operation.
#>
function Clear-OperationResources {
wsl --unregister (Get-DistributionName);
}
};