Remove unused resources after user setup

This commit is contained in:
Manuel Thalmann 2024-08-24 16:15:10 +02:00
parent 4608c4748c
commit a5f1f06ca0
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

@ -40,7 +40,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) {
@ -198,8 +200,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 ($_) {
@ -617,7 +619,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;
}
}
}