Skip to content

Commit

Permalink
Update ./scripts/Build/Update TRMM agent.ps1
Browse files Browse the repository at this point in the history
  • Loading branch information
P6g9YHK6 committed Dec 21, 2024
1 parent b8f19df commit cf2d1a7
Showing 1 changed file with 21 additions and 36 deletions.
57 changes: 21 additions & 36 deletions scripts_staging/Build/Update TRMM agent.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,20 @@
.PARAMETER version
Specifies the version to download. If set to "latest," the script retrieves the latest version available on GitHub.
This can be specified through the environment variable `version`.
.PARAMETER isSigned
Boolean flag to determine if the signed version should be downloaded.
Set to true in the environment variable `issigned` to download the signed version; otherwise, the unsigned version is downloaded.
This should be specified through the environment variable `version`.
.PARAMETER signedDownloadToken
The token used for authenticated signed downloads. This should be set in the environment variable `trmm_sign_download_token`
and is required if `isSigned` is set to true.
The token used for authenticated signed downloads. This should be set in the environment variable `trmm_sign_download_token`.
If this token is provided, the script will download the signed version.
.PARAMETER trmm_api_target
The API target required for signed downloads. This should be specified in the environment variable `trmm_api_target`.
This is only necessary if using a signed download.
.EXEMPLE var
.EXEMPLE
trmm_sign_download_token={{global.trmm_sign_download_token}}
version=latest
version=2.7.0
issigned=true
trmm_api_target=api.exemple.com
.NOTES
Expand All @@ -33,25 +32,21 @@
#public
.CHANGELOG
29.10.24 SAN Initial script with signed and unsigned download support.
21.12.24 SAN updated the script to not require "issigned"
.TODO
integrate to our monthly update runs
test if api target is really needed
default to latest when nothing is set
#>


# Variables
$version = $env:version # Specify a version manually, or set it as "latest" to get the latest version from GitHub
$isSigned = $env:issigned -eq 'true' # Set to true to download the signed version
$version = $env:version # Specify a version manually, or leave as "latest" to get the latest version from GitHub
$signedDownloadToken = $env:trmm_sign_download_token # Token used for signed downloads only
$apiTarget = $env:trmm_api_target # Environment variable for the API target URL

# Check for signed download token and API target if isSigned is true
if ($isSigned -and (-not $signedDownloadToken -or -not $apiTarget)) {
Write-Output "Error: Missing signed download token or API target. Exiting..."
exit 1
}

# Define GitHub API URL for the RMMAgent repository
$repoUrl = "https://api.github.com/repos/amidaware/rmmagent/releases/latest"

Expand Down Expand Up @@ -108,29 +103,19 @@ try {
}
} else {
Write-Output "'Tactical RMM Agent' is not installed on this system. Checking installed software..."
# List all installed software for debugging
$allInstalledSoftware = Get-CimInstance -ClassName Win32_Product
Write-Output "Currently installed software (Win32_Product):"
$allInstalledSoftware | ForEach-Object { Write-Output "- $($_.Name)" }

# Check the uninstall registry key as well
$uninstallKeys = @(
"HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*",
"HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*"
)
Write-Output "Currently installed software (Registry):"
foreach ($key in $uninstallKeys) {
$allInstalledSoftware = Get-ItemProperty $key
$allInstalledSoftware | ForEach-Object { Write-Output "- $($_.DisplayName)" }
}
}

# Define the temp directory for downloading
$tempDir = [System.IO.Path]::GetTempPath()
$outputFile = Join-Path -Path $tempDir -ChildPath "tacticalagent-v$version.exe"

# Determine the download URL based on the $isSigned variable
if ($isSigned) {
# Determine the download URL based on the presence of $signedDownloadToken
if ($signedDownloadToken) {
if (-not $apiTarget) {
Write-Output "Error: Missing API target for signed downloads. Exiting..."
exit 1
}

# Download the signed agent using the token
$downloadUrl = "https://agents.tacticalrmm.com/api/v2/agents?version=$version&arch=amd64&token=$signedDownloadToken&plat=windows&api=$apiTarget"
} else {
Expand Down

0 comments on commit cf2d1a7

Please sign in to comment.