Skip to content

Instantly share code, notes, and snippets.

@jhaynie
Last active July 8, 2018 00:03
Show Gist options
  • Save jhaynie/46d8d50fc26a3def3e824e6fed8a9fcf to your computer and use it in GitHub Desktop.
Save jhaynie/46d8d50fc26a3def3e824e6fed8a9fcf to your computer and use it in GitHub Desktop.
##
## This is the installer for the Pinpoint Agent.
##
## For more information, see: https://github.com/pinpoint/agent
##
## This script was adapted from https://github.com/buildkit/agent
$installDir = "C:\pinpoint-agent"
$arch = "amd64"
$ErrorActionPreference = "Stop"
Write-Host "
____ _ _ __
/ __ \(_)___ ____ ____ (_)___ / /_
/ /_/ / / __ \/ __ \/ __ \/ / __ \/ __/
/ ____/ / / / / /_/ / /_/ / / / / / /_
/_/ /_/_/ /_/ .___/\____/_/_/ /_/\__/
/_/
"
## Verify we are elevated
## https://superuser.com/questions/749243/detect-if-powershell-is-running-as-administrator
$elevated = [bool](([System.Security.Principal.WindowsIdentity]::GetCurrent()).groups -match "S-1-5-32-544")
if($elevated -eq $false) {
throw "In order to install services, please run this script elevated."
}
# Github requires TLS1.2
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$releaseInfoUrl = "https://api.github.com/repos/pinpt/agent/releases/latest"
Write-Host "Finding latest release"
$resp = Invoke-WebRequest -Uri "$releaseInfoUrl" -UseBasicParsing -Method GET | ConvertFrom-JSON
$asset = $resp.assets | where { $_.name -match "windows" }
$url = $asset.browser_download_url
Write-Host "Downloading $(url)"
Invoke-WebRequest -Uri $url -OutFile 'pinpoint-agent.zip'
Write-Host 'Expanding pinpoint-agent.zip'
Expand-Archive -Force -Path pinpoint-agent.zip -DestinationPath $installDir
Remove-Item pinpoint-agent.zip -Force
Write-Host 'Updating PATH'
$env:PATH = "${installDir};" + $env:PATH
[Environment]::SetEnvironmentVariable('PATH', $env:PATH, [EnvironmentVariableTarget]::Machine)
# Verify it worked
pinpoint-agent version
Write-Host "Successfully installed to $installDir
You can now start the agent!
${binDir}\pinpoint-agent.exe start
If this is your first time using the agent, make sure you run setup first:
${binDir}\pinpoint-agent.exe setup
"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment