forked from fossas/fossa-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-latest.ps1
103 lines (83 loc) · 3.13 KB
/
install-latest.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
#Requires -Version 5
<#
.SYNOPSIS
Download and install the latest available FOSSA release from GitHub.
#>
[CmdletBinding()]
Param()
$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 ""
Write-Host "------"
Write-Host "Notice"
Write-Host "------"
Write-Host ""
Write-Host "FOSSA collects warnings, errors, and usage data to improve"
Write-Host "the FOSSA CLI and your experience."
Write-Host ""
Write-Host "Read more: https://github.com/fossas/fossa-cli/blob/master/docs/telemetry.md"
Write-Host ""
Write-Host "If you want to prevent any telemetry data from being sent to"
Write-Host "the server, you can opt out of telemetry by setting"
Write-Host "FOSSA_TELEMETRY_SCOPE environment variable to 'off' in your shell."
Write-Host ""
Write-Host "For example:"
Write-Host " `$env:FOSSA_TELEMETRY_SCOPE=off"
Write-Host " fossa analyze"
Write-Host ""
Write-Host ""
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