diff --git a/scripts/Common/Scripts/Config.ps1 b/scripts/Common/Scripts/Config.ps1 index 7c0dd078..0e4eae53 100644 --- a/scripts/Common/Scripts/Config.ps1 +++ b/scripts/Common/Scripts/Config.ps1 @@ -4,7 +4,6 @@ using namespace System.Security.Principal; enum SetupStage { Idle - Initialize OneShot Configure Install diff --git a/scripts/Common/Scripts/Operations.ps1 b/scripts/Common/Scripts/Operations.ps1 index 89a1b889..be0991cc 100644 --- a/scripts/Common/Scripts/Operations.ps1 +++ b/scripts/Common/Scripts/Operations.ps1 @@ -64,10 +64,10 @@ $null = New-Module { }; } - Set-Stage ((Get-Stage) ?? ([SetupStage]::Initialize)); - & { - while ((Get-Stage) -eq ([SetupStage]::Initialize)) { + $initialized = $false; + + while (-not $initialized) { if ($IsWindows) { if (-not ((Test-Command "choco") -and (Test-Command "refreshenv"))) { Invoke-Hook "Install-Chocolatey" -Fallback { @@ -174,7 +174,11 @@ $null = New-Module { } if (-not (Test-WslDistributions)) { - Install-WslDistribution; + if (-not (Test-Path (Get-WslDistributionDisk))) { + Install-WslDistribution; + } + + Register-WslDistribution; continue; } @@ -219,7 +223,7 @@ $null = New-Module { Install-ChocoPackage selenium-gecko-driver firefox; Install-WingetPackage AutoHotkey.AutoHotkey; - Set-Stage ([SetupStage]::Configure); + $initialized = $true; } } } diff --git a/scripts/Windows/OS/Install.ps1 b/scripts/Windows/OS/Install.ps1 index 26d243e2..9de37dc0 100644 --- a/scripts/Windows/OS/Install.ps1 +++ b/scripts/Windows/OS/Install.ps1 @@ -41,11 +41,11 @@ $null = New-Module { #> function Start-InstallationLoop { while (-not (Get-IsFinished)) { - if (-not (Test-Wsl)) { - Register-WslDistribution; - } - switch (Get-Stage) { + ($null) { + Set-Stage ([SetupStage]::Configure); + break; + } ([SetupStage]::OneShot) { Write-Host "Running OneShot task ``$(Get-OneShotTask)``"; diff --git a/scripts/Windows/Scripts/WSL.ps1 b/scripts/Windows/Scripts/WSL.ps1 index 8f7b3b88..57b5125a 100644 --- a/scripts/Windows/Scripts/WSL.ps1 +++ b/scripts/Windows/Scripts/WSL.ps1 @@ -55,6 +55,13 @@ function Install-Wsl { function Install-WslDistribution { $dir = Get-WslDistributionPath; $root = Split-Path -Parent $dir; + $registryPath = "HKCU:/Software/Microsoft/Windows/CurrentVersion/Lxss"; + $key = Get-Item $registryPath; + wsl --shutdown; + + if ($key) { + $key = $key | Rename-Item -NewName "$(Split-Path -Leaf $key)_" -PassThru; + } if (-not (Test-Path $root)) { $null = New-Item -ItemType Directory $root; @@ -64,6 +71,11 @@ function Install-WslDistribution { Set-UserPermissions $dir; & "$dir\ubuntu.exe" install --root; wsl --shutdown; + Remove-Item -Recurse -Force $registryPath; + + if ($key) { + Move-Item $key.PSPath $registryPath; + } } <#