Skip to content

Commit

Permalink
add(docs): add script todownload latest QDT version with PowerShell (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Guts authored Dec 6, 2024
2 parents b3d91ea + ff50538 commit 0eca2f1
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 0 deletions.
14 changes: 14 additions & 0 deletions docs/guides/howto_download_latest_qdt_exe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# How to dwonload the latest QDT's version

QDT comes with an upgrade command that check if a new version has been released in comparison with the used on, read the changelog and download the newest version: see [command-line usage](../usage/cli.md#upgrade-\(auto-update,-update\)).

Sometimes a system script fits better to usage, use-case or IT policy. We give below an example in PowerShell for Windows.

:::{info}
This script is a sample et might be not adapted to your environment or your IT policy. If you intend to use it in production, take time to review it before. If you improve or fix it, please share it.
:::

```{eval-rst}
.. literalinclude:: ../../scripts/qdt_dowloader.ps1
:language: powershell
```
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ caption: Guides
glob:
maxdepth: 1
---
guides/howto_download_latest_qdt_exe.md
guides/howto_validate_profiles_scenarios
guides/howto_behind_proxy
guides/howto_use_custom_ssl_certs
Expand Down
71 changes: 71 additions & 0 deletions scripts/qdt_dowloader.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<#
.Synopsis
Download the latest version of QDT executable from GitHub Releases.
.DESCRIPTION
This script will:
1. retrieve latest version of QDT from GitHub Releases API
2. identify the asset to download (*.exe)
3. download it as ~/qdt.exe
4. launch it with --help args to check it runs well
.LICENSE
SPDX-License-Identifier: Apache-2.0
#>

# -- VARIABLES

# source repository
$repository = "qgis-deployment/qgis-deployment-toolbelt-cli"

# GitHub API URL for the latest release
$apiUrl = "https://api.github.com/repos/$repository/releases/latest"

# API request headers
$apiHeaders = @{"User-Agent" = "QDT upgrader from $env:computername" }

# destination path
$destinationFile = "$env:USERPROFILE/qdt.exe"

# -- MAIN
try {
# Retrieve the latest release data
Write-Host "Retrieving latest QDT release from $apiUrl..."
$releaseData = Invoke-RestMethod -Uri $apiUrl -Headers $apiHeaders

# Extract the latest tag and the asset download URL
$latestTag = $releaseData.tag_name
$asset = $releaseData.assets | Where-Object { $_.name -like "*.exe" }

if (-not $asset) {
Write-Error "No executable asset found in the latest release: &apiUrl"
exit 1
}

Write-Host "Downloading QDT version $latestTag from $downloadUrl to $destinationFile"
$downloadUrl = $asset.browser_download_url

# Download the asset
$webClient = New-Object System.Net.WebClient
$webClient.Proxy = [System.Net.WebRequest]::DefaultWebProxy
$webClient.Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
$webClient.DownloadFile($downloadUrl, $destinationFile)

# log it
Write-Host "Download successful! File saved as $destinationFile" -ForegroundColor Green
}
catch {
# If there's an error, output details
if ($null -ne $_.Exception.Response) {
$statusCode = $_.Exception.Response.StatusCode
$statusDescription = $_.Exception.Response.StatusDescription
Write-Error "API request failed with status code ${statusCode}: ${statusDescription}"
}
else {
Write-Error "An error occurred: $_"
}
}

# Run the downloaded executable with --help
Write-Host "Running qdt.exe with --help..."
#Start-Process -FilePath $destinationFile -ArgumentList "--help" -NoNewWindow -Wait
#Start-Process -FilePath $destinationFile -ArgumentList "--help" -Wait -WindowStyle Hidden
Start-Process -FilePath $destinationFile -ArgumentList "--help" -NoNewWindow -Wait

0 comments on commit 0eca2f1

Please sign in to comment.