From a5f1f06ca0fe00f433f075d216ed3d3f4f91afe2 Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Sat, 24 Aug 2024 16:15:10 +0200 Subject: [PATCH] Remove unused resources after user setup --- scripts/Common/Scripts/Config.ps1 | 1 + scripts/Windows/OS/Install.ps1 | 20 +++++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/scripts/Common/Scripts/Config.ps1 b/scripts/Common/Scripts/Config.ps1 index cc412f36..7c0dd078 100644 --- a/scripts/Common/Scripts/Config.ps1 +++ b/scripts/Common/Scripts/Config.ps1 @@ -14,6 +14,7 @@ enum SetupStage { enum UserStage { Create Configure + Cleanup Completed } diff --git a/scripts/Windows/OS/Install.ps1 b/scripts/Windows/OS/Install.ps1 index 887dc74f..fb49057f 100644 --- a/scripts/Windows/OS/Install.ps1 +++ b/scripts/Windows/OS/Install.ps1 @@ -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; } } }