Initialize operation for all users

This commit is contained in:
Manuel Thalmann 2024-08-27 04:24:29 +02:00
parent ab9b8fb798
commit 4a189b297a
4 changed files with 24 additions and 10 deletions

View file

@ -4,7 +4,6 @@ using namespace System.Security.Principal;
enum SetupStage {
Idle
Initialize
OneShot
Configure
Install

View file

@ -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;
}
}
}

View file

@ -39,11 +39,11 @@ $null = New-Module {
function Start-InstallationLoop {
while (-not (Get-IsFinished)) {
switch (Get-Stage) {
($null) {
Set-Stage ([SetupStage]::Configure);
break;
}
default {
if (-not (Test-Wsl)) {
Register-WslDistribution;
}
switch ($_) {
([SetupStage]::OneShot) {
Write-Host "Running OneShot task ``$(Get-OneShotTask)``";

View file

@ -55,6 +55,12 @@ 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;
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 +70,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;
}
}
<#