-
Notifications
You must be signed in to change notification settings - Fork 2
/
install.ps1
66 lines (47 loc) · 2.58 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
#Requires -Version 5
# remote install commands:
# Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/kintoproj/kinto-cli/master/install.ps1')
# iex (new-object net.webclient).downloadstring('https://raw.githubusercontent.com/kintoproj/kinto-cli/master/install.ps1')
# iwr https://raw.githubusercontent.com/kintoproj/kinto-cli/master/install.ps1 | iex
$old_erroractionpreference = $erroractionpreference
$erroractionpreference = 'stop' # quit if anything goes wrong
if (($PSVersionTable.PSVersion.Major) -lt 5) {
Write-Output "PowerShell 5 or later is required to download Kinto CLI."
Write-Output "Upgrade PowerShell: https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell"
break
}
# show notification to change execution policy:
$allowedExecutionPolicy = @('Unrestricted', 'RemoteSigned', 'ByPass')
if ((Get-ExecutionPolicy).ToString() -notin $allowedExecutionPolicy) {
Write-Output "PowerShell requires an execution policy in [$($allowedExecutionPolicy -join ", ")] to download Kinto CLI"
Write-Output "For example, to set the execution policy to 'RemoteSigned' please run :"
Write-Output "'Set-ExecutionPolicy RemoteSigned -scope CurrentUser'"
break
}
Write-Output 'Initializing...'
#Variables
$repoName = "kintoproj/kintohub"
$releaseName = "cli-kinto-win-amd64.zip"
$installationPath = $ENV:UserProfile+"\kinto"
$latestRelease = Invoke-WebRequest https://github.com/$repoName/releases/latest -Headers @{"Accept"="application/json"}
$json = $latestRelease.Content | ConvertFrom-Json
$latestVersion = $json.tag_name
Write-Output "Latest version found $latestVersion"
$downloadLink = "https://github.com/$repoName/releases/download/$latestVersion/$releaseName"
$downloadPath = Join-Path -Path $([System.IO.Path]::GetTempPath()) -ChildPath $(Split-Path -Path $downloadLink -Leaf)
echo "Downloading $releaseName ..."
Invoke-WebRequest $downloadLink -Out $downloadPath
Write-Output "Extracting..."
Remove-Item -Path $installationPath -Recurse -Force -ErrorAction SilentlyContinue
Expand-Archive -Path $downloadPath -DestinationPath $installationPath -Force
Write-Output 'Removing temp files...'
Remove-Item $downloadPath -Force
$path = ([Environment]::GetEnvironmentVariable("Path", "User"))
if ($path.Indexof($installationPath) -eq -1) {
Write-Output "Adding Kinto to PATH..."
[Environment]::SetEnvironmentVariable("Path", $path +";"+ $installationPath, "User")
break
} else {
Write-Output "Kinto is already present in PATH. Skipping..."
}
Write-Output "Successfully installed."