1010
1111. PARAMETER version
1212 Specifies the version to download. If set to "latest," the script retrieves the latest version available on GitHub.
13- This can be specified through the environment variable `version`.
14-
15- . PARAMETER isSigned
16- Boolean flag to determine if the signed version should be downloaded.
17- Set to true in the environment variable `issigned` to download the signed version; otherwise, the unsigned version is downloaded.
13+ This should be specified through the environment variable `version`.
1814
1915. PARAMETER signedDownloadToken
20- The token used for authenticated signed downloads. This should be set in the environment variable `trmm_sign_download_token`
21- and is required if `isSigned` is set to true.
16+ The token used for authenticated signed downloads. This should be set in the environment variable `trmm_sign_download_token`.
17+ If this token is provided, the script will download the signed version.
18+
19+ . PARAMETER trmm_api_target
20+ The API target required for signed downloads. This should be specified in the environment variable `trmm_api_target`.
21+ This is only necessary if using a signed download.
2222
23- .EXEMPLE var
23+ .EXEMPLE
2424 trmm_sign_download_token={{global.trmm_sign_download_token}}
2525 version=latest
2626 version=2.7.0
27- issigned=true
27+ trmm_api_target=api.exemple.com
2828
2929. NOTES
3030 Author: SAN
3131 Date: 29.10.24
3232 #public
3333
3434.CHANGELOG
35- - Initial version
36- - Added support for environment variable input
37- - Enhanced error handling and process execution
38- - Added local version check to skip download if versions match
35+ 29.10.24 SAN Initial script with signed and unsigned download support.
36+ 21.12.24 SAN updated the script to not require "issigned"
37+ 22.12.24 SAN default to latest when no version is set
3938
4039.TODO
41- integrate to monthly update runs
40+ integrate to our monthly update runs
41+ test if api target is really needed
42+
4243#>
43-
4444# Variables
4545$version = $env: version # Specify a version manually, or leave as "latest" to get the latest version from GitHub
46- $isSigned = $env: issigned -eq ' true' # Set to true to download the signed version
4746$signedDownloadToken = $env: trmm_sign_download_token # Token used for signed downloads only
48-
49- # Check for signed download token if isSigned is true
50- if ($isSigned -and -not $signedDownloadToken ) {
51- Write-Output " Error: Missing signed download token. Exiting..."
52- exit 1
53- }
47+ $apiTarget = $env: trmm_api_target # Environment variable for the API target URL
5448
5549# Define GitHub API URL for the RMMAgent repository
5650$repoUrl = " https://api.github.com/repos/amidaware/rmmagent/releases/latest"
5751
5852# Function to get the currently installed version of the Tactical RMM agent from the software list
5953function Get-InstalledVersion {
60- $appName = " Tactical RMM Agent" # Adjust if the application's display name differs
54+ $appName = " Tactical RMM Agent" # Adjust if the application's display name differs left this in case whitelabel changes the name of the app
6155 $installedSoftware = Get-CimInstance - ClassName Win32_Product | Where-Object { $_.Name -like " *$appName *" }
6256
6357 if ($installedSoftware ) {
8680 " User-Agent" = " PowerShell Script"
8781 }
8882
83+ # If version is not set, default to "latest"
84+ if (-not $version ) {
85+ $version = " latest"
86+ }
87+
8988 # If version is set to "latest", fetch the latest release information from GitHub
9089 if ($version -eq " latest" ) {
9190 Write-Output " Fetching the latest version information from GitHub..."
@@ -108,31 +107,21 @@ try {
108107 }
109108 } else {
110109 Write-Output " 'Tactical RMM Agent' is not installed on this system. Checking installed software..."
111- # List all installed software for debugging
112- $allInstalledSoftware = Get-CimInstance - ClassName Win32_Product
113- Write-Output " Currently installed software (Win32_Product):"
114- $allInstalledSoftware | ForEach-Object { Write-Output " - $ ( $_.Name ) " }
115-
116- # Check the uninstall registry key as well
117- $uninstallKeys = @ (
118- " HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*" ,
119- " HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*"
120- )
121- Write-Output " Currently installed software (Registry):"
122- foreach ($key in $uninstallKeys ) {
123- $allInstalledSoftware = Get-ItemProperty $key
124- $allInstalledSoftware | ForEach-Object { Write-Output " - $ ( $_.DisplayName ) " }
125- }
126110 }
127-
111+
128112 # Define the temp directory for downloading
129113 $tempDir = [System.IO.Path ]::GetTempPath()
130114 $outputFile = Join-Path - Path $tempDir - ChildPath " tacticalagent-v$version .exe"
131115
132- # Determine the download URL based on the $isSigned variable
133- if ($isSigned ) {
116+ # Determine the download URL based on the presence of $signedDownloadToken
117+ if ($signedDownloadToken ) {
118+ if (-not $apiTarget ) {
119+ Write-Output " Error: Missing API target for signed downloads. Exiting..."
120+ exit 1
121+ }
122+
134123 # Download the signed agent using the token
135- $downloadUrl = " https://agents.tacticalrmm.com/api/v2/agents?version=$version &arch=amd64&token=$signedDownloadToken &plat=windows&api=api-rmm-managed-services.vtx.ch "
124+ $downloadUrl = " https://agents.tacticalrmm.com/api/v2/agents?version=$version &arch=amd64&token=$signedDownloadToken &plat=windows&api=$apiTarget "
136125 } else {
137126 # Download the unsigned agent directly from GitHub releases
138127 $downloadUrl = " https://github.com/amidaware/rmmagent/releases/download/v$version /tacticalagent-v$version -windows-amd64.exe"
0 commit comments