-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbootstrap.ps1
46 lines (34 loc) · 1.66 KB
/
bootstrap.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
$dist = "ubuntu-wpaas-noble"
$rootfs = "$dist-rootfs.tar.gz"
try {
if (-not(Test-Path $rootfs)) {
$url = (("https://cloud-images.ubuntu.com",
"wsl/noble/current",
"ubuntu-noble-wsl-amd64-ubuntu24.04lts.rootfs.tar.gz") -join "/")
Write-Output "Downloading ubuntu cloud image from $url ...please be patient"
Start-BitsTransfer -Source $url -Destination $rootfs
}
wsl --set-default-version 2
wsl --import $dist (($HOME, $dist) -join "\") .\$rootfs
$user = Read-Host -Prompt "Enter your linux username"
wsl -d $dist -- useradd -u 1000 -m -G sudo -s /bin/bash $user
wsl -d $dist -- passwd $user
$key = "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Lxss"
Get-ChildItem -Path $key | ForEach-Object {
$distributionName = (Get-ItemProperty -Path $_.PsPath).DistributionName
if ($distributionName -eq $dist) {
Set-ItemProperty -Path $_.PsPath -Name DefaultUid -Value 1000 -Type DWORD
Write-Output "DefaultUid value set to 1000 for $($_.Name)"
}
}
wsl -d $dist -u $user --cd ~ -- curl --insecure -L https://github.com/swisstxt/wpaas-wsl-ubuntu/archive/refs/heads/master.tar.gz -o install.tar.gz
wsl -d $dist -u $user --cd ~ -- mkdir ~/installer
wsl -d $dist -u $user --cd ~ -- tar xvzf install.tar.gz -C installer --strip-components=1
wsl -d $dist -u $user --cd ~/installer -- bash install.sh
wsl --terminate $dist
wsl -d $dist -u $user --cd ~/installer -- bash post_install.sh
} catch {
Write-Output "$($_.ScriptStackTrace)"
Write-Output "failed to setup WSL: $($_.Exception.Message)"
exit 1
}