/
BackEnd-InstallWSL.ps1
85 lines (69 loc) · 2.77 KB
/
BackEnd-InstallWSL.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
Set-ExecutionPolicy Bypass -Scope Process -Force
function WriteTimestampedMessage {
param (
[string]$message
)
$currentTime = Get-Date
Write-Host "$message at $($currentTime.ToLongTimeString())"
}
function EnsureDirectory {
param (
[string]$path
)
if (-not (Test-Path $path)) {
New-Item -Path $path -ItemType Directory | Out-Null
}
}
function DownloadScript {
param (
[string]$uri,
[string]$destinationPath
)
Invoke-WebRequest -Uri $uri -OutFile $destinationPath
}
# Main Script Execution
WriteTimestampedMessage "Starting WSL Ubuntu installation"
$automaticInstall = $true
$wslRootPath = "c:\WSL2"
$wslTempPath = Join-Path $wslRootPath "temp"
$wslStagingPath = Join-Path $wslTempPath "staging"
$wslScriptsPath = Join-Path $wslRootPath "scripts"
Write-Host "Creating Directories"
EnsureDirectory $wslRootPath
EnsureDirectory $wslTempPath
EnsureDirectory $wslStagingPath
EnsureDirectory $wslScriptsPath
Write-Host "Directories Created"
$wslInstalled = (Get-Command wsl.exe -ErrorAction SilentlyContinue) -ne $null
if ($wslInstalled) {
Write-Host "WSL is Installed"
} else {
Write-Error "WSL not detected! WSL is needed to install."
exit 1
}
Write-Host "Downloading Scripts"
DownloadScript "https://raw.githubusercontent.com/Evilazaro/MicrosoftDevBox/main/Deploy/ARMTemplates/computeGallery/createUser.sh" (Join-Path $wslScriptsPath "createUser.sh")
DownloadScript "https://raw.githubusercontent.com/Evilazaro/MicrosoftDevBox/main/Deploy/ARMTemplates/computeGallery/installUtils.sh" (Join-Path $wslScriptsPath "installUtils.sh")
Write-Host "Scripts downloaded to $wslScriptsPath"
if ($automaticInstall) {
$wslName = 'Ubuntu'
$wslInstallationPath = "C:\Users\Default\AppData\Local\WSL2\$wslName"
$wslUsername = "vmadmin"
WriteTimestampedMessage "Installing Ubuntu"
wsl --install -d Ubuntu -u root -y
WriteTimestampedMessage "Ubuntu installed successfully"
# Commented out sections can be uncommented if needed.
# WriteTimestampedMessage "Creating Ubuntu User"
# wsl -d $wslName -u root bash -ic "/mnt/c/WSL2/scripts/createUser.sh $wslUsername ubuntu"
# WriteTimestampedMessage "Ubuntu User Created"
# WriteTimestampedMessage "Updating Ubuntu User"
# wsl -d $wslName -u root bash -ic "/mnt/c/temp/configureUbuntuFrontEnd.sh"
# wsl -d $wslName -u root bash -ic "DEBIAN_FRONTEND=noninteractive /mnt/c/temp/updateUbuntu.sh"
# WriteTimestampedMessage "Ubuntu Updated"
# Write-Host "Restarting WSL Distro"
# wsl -t $wslName
# Write-Host "WSL Distro Restarted"
WriteTimestampedMessage "Finishing WSL Ubuntu installation"
} else {
Add-AppxPackage $packageArgs.fileFullPath
}