Last active
February 23, 2024 19:19
-
-
Save Guts/6303dc5eb941eb24be3e27609cd46985 to your computer and use it in GitHub Desktop.
Use OSGeo4W installer command-line abilities to provide a real-life example like downloading and installing QGIS LTR full meta-package
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
#Requires -RunAsAdministrator | |
<# | |
.Synopsis | |
Download the OSGeo4W installer then download and install QGIS LTR (through the 'full' meta-package). | |
.DESCRIPTION | |
This script will: | |
1. change the current directory to the user downloads folder | |
2. download the OSGeo4W installer | |
3. launch it passing command-line parameters to DOWNLOAD packages required to QGIS LTR FULL | |
4. launch it passing command-line parameters to INSTALL QGIS LTR | |
Documentation reference: https://trac.osgeo.org/osgeo4w/wiki/CommandLine | |
#> | |
# Save current working directory | |
$starter_path = Get-Location | |
# Move into the user download directory | |
Set-Location -Path "$env:USERPROFILE/Downloads" | |
# Download installer if not exists | |
if (-Not (Test-Path "osgeo4w_v2-setup.exe" -PathType leaf )) { | |
Write-Host "= Start downloading the OSGeo4W installer" -ForegroundColor Yellow | |
Invoke-WebRequest -Uri "https://download.osgeo.org/osgeo4w/v2/osgeo4w-setup.exe" -OutFile "osgeo4w_v2-setup.exe" | |
Write-Host "== Installer downloaded into $env:USERPROFILE/Downloads" -ForegroundColor Yellow | |
} | |
else | |
{ Write-Host "= OSGeo4W installer already exists. Let's use it!" -ForegroundColor Blue } | |
# Download and install (same command to upgrade with clean up) | |
Write-Host "=== Start installing / upgrading QGIS LTR..." -ForegroundColor Yellow | |
& .\osgeo4w_v2-setup.exe ` | |
--advanced ` | |
--arch x86_64 ` | |
--autoaccept ` | |
--delete-orphans ` | |
--local-package-dir "$env:APPDATA/OSGeo4W_v2-Packages" ` | |
--menu-name "QGIS LTR" ` | |
--no-desktop ` | |
--packages qgis-ltr-full ` | |
--quiet-mode ` | |
--root "$env:ProgramFiles/OSGeo4W_v2" ` | |
--site "http://www.norbit.de/osgeo4w/v2" ` | |
--site "http://download.osgeo.org/osgeo4w/v2" ` | |
--site "http://ftp.osuosl.org/pub/osgeo/download/osgeo4w/v2" ` | |
--upgrade-also ` | |
| out-null | |
# Return to the initial directory | |
Set-Location -Path $starter_path | |
Write-Host "==== Work is done!" -ForegroundColor Green |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Then why didn't you specify
--quiet-mode
?