-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.ps1
121 lines (96 loc) · 3.33 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
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
121
#!/usr/bin/env pwsh
# Stop executing script on any error
$ErrorActionPreference = 'Stop'
# Do not show download progress
$ProgressPreference = 'SilentlyContinue'
# Taken from https://stackoverflow.com/a/34559554/6537420
function New-TemporaryDirectory {
$parent = [System.IO.Path]::GetTempPath()
[string] $name = [System.Guid]::NewGuid()
New-Item -ItemType Directory -Path (Join-Path $parent $name)
}
$platform = $null
$architecture = $null
$fileName = $null
# PowerShell versions before 6.* were only for Windows OS
if ($PSVersionTable.PSVersion.Major -eq 5) {
$platform = 'win'
}
if ($PSVersionTable.PSVersion.Major -ge 6) {
if ($PSVersionTable.Platform -eq 'Unix') {
if ($PSVersionTable.OS -like 'Darwin*') {
$platform = 'darwin'
}
if ($PSVersionTable.OS -like 'Linux*') {
$platform = 'linux'
}
# PowerShell does not seem to have normal cmdlets for retrieving system information, so we use UNAME(1) for this.
$arch = uname -m
switch -Wildcard ($arch) {
'x86_64' { $architecture = 'amd64'; Break }
'amd64' { $architecture = 'amd64'; Break }
'armv*' { $architecture = 'arm'; Break }
'arm64' { $architecture = 'arm64'; Break }
'aarch64' { $architecture = 'arm64'; Break }
}
# 'uname -m' in some cases mis-reports 32-bit OS as 64-bit, so double check
if ([System.Environment]::Is64BitOperatingSystem -eq $false) {
if ($architecture -eq 'amd64') {
$architecture = 'i686'
}
if ($architecture -eq 'arm64') {
$architecture = 'arm'
}
}
$fileName = "blue"
}
if ($PSVersionTable.Platform -eq 'Win32NT') {
$platform = 'win'
}
}
if ($platform -eq 'win') {
if ([System.Environment]::Is64BitOperatingSystem -eq $true) {
$architecture = 'amd64'
}
if ([System.Environment]::Is64BitOperatingSystem -eq $false) {
$architecture = 'i686'
}
$fileName = "blue.exe"
}
if ($null -eq $platform) {
Write-Error "Platform could not be determined! Only Windows, Linux and macOS are supported."
}
switch ($architecture) {
'amd64' { ; Break }
'arm64' { ; Break }
Default {
Write-Error "Sorry! Blue currently only provides pre-built binaries for x86_64/arm64 architectures."
}
}
# The name of the bin file to download
$file = "blue-$platform-$architecture"
if ($platform -eq 'win') {
$file="$file.exe"
}
# Determine latest release tag
$releases = "https://api.github.com/repos/slekup/blue/releases"
$tagsResponse = Invoke-WebRequest $releases | ConvertFrom-Json
if ($tagsResponse.Count -gt 0) {
$tag = $tagsResponse[0].tag_name
} else {
Write-Error "No tags found in the GitHub repository. Unable to determine the latest release."
# Add your error handling or exit logic here
}
$download = "https://github.com/slekup/blue/releases/download/$tag/$file"
Write-Host "Downloading Blue from latest GitHub release...`n" -ForegroundColor Green
$tempFileFolder = New-TemporaryDirectory
$tempFile = (Join-Path $tempFileFolder.FullName $fileName)
Invoke-WebRequest $download -OutFile $tempFile -UseBasicParsing
Invoke-WebRequest $download -OutFile $tempFile
Write-Host "Running Blue installation...`n" -ForegroundColor Green
if ($platform -ne 'win') {
chmod +x $tempFile
}
Start-Process -FilePath $tempFile -ArgumentList "boostrap" -NoNewWindow -Wait -ErrorAction Continue
Remove-Item $tempFile
Remove-Item $tempFileFolder -Recurse