-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add(docs): add script todownload latest QDT version with PowerShell (#…
…595)
- Loading branch information
Showing
3 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |