-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap_wsl.ps1
67 lines (49 loc) · 1.96 KB
/
bootstrap_wsl.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
Param (
[Parameter(Mandatory=$True)][ValidateNotNull()][string]$wslName,
[Parameter(Mandatory=$True)][ValidateNotNull()][string]$username,
[Parameter(Mandatory=$True)][ValidateNotNull()][string]$reinstallWSL,
[Parameter(Mandatory=$True)][ValidateNotNull()][string]$installAllSoftware
)
Write-Output "Clean up installed $wslName distro"
wsl.exe --terminate $wslName
wsl.exe --unregister $wslName
if ($reinstallWSL -ieq "true") {
# Preparing WSL
Write-Output "Uninstalling WSL2"
wsl.exe --uninstall
Write-Output "Installing WSL2"
wsl.exe --install --inbox
wsl.exe --install
wsl.exe --update
Write-Output "Setting WSL2 as default"
wsl.exe --set-default-version 2
}
# create staging directory if it does not exists
if (-Not (Test-Path -Path .\staging)) {
mkdir .\staging
}
write-output "Downloading Debian"
curl.exe -L -o .\staging\Debian.appx https://aka.ms/wsl-debian-gnulinux
Write-Output "Installing Debian"
Move-Item .\staging\Debian.appx .\staging\$wslName.zip
Expand-Archive .\staging\$wslName.zip .\staging\$wslName
Move-Item .\staging\$wslName\DistroLauncher-*_x64.appx .\staging\$wslName\x64.zip
Expand-Archive .\staging\$wslName\x64.zip .\staging\$wslName\x64
if (-Not (Test-Path -Path C:\dev\WSL)) {
mkdir C:\dev\WSL
}
if (-Not (Test-Path -Path C:\dev\WSL\$wslName)) {
mkdir C:\dev\WSL\$wslName
}
wsl.exe --import $wslName C:\dev\WSL\$wslName .\staging\$wslName\x64\install.tar.gz
wsl.exe --set-default $wslName
Remove-Item .\staging\$wslName.zip
Remove-Item -r .\staging\$wslName\
Write-Output "Updating Debian"
wsl -d $wslName -u root bash -ic "apt update"
$wslCurrentPath = wsl wslpath ($PSScriptRoot -replace "\\","/")
Write-Output "Installing ansible"
wsl -d $wslName -u root bash -ic 'apt install ansible -y'
wsl -d $wslName -u root bash -ic "ansible-playbook $wslCurrentPath/ansible/playbook1.yml"
wsl -t $wslName
wsl -d $wslName -u root bash -ic "ansible-playbook $wslCurrentPath/ansible/playbook2.yml"