Remove WSL after operation
This commit is contained in:
parent
14dc6e5c28
commit
7eb0c61cf6
3 changed files with 29 additions and 2 deletions
7
scripts/Common/Scripts/Constants.ps1
Normal file
7
scripts/Common/Scripts/Constants.ps1
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
<#
|
||||||
|
.SYNOPSIS
|
||||||
|
Gets the name of the WSL distribution used for reading configuration values.
|
||||||
|
#>
|
||||||
|
function Get-DistributionName {
|
||||||
|
return "ValhallaUbuntu";
|
||||||
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
. "$PSScriptRoot/Config.ps1";
|
. "$PSScriptRoot/Config.ps1";
|
||||||
|
. "$PSScriptRoot/Constants.ps1";
|
||||||
. "$PSScriptRoot/../Types/OneShotTask.ps1";
|
. "$PSScriptRoot/../Types/OneShotTask.ps1";
|
||||||
. "$PSScriptRoot/../../Windows/Scripts/PowerManagement.ps1";
|
. "$PSScriptRoot/../../Windows/Scripts/PowerManagement.ps1";
|
||||||
. "$PSScriptRoot/../../Windows/Scripts/Registry.ps1";
|
. "$PSScriptRoot/../../Windows/Scripts/Registry.ps1";
|
||||||
|
@ -25,9 +26,12 @@ $null = New-Module {
|
||||||
function Start-Operation {
|
function Start-Operation {
|
||||||
param(
|
param(
|
||||||
[switch] $NonInteractive,
|
[switch] $NonInteractive,
|
||||||
|
[switch] $NoImplicitCleanup,
|
||||||
[scriptblock] $Action
|
[scriptblock] $Action
|
||||||
)
|
)
|
||||||
|
|
||||||
|
$cleanup = { };
|
||||||
|
|
||||||
if (-not $Global:InOperation) {
|
if (-not $Global:InOperation) {
|
||||||
if ($env:DEBUG) {
|
if ($env:DEBUG) {
|
||||||
Set-PSDebug -Trace 1;
|
Set-PSDebug -Trace 1;
|
||||||
|
@ -46,9 +50,16 @@ $null = New-Module {
|
||||||
}
|
}
|
||||||
|
|
||||||
New-Alias -Force "sudo" gsudo;
|
New-Alias -Force "sudo" gsudo;
|
||||||
|
|
||||||
|
if (-not $NoImplicitCleanup.IsPresent) {
|
||||||
|
$cleanup = {
|
||||||
|
Clear-OperationResources;
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
& $Action;
|
& $Action;
|
||||||
|
& $cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
<#
|
<#
|
||||||
|
@ -174,4 +185,12 @@ $null = New-Module {
|
||||||
Write-EventLog -LogName $logName -Source $logName -EventId $oneShotTrigger -Message "The OneShot task ``$(Get-OneShotTask)`` finished.";
|
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);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -18,6 +18,7 @@ $null = New-Module {
|
||||||
. "$PSScriptRoot/../Scripts/Security.ps1";
|
. "$PSScriptRoot/../Scripts/Security.ps1";
|
||||||
. "$PSScriptRoot/../Scripts/Update.ps1";
|
. "$PSScriptRoot/../Scripts/Update.ps1";
|
||||||
. "$PSScriptRoot/../Scripts/Users.ps1";
|
. "$PSScriptRoot/../Scripts/Users.ps1";
|
||||||
|
. "$PSScriptRoot/../../Common/Scripts/Constants.ps1";
|
||||||
. "$PSScriptRoot/../../Common/Scripts/Config.ps1";
|
. "$PSScriptRoot/../../Common/Scripts/Config.ps1";
|
||||||
. "$PSScriptRoot/../../Common/Scripts/Operations.ps1";
|
. "$PSScriptRoot/../../Common/Scripts/Operations.ps1";
|
||||||
. "$PSScriptRoot/../../Common/Scripts/Software.ps1";
|
. "$PSScriptRoot/../../Common/Scripts/Software.ps1";
|
||||||
|
@ -30,7 +31,7 @@ $null = New-Module {
|
||||||
Finishes the installation of a running Windows machine.
|
Finishes the installation of a running Windows machine.
|
||||||
#>
|
#>
|
||||||
function Start-WindowsInstallation {
|
function Start-WindowsInstallation {
|
||||||
Start-Operation {
|
Start-Operation -NoImplicitCleanup {
|
||||||
Start-InstallationLoop;
|
Start-InstallationLoop;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -40,7 +41,7 @@ $null = New-Module {
|
||||||
Starts the installation loop.
|
Starts the installation loop.
|
||||||
#>
|
#>
|
||||||
function Start-InstallationLoop {
|
function Start-InstallationLoop {
|
||||||
$distribution = "ValhallaUbuntu";
|
$distribution = Get-DistributionName;
|
||||||
$wslLocation = "$env:ProgramData/PortValhalla/$distribution";
|
$wslLocation = "$env:ProgramData/PortValhalla/$distribution";
|
||||||
$wslDisk = "$wslLocation/ext4.vhdx";
|
$wslDisk = "$wslLocation/ext4.vhdx";
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue