Initialize operation for all users
This commit is contained in:
parent
1b0c715514
commit
3185e67a59
4 changed files with 25 additions and 10 deletions
|
@ -4,7 +4,6 @@ using namespace System.Security.Principal;
|
|||
|
||||
enum SetupStage {
|
||||
Idle
|
||||
Initialize
|
||||
OneShot
|
||||
Configure
|
||||
Install
|
||||
|
|
|
@ -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)) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)``";
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
<#
|
||||
|
|
Loading…
Reference in a new issue