This repository has been archived by the owner on Apr 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
install.ps1
96 lines (74 loc) · 2.81 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
#Requires -Version 5
<#
.SYNOPSIS
Download and install the latest available FOSSA release from GitHub.
#>
[CmdletBinding()]
Param()
Write-Host ""
Write-Host "Notice:"
Write-Host ""
Write-Host " Spectrometer has been migrated to the fossa-cli repository at:"
Write-Host " https://github.com/fossas/fossa-cli"
Write-Host ""
Write-Host " Please migrate to using latest installation script provided at:"
Write-Host " https://github.com/fossas/fossa-cli"
Write-Host ""
Write-Host ""
$OldEAP = $ErrorActionPreference #Preserve the original value
$ErrorActionPreference = "Stop"
$app = "fossa"
# Set to default if null
if ($env:FOSSA_RELEASE)
{
if ($env:FOSSA_RELEASE -inotmatch '^v\d.\d+.\d+$')
{
throw "FOSSA_RELEASE must be in the format of v2.x.x (e.g.: 'v2.0.1')"
}
$releaseTag = "$env:FOSSA_RELEASE"
}
else
{
$releaseTag = "latest"
}
$github = "https://github.com"
$latestUri = "$github/fossas/fossa-cli/releases/$releaseTag"
$userExtractDir = "$env:LOCALAPPDATA\fossa-cli"
$allUsersExtractDir = "$env:PROGRAMFILES\fossa-cli"
if ($env:FOSSA_ALL_USERS)
{
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
if (-not $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator))
{
throw "Cannot install for all users without admin privleges. Please run powershell as administrator to install for all users."
}
$extractDir = "$allUsersExtractDir"
}
else
{
$extractDir = "$userExtractDir"
}
Write-Verbose "Looking up release ($releaseTag)..."
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12
$headers = @{
'Accept' = 'application/json'
}
$release = Invoke-RestMethod -Uri $latestUri -Method Get -Headers $headers
$releaseVersion = $release.tag_name;
$releaseVersionSemver = $releaseVersion.TrimStart("v");
$downloadUri = "$github/fossas/fossa-cli/releases/download/$releaseVersion/$($app)_$($releaseVersionSemver)_windows_amd64.zip"
Write-Output "Downloading from: $downloadUri"
$TempDir = Join-Path ([System.IO.Path]::GetTempPath()) "fossa"
if (![System.IO.Directory]::Exists($TempDir)) {[void][System.IO.Directory]::CreateDirectory($TempDir)}
$zipFile = "$TempDir\fossa.zip"
(New-Object System.Net.WebClient).DownloadFile($downloadUri, $zipFile)
Expand-Archive -Path $zipFile -DestinationPath $extractDir -Force
$ErrorActionPreference = $OldEAP
$fossa = "$extractDir\fossa.exe"
$env:Path += ";$extractDir"
Write-Host "The fossa-cli installation directory has been added to the PATH for this session."
Write-Host "Installed fossa at: $fossa"
Write-Host "Get started by running: fossa.exe --help"
Write-Host "Running fossa.exe --version"
# Doesn't run without '&', seems to tell PS to treat the output as a command
& $fossa --version