Install Ubuntu automatically

This commit is contained in:
Manuel Thalmann 2024-09-03 12:08:14 +02:00
parent 4f5c39df66
commit 86a3f87f70

View file

@ -63,8 +63,14 @@ function Install-Wsl {
function Install-WslDistribution {
$dir = Get-WslDistributionPath;
$root = Split-Path -Parent $dir;
$ubuntuPattern = "*Ubuntu*";
$registryPath = "HKCU:/Software/Microsoft/Windows/CurrentVersion/Lxss";
$key = Get-Item $registryPath;
if (-not (Get-AppxPackage $ubuntuPattern)) {
Install-Wsl;
}
wsl --shutdown;
if ($key) {
@ -75,7 +81,7 @@ function Install-WslDistribution {
$null = New-Item -ItemType Directory $root;
}
Copy-Item -Recurse -Force (Get-AppxPackage "*Ubuntu*").InstallLocation $dir;
Copy-Item -Recurse -Force (Get-AppxPackage $ubuntuPattern).InstallLocation $dir;
Set-UserPermissions $dir;
& "$dir\ubuntu.exe" install --root;
wsl --shutdown;