-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.ps1
68 lines (55 loc) · 2.16 KB
/
install.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
$wslInstallDir = "$(Get-Content env:USERPROFILE)\wsl"
$wslImage = "devbox-fedora-wsl.tar"
#########
# Check if running as administrator
function Get-ScriptDirectory
{
$Invocation = (Get-Variable MyInvocation -Scope 1).Value
Split-Path $Invocation.MyCommand.Path
}
if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
# Relaunch as an admin
#$CommandLine = "-File `"" + $MyInvocation.MyCommand.Path + "`" " + $MyInvocation.UnboundArguments
#Start-Process -FilePath PowerShell.exe -WorkingDirectory $(Get-ScriptDirectory) -Verb Runas -ArgumentList $CommandLine
Write-Host "please run with UAC rights."
exit
}
$console = ([console]::OutputEncoding)
[console]::OutputEncoding = New-Object System.Text.UnicodeEncoding
$wslList = (wsl.exe --list)
[console]::OutputEncoding = $console
if ($wslList -match 'wsl-data') {
Write-Host "WSL data for /home already exists."
} else {
Write-Host "WSL data for /home does not exist. And must be created."
Write-Host "Creating wsl-data distribution from wsl-data.tar"
$importPath = "$wslInstallDir/wsl-data"
Write-Host "wsl path $importPath"
wsl.exe --import wsl-data $importPath "./wsl-data.tar"
}
try {
# Prompt the user for the WSL name
Write-Host "New WSL distribution will be installed."
$wslName = Read-Host -Prompt "Please enter the wanted WSL name"
# Check if the user provided a name
if (-not $wslName) {
Write-Output "No WSL name provided. Exiting..."
exit
}
Write-Output "installing as: $wslName"
$importPath = "$wslInstallDir\$wslName"
Write-Host "wsl path $importPath"
wsl.exe --unregister $wslName
wsl.exe --import $wslName $importPath "$(Get-ScriptDirectory)/$wslImage"
wsl.exe -d $wslName
wsl.exe -t $wslName
Write-Host "Setup complete."
Write-Host "Please note that the zsh installation might download a few extra script on first start."
Write-Host "After download you have to exit ones more."
Write-Host ""
Write-Host "Enjoy!"
pause
} catch {
Write-Output "An error occurred: $_"
pause
}