-
Notifications
You must be signed in to change notification settings - Fork 37
/
elan-init.ps1
89 lines (74 loc) · 2.31 KB
/
elan-init.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
86
87
88
89
<#
.SYNOPSIS
.
.DESCRIPTION
This is just a little script that can be downloaded from the Internet to
install elan. It just does platform detection, downloads the latest
installer, then runs it.
.PARAMETER Verbose
Produce verbose output about the elan installation process.
.PARAMETER NoPrompt
Do not present elan installation menu of choices.
.PARAMETER NoModifyPath
Do not modify PATH environment variable.
.PARAMETER DefaultToolchain
Which tool chain to setup as your default toolchain, or specify 'none'
.PARAMETER ElanRoot
Where to find the elan-init tool, default is https://github.com/leanprover/elan/releases
.PARAMETER ElanVersion
Specific version of elan to download and run instead of latest, e.g. 1.4.1
#>
param(
[bool] $Verbose = 0,
[bool] $NoPrompt = 0,
[bool] $NoModifyPath = 0,
[string] $DefaultToolchain = "",
[string] $ElanRoot = "https://github.com/leanprover/elan/releases",
[string] $ElanVersion = ""
)
# There are no Windows ARM releases yet, use emulated x64
$_arch = "x86_64-pc-windows-msvc"
$_ext = ".exe"
$temp = [System.IO.Path]::GetTempPath()
$_dir = Join-Path $temp "elan"
if (-not (Test-Path -Path $_dir)) {
$null = New-Item -ItemType Directory -Path $_dir
}
$_file = "$_dir/elan-init$_ext"
Write-Host "info: downloading installer to ${temp}"
try {
[string] $DownloadUrl = ""
if ($ElanVersion.Length -gt 0) {
$DownloadUrl = "$ElanRoot/download/v$ElanVersion/elan-$_arch.zip"
}
else {
$DownloadUrl = "$ElanRoot/latest/download/elan-$_arch.zip"
}
$null = Start-BitsTransfer -Source $DownloadUrl -Destination "$_dir/elan-init.zip" -ErrorAction Stop
}
catch {
Write-Host "Download failed for ${DownloadUrl}"
return 1
}
$null = Expand-Archive -Path "$_dir/elan-init.zip" -DestinationPath "$_dir" -Force
$cmdline = " "
if ($DefaultToolchain -ne "") {
$cmdline += "--default-toolchain $DefaultToolchain"
}
if ($NoPrompt) {
$cmdline += " -y"
}
if ($NoModifyPath) {
$cmdline += " --no-modify-path"
}
if ($Verbose) {
$cmdline += " --verbose"
}
$details = Start-Process -FilePath "$_file" -ArgumentList $cmdline -Wait -NoNewWindow -Passthru
$rc = $details.exitCode
if ($rc -ne 0 ) {
Write-Host "Elan failed with error code $rc"
return 1
}
$null = Remove-Item -Recurse -Force "$_dir"
return 0