-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathleadman_windows.ps1
120 lines (89 loc) · 2.99 KB
/
leadman_windows.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
$ErrorActionPreference = "Stop"
$INFO = "$($PSStyle.Foreground.Blue)[INFO]$($PSStyle.Reset)"
$ERR = "$($PSStyle.Foreground.Red)$($PSStyle.Bold)[ERRR]$($PSStyle.Reset)"
$SUCC = "$($PSStyle.Foreground.Green)$($PSStyle.Bold)[SUCC]$($PSStyle.Reset)"
$architecture = $env:PROCESSOR_ARCHITECTURE
$tag = $env:TAG_NAME
$vcArm64 = "https://aka.ms/vs/17/release/vc_redist.arm64.exe"
$vcX86 = "https://aka.ms/vs/17/release/vc_redist.x86.exe"
$vcX64 = "https://aka.ms/vs/17/release/vc_redist.x64.exe"
"$INFO Checking OS"
if ([System.Environment]::OSVersion.Platform -ne "Win32NT") {
Write-Err "$ERR Unsupported Operating System, run this in $($PSStyle.Bold)Windows$($PSStyle.Reset) or use the $($PSStyle.Bold)bash script$($PSStyle.Reset)"
exit 1
}
"$INFO Getting architecture"
if ($tag.Length -eq 0) {
"$INFO Using latest as version"
$tag = "latest"
}
else {
"$INFO Provided Leadman Version $tag"
}
$isWin11 = (Get-WmiObject Win32_OperatingSystem).Caption -Match "Windows 11"
"$INFO Found Leadman Version $tag"
function AskDownloadVC {
param (
[string]$Url
)
Write-Host -NoNewline "$INFO Would you like to download the Visual C++ Redistributable? [Y/n]"
$ask = (Read-Host).ToLower()
if (-not $ask.StartsWith("n")) {
curl.exe -o "$env:temp\vc_redist.exe" -L $Url
Start-Process -FilePath "$env:TEMP\vc_redist.exe" -Wait -ArgumentList @("/install", "/passive", "/norestart")
}
}
switch ($architecture) {
"AMD64" {
AskDownloadVC -Url $vcX64
$arch = "x86_64"
break
}
"ARM64" {
AskDownloadVC -Url $vcArm64
$arch = "aarch64"
if ($isWin11) {
"$INFO Lead Language might soon introduce ARM64EC support for Windows 11 once Microsoft supports it on GitHub Actions"
#Write-Host -NoNewline "$INFO Would you like to use the ARM64EC version? [Y/n]"
#$ask = (Read-Host).ToLower()
#if ($ask -eq "y") {
# $arch = "arm64ec"
#}
}
break
}
"x86" {
AskDownloadVC -Url $vcX86
$arch = "i686"
break
}
default {
Write-Err "$ERR Unknown architecture $architecture"
exit 1
}
}
"$INFO Found Architecture $arch"
if ($tag -eq "latest") {
$tag = "latest/download"
}
else {
$tag = "download/$tag"
}
$nt = [Environment]::OSVersion.Version.Major
$DOWNLOAD = "https://github.com/leadlang/lead/releases/$tag/leadman_$arch-pc-windows-msvc.exe"
if ($nt -lt 10) {
"$INFO Using win7 compat binary as NT Version $nt is less than NT 10.0"
$DOWNLOAD = "https://github.com/leadlang/lead/releases/$tag/leadman_$arch-win7-windows-msvc.exe"
}
"$INFO Starting leadman"
""
curl.exe -o "$env:temp\leadman_init.exe" -L $DOWNLOAD
$result = Start-Process -Wait -NoNewWindow -FilePath "$env:TEMP\leadman_init.exe" -ArgumentList "create" -PassThru
if ($result.ExitCode -eq 0) {
"$SUCC Successfully installed"
Start-Sleep -Seconds 1
}
$ver = $PSVersionTable.PSVersion.Major
if (-not $PSVersionTable -or $ver -lt 7) {
"$INFO We recommend you to upgrade to PowerShell 7.0 or higher. Current version: $($PSVersionTable.PSVersion)"
}