-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall.ps1
78 lines (61 loc) · 2.32 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
#!/usr/bin/env pwsh
# inherited from https://github.com/release-lab/install
Write-Output "Installing Quix CLI"
Write-Output ""
$ErrorActionPreference = 'Stop'
$githubUrl = "https://github.com"
$owner = "quixio"
$repoName = "quix-cli"
$exeName = "quix"
if ([System.Environment]::Is64BitOperatingSystem) {
$architecture = [System.Environment]::GetEnvironmentVariable("PROCESSOR_ARCHITECTURE")
if ($architecture -eq "ARM64") {
$arch = "arm64"
} else {
$arch = "x64"
}
} else {
throw "Unsupported architecture: 32-bit operating system"
}
$BinDir = "$Home\bin"
$Target = "win-$arch"
$downloadedZip = "$BinDir\${Target}.zip"
# GitHub requires TLS 1.2
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$ResourceUri = if (!$version) {
"${githubUrl}/${owner}/${repoName}/releases/latest/download/${Target}.zip"
} else {
"${githubUrl}/${owner}/${repoName}/releases/download/${version}/${Target}.zip"
$version = ""
}
if (!(Test-Path $BinDir)) {
New-Item $BinDir -ItemType Directory | Out-Null
}
Write-Output "[1/5] Detected '${arch}' architecture"
Write-Output "[2/5] Downloading '${Target}.zip' to '${BinDir}'"
Invoke-WebRequest $ResourceUri -OutFile $downloadedZip -UseBasicParsing -ErrorAction Stop
Write-Output "[3/5] Decompressing '${Target}.zip' in '${BinDir}'"
if (Get-Command Expand-Archive -ErrorAction Ignore) {
Expand-Archive -Path $downloadedZip -DestinationPath $BinDir -Force
}
else {
function Expand-Zip($zipFile, $dest) {
if (-not (Get-Command Expand-7Zip -ErrorAction Ignore)) {
Install-Package -Scope CurrentUser -Force 7Zip4PowerShell > $null
}
Expand-7Zip $zipFile $dest
}
Expand-Zip $downloadedZip $BinDir
}
Write-Output "[4/5] Cleaning '${downloadedZip}'"
Remove-Item $downloadedZip
Write-Output "[5/5] Adding '${BinDir}' to the environment variables"
$User = [EnvironmentVariableTarget]::User
$Path = [Environment]::GetEnvironmentVariable('Path', $User)
if (!(";$Path;".ToLower() -like "*;$BinDir;*".ToLower())) {
[Environment]::SetEnvironmentVariable('Path', "$Path;$BinDir", $User)
$Env:Path += ";$BinDir"
}
Write-Output ""
Write-Output "Quix CLI was installed successfully"
Write-Output "Run '${exeName} --help' to get started"