forked from leanprover/elan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelan-init.ps1
96 lines (75 loc) · 2.7 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
90
91
92
93
94
95
96
# This is just a little script that can be downloaded from the internet to
# install elan. It just does platform detection, downloads the installer
# and runs it.
$ELAN_UPDATE_ROOT="https://github.com/leanprover/elan/releases"
#XXX: If you change anything here, please make the same changes in setup_mode.rs
function usage() {
Write-Host "
elan-init 1.0.0 (408ed84 2017-02-11)
The installer for elan
USAGE:
elan-init [FLAGS] [OPTIONS]
FLAGS:
-v, --verbose Enable verbose output
-y Disable confirmation prompt.
--no-modify-path Don't configure the PATH environment variable
-h, --help Prints help information
-V, --version Prints version information
OPTIONS:
--default-toolchain <default-toolchain> Choose a default toolchain to install
--default-toolchain none Do not install any toolchains
"
}
Function Get-RedirectedUrl {
Param (
[Parameter(Mandatory=$true)]
[String]$url
)
$request = [System.Net.WebRequest]::Create($url)
$request.AllowAutoRedirect=$true
$request.UserAgent = 'Mozilla/5.0 (Windows NT; Windows NT 10.0; en-US) AppleWebKit/534.6 (KHTML, like Gecko) Chrome/7.0.500.0 Safari/534.6'
try
{
$response = $request.GetResponse()
$response.ResponseUri.AbsoluteUri
$response.Close()
}
catch
{
"Error: $_"
}
}
function main($cmdline) {
$cputype=[System.Environment]::GetEnvironmentVariable("PROCESSOR_ARCHITECTURE");
if ($cputype -ne "AMD64") {
Write-Host "### Elan install only supports 64 bit windows with AMD64 architecture"
return 1
}
$_arch="x86_64-pc-windows-msvc"
$_ext = ".exe"
$temp = [System.IO.Path]::GetTempPath()
$_dir = Join-Path $temp "elan"
if (-not (Test-Path -Path $_dir)) {
New-Item -ItemType Directory -Path $_dir
}
$_file = "$_dir/elan-init$_ext"
Write-Host "info: downloading installer to ${temp}"
$x = Get-RedirectedUrl "https://github.com/leanprover/elan/releases/latest"
$xs = -split $x -split '/'
$_latest = $xs[-1]
Invoke-WebRequest -Uri "$ELAN_UPDATE_ROOT/download/$_latest/elan-$_arch.zip" -OutFile "$_dir/elan-init.zip"
Expand-Archive -Path "$_dir/elan-init.zip" -DestinationPath "$_dir" -Force
if ($cmdline.Count -eq 0) {
Start-Process -FilePath "$_dir/elan-init.exe" -Wait -NoNewWindow
} else {
Start-Process -FilePath "$_dir/elan-init.exe" -ArgumentList $cmdline -Wait -NoNewWindow
}
if( -not $? ) {
Write-Host "Elan failed with error code $?"
return 1
}
Remove-Item -Recurse -Force "$_dir"
return 0
}
$rc = main -cmdline $args
Exit $rc