refactor: finish moving ssh-* scripts to own installers
[webi-installers/.git] / wsl / install.ps1
1 #!/usr/bin/env pwsh
2
3 echo "Installing WSL (Windows Subsystem for Linux) ..."
4 echo ""
5 echo "Security: requires administrator approval to install"
6
7 IF ($Env:WEBI_HOST -eq $null -or $Env:WEBI_HOST -eq "") { $Env:WEBI_HOST = "https://webinstall.dev" }
8
9 # From https://devblogs.microsoft.com/scripting/use-a-powershell-function-to-see-if-a-command-exists/
10 Function Test-CommandExists
11 {
12     Param ($command)
13     $oldPreference = $ErrorActionPreference
14     $ErrorActionPreference = 'stop'
15     try {if(Get-Command $command){RETURN $true}}
16     Catch {RETURN $false}
17     Finally {$ErrorActionPreference=$oldPreference}
18 }
19
20
21 # $MYPWD = (Get-Item .).FullName
22 & curl.exe -fsSA "MS" -o "$Env:TEMP\install-wsl2.ps1" "$Env:WEBI_HOST/packages/wsl/install-wsl.ps1"
23 powershell -Command "Start-Process cmd -Wait -Verb RunAs -ArgumentList '/c cd /d %CD% && powershell -ExecutionPolicy Bypass $Env:TEMP\install-wsl2.ps1'"
24
25 IF(!(Test-CommandExists wsl))
26 {
27     echo "Warning: Skipping 3 of 5: Reboot Required to install WSL 2 !!"
28 }
29
30 echo ""
31 IF ((Test-Path -Path "$Env:UserProfile\Downloads\webi\Ubuntu_2004_x64.appx" )) {
32     echo "Skipping 4 of 5: Ubuntu Linux 20.04 already installed"
33 } ELSE {
34     echo "Installing 4 of 5 Ubuntu Linux 20.04 (for WSL 1 and WSL 2) ..."
35     curl.exe -fL -o "$Env:UserProfile\Downloads\webi\Ubuntu_2004_x64.appx.part" https://aka.ms/wslubuntu2004
36     & move "$Env:UserProfile\Downloads\webi\Ubuntu_2004_x64.appx.part" "$Env:UserProfile\Downloads\webi\Ubuntu_2004_x64.appx"
37     Add-AppxPackage "$Env:UserProfile\Downloads\webi\Ubuntu_2004_x64.appx"
38 }
39
40 echo ""
41 echo ""
42 echo ""
43 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
44 echo "!!!                           !!!"
45 echo "!!!      ACTION REQUIRED      !!!"
46 echo "!!!      READ CAREFULLY!      !!!"
47 echo "!!!                           !!!"
48 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
49
50 IF(!(Test-CommandExists wsl))
51 {
52     echo ""
53     echo "WSL 2 was NOT installed yet. FOLLOW these instructions:"
54     echo ""
55     echo "    1. REBOOT you computer to finish the WSL 1 install"
56     echo "       (either click Start Menu => Restart, or run 'shutdown /r /t 5')"
57     echo ""
58     echo "    2. RE-RUN this WSL 2 installer"
59     echo "       (WSL 2 cannot finish installing until the WSL 1 install is complete)"
60     echo ""
61     echo "    3. WSL 2 must be enabled manually. See https://webinstall.dev/wsl2"
62     echo ""
63
64     Exit
65 }
66
67 echo ""
68 echo "You must ALSO run UBUNTU LINUX from the START MENU to complete the install."
69 echo ""
70 echo "    -  Select Ubuntu Linux from the Search menu or Start Menu"
71 echo "    -  Wait for the initialization to complete"
72 echo "    -  Choose a username (we recommend 'app') and a password"
73 echo ""