Remove unused resources after user setup

This commit is contained in:
Manuel Thalmann 2024-08-24 16:15:10 +02:00
parent 8e97e7f54b
commit 70f34d2685
2 changed files with 18 additions and 3 deletions

View file

@ -14,6 +14,7 @@ enum SetupStage {
enum UserStage {
Create
Configure
Cleanup
Completed
}

View file

@ -37,7 +37,9 @@ $null = New-Module {
Starts the installation loop.
#>
function Start-InstallationLoop {
$wslLocation = "$env:ProgramData\PortValhalla\Ubuntu";
$distribution = "PortValhalla";
$wslLocation = "$env:ProgramData/PortValhalla/Ubuntu";
$wslDisk = "$wslLocation/ext4.vhdx";
while (-not (Get-IsFinished)) {
switch (Get-Stage) {
@ -195,8 +197,8 @@ $null = New-Module {
}
default {
if (-not (& { $null = wsl -l; $? })) {
wsl --import-in-place "PortValhalla" "$wslLocation/ext4.vhdx";
wsl --set-default "PortValhalla";
wsl --import-in-place $distribution "$wslDisk";
wsl --set-default $distribution;
}
switch ($_) {
@ -614,7 +616,19 @@ $null = New-Module {
net user $name /logonpasswordchg:yes;
}
Set-UserStage ([UserStage]::Cleanup);
}
([UserStage]::Cleanup) {
$user = Get-SetupUser;
Enable-LocalUser $user;
Set-AutologinUser $user;
wsl --shutdown;
$tempDisk = Rename-Item -Force $wslDisk "ext4_.vhdx" -PassThru;
wsl --unregister $distribution;
Move-Item $tempDisk $wslDisk;
Set-UserStage ([UserStage]::Completed);
Restart-Intermediate;
exit;
}
}
}