Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jmarsac/6dbf7a522d13726046da6548309eba32 to your computer and use it in GitHub Desktop.
Save jmarsac/6dbf7a522d13726046da6548309eba32 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
#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-setup-x86_64.exe" -PathType leaf )) {
Write-Host "= Start downloading the OSGeo4W installer" -ForegroundColor Yellow
Invoke-WebRequest -Uri "https://download.osgeo.org/osgeo4w/osgeo4w-setup-x86_64.exe" -OutFile "osgeo4w-setup-x86_64.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-setup-x86_64.exe --advanced --arch x86_64 --autoaccept --delete-orphans --no-desktop --packages qgis-ltr-full --quiet-mode --site "http://download.osgeo.org/osgeo4w" --site "http://osgeo4w-oslandia.com/mirror" --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