bugfix(vim-shfmt): fix package name
[webi-installers/.git] / wsl2 / install.ps1
1 #!/usr/bin/env pwsh
2
3 echo "Installing WSL 2 (Windows Subsystem for Linux with Hyper-V) ..."
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 $MYPWD = (Get-Item .).FullName
10 & curl.exe -fA "MS" -o "$Env:TEMP\install-wsl2.ps1" "$Env:WEBI_HOST/packages/wsl2/install-wsl2.ps1"
11 powershell -Command "Start-Process cmd -Wait -Verb RunAs -ArgumentList '/c cd /d %CD% && powershell -ExecutionPolicy Bypass $Env:TEMP\install-wsl2.ps1'"
12
13 # From https://devblogs.microsoft.com/scripting/use-a-powershell-function-to-see-if-a-command-exists/
14 Function Test-CommandExists
15 {
16     Param ($command)
17     $oldPreference = $ErrorActionPreference
18     $ErrorActionPreference = 'stop'
19     try {if(Get-Command $command){RETURN $true}}
20     Catch {RETURN $false}
21     Finally {$ErrorActionPreference=$oldPreference}
22 }
23
24 IF(!(Test-CommandExists wsl))
25 {
26     echo ""
27     echo ""
28     echo ""
29     echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
30     echo "!!!                          !!!"
31     echo "!!!      READ CAREFULLY      !!!"
32     echo "!!!                          !!!"
33     echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
34     echo ""
35     echo "WSL 2 was NOT installed yet. You MUST follow these instructions:"
36     echo ""
37     echo "    1. REBOOT you computer to finish the WSL 1 install"
38     echo "       (either click Start Menu => Restart, or run 'shutdown /r /t 5')"
39     echo ""
40     echo "    2. RE-RUN this WSL 2 installer"
41     echo "       (WSL 2 cannot finish installing until the WSL 1 install is complete)"
42     echo ""
43     echo "    3. Download and Install Linux"
44     echo "       (see https://webinstall.dev/wsl2)"
45     echo ""
46
47     Exit
48 }
49
50 echo ""
51 echo ""
52 echo ""
53 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
54 echo "!!!                          !!!"
55 echo "!!!      READ CAREFULLY      !!!"
56 echo "!!!                          !!!"
57 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
58 echo ""
59 echo "WSL 2 is now installed, HOWEVER, you MUST:"
60 echo ""
61 echo "However, you still MUST INSTALL LINUX:"
62 echo ""
63 echo "    1. Download and Install Ubuntu Linux"
64 echo "       (see https://webinstall.dev/wsl2)"
65 echo ""
66 echo "    2. Set WSL to use WSL 2 with Hyper-V. For example:"
67 echo "       wsl.exe --set-version Ubuntu-20.04 2"
68 echo "       wsl.exe --set-default-version 2"
69 echo ""