Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions ee/maintained-apps/ingesters/homebrew/ingester.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ func (i *brewIngester) ingestOne(ctx context.Context, input inputApp) (*maintain
out.UniqueIdentifier,
)
}
if pathFilter, ok := qgisPathFilters[input.Token]; ok {
// The patch policy generated below inherits this filter.
out.Queries.Exists = fmt.Sprintf("SELECT 1 FROM apps WHERE bundle_identifier = '%s' AND %s;", out.UniqueIdentifier, pathFilter)
}
out.Slug = input.Slug
out.DefaultCategories = input.DefaultCategories

Expand Down Expand Up @@ -364,10 +368,24 @@ func (i *brewIngester) ingestOne(ctx context.Context, input inputApp) (*maintain
out.UniqueIdentifier,
)
}
if pathFilter, ok := qgisPathFilters[input.Token]; ok {
// Only this channel's copy counts as open; the other channel doesn't block its install.
out.Queries.Open = fmt.Sprintf(
"SELECT 1 WHERE NOT EXISTS (SELECT 1 FROM apps a JOIN processes p ON p.path = concat(a.path, '/Contents/MacOS/', a.bundle_executable) WHERE a.bundle_identifier = '%s' AND a.%s AND a.bundle_executable != '');",
out.UniqueIdentifier, pathFilter,
)
}

return out, nil
}

// qgisPathFilters tells QGIS and QGIS LTR apart by where their casks install them:
// both report the org.qgis.qgis3 bundle identifier.
var qgisPathFilters = map[string]string{
"qgis": "path LIKE '/Applications/QGIS-final-%.app'",
"qgis@ltr": "path = '/Applications/QGIS-LTR.app'",
}

var firefoxBetaVersionPattern = regexp.MustCompile(`^(\d+(?:\.\d+)*)b\d+$`)

// firefoxBetaBaseVersion strips the beta suffix from a Firefox pre-release
Expand Down
27 changes: 26 additions & 1 deletion ee/maintained-apps/ingesters/homebrew/ingester_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func TestIngestValidations(t *testing.T) {
Version: "1.0",
}

case "ok", "1password", "docker-desktop", "microsoft-edge", "google-chrome", "webex", "i1profiler", "steam", "swiftdialog", "teleport-suite", "r-app", "install_script_path", "uninstall_script_path", "uninstall_script_path_with_pre", "uninstall_script_path_with_post", "patch_policy_path", "open-query":
case "ok", "1password", "docker-desktop", "microsoft-edge", "google-chrome", "webex", "i1profiler", "steam", "swiftdialog", "teleport-suite", "r-app", "qgis", "qgis@ltr", "install_script_path", "uninstall_script_path", "uninstall_script_path_with_pre", "uninstall_script_path_with_post", "patch_policy_path", "open-query":
cask = brewCask{
Token: appToken,
Name: []string{appToken},
Expand Down Expand Up @@ -154,6 +154,8 @@ func TestIngestValidations(t *testing.T) {
{"", inputApp{Token: "swiftdialog", UniqueIdentifier: "au.csiro.dialog", InstallerFormat: "pkg", Name: "swiftDialog", Slug: "swiftdialog/darwin"}},
{"", inputApp{Token: "teleport-suite", UniqueIdentifier: "com.gravitational.teleport.tsh", InstallerFormat: "pkg", Name: "Teleport Suite", Slug: "teleport-suite/darwin"}},
{"", inputApp{Token: "r-app", UniqueIdentifier: "org.R-project.R", InstallerFormat: "pkg", Name: "R for macOS", Slug: "r/darwin"}},
{"", inputApp{Token: "qgis", UniqueIdentifier: "org.qgis.qgis3", InstallerFormat: "dmg", Name: "QGIS", Slug: "qgis/darwin"}},
{"", inputApp{Token: "qgis@ltr", UniqueIdentifier: "org.qgis.qgis3", InstallerFormat: "dmg", Name: "QGIS LTR", Slug: "qgis@ltr/darwin"}},
{"", inputApp{Token: "install_script_path", UniqueIdentifier: "abc", InstallerFormat: "pkg", InstallScriptPath: path.Join(tempDir, "install_script.sh")}},
{"", inputApp{Token: "uninstall_script_path", UniqueIdentifier: "abc", InstallerFormat: "pkg", UninstallScriptPath: path.Join(tempDir, "uninstall_script.sh")}},
{"", inputApp{Token: "open-query", UniqueIdentifier: "com.example.app", InstallerFormat: "pkg", Name: "Example App"}},
Expand Down Expand Up @@ -259,6 +261,19 @@ func TestIngestValidations(t *testing.T) {
"SELECT 1 WHERE NOT EXISTS (SELECT 1 FROM apps WHERE bundle_identifier = 'org.R-project.R' AND version_compare(REGEX_MATCH(bundle_short_version, 'R (?:R )?([0-9]+(?:\\.[0-9]+)+) GUI', 1), '1.0') < 0);",
out.Queries.Patched,
)
case "qgis":
// QGIS and QGIS LTR share a bundle identifier, so each is scoped to its install path.
require.Equal(t, "SELECT 1 FROM apps WHERE bundle_identifier = 'org.qgis.qgis3' AND path LIKE '/Applications/QGIS-final-%.app';", out.Queries.Exists)
require.Equal(t,
"SELECT 1 WHERE NOT EXISTS (SELECT 1 FROM apps WHERE bundle_identifier = 'org.qgis.qgis3' AND path LIKE '/Applications/QGIS-final-%.app' AND version_compare(bundle_short_version, '1.0') < 0);",
out.Queries.Patched,
)
case "qgis@ltr":
require.Equal(t, "SELECT 1 FROM apps WHERE bundle_identifier = 'org.qgis.qgis3' AND path = '/Applications/QGIS-LTR.app';", out.Queries.Exists)
require.Equal(t,
"SELECT 1 WHERE NOT EXISTS (SELECT 1 FROM apps WHERE bundle_identifier = 'org.qgis.qgis3' AND path = '/Applications/QGIS-LTR.app' AND version_compare(bundle_short_version, '1.0') < 0);",
out.Queries.Patched,
)
default:
require.Equal(t,
fmt.Sprintf("SELECT 1 WHERE NOT EXISTS (SELECT 1 FROM apps WHERE bundle_identifier = '%s' AND version_compare(bundle_short_version, '%s') < 0);", c.inputApp.UniqueIdentifier, out.Version),
Expand All @@ -273,6 +288,16 @@ func TestIngestValidations(t *testing.T) {
fmt.Sprintf("SELECT 1 WHERE NOT EXISTS (SELECT 1 FROM apps a JOIN processes p ON (p.path = concat(a.path, '/Contents/MacOS/', a.bundle_executable) OR p.path LIKE concat('%%/', a.bundle_identifier, '.code_sign_clone/%%/Contents/MacOS/', a.bundle_executable)) WHERE a.bundle_identifier = '%s' AND a.bundle_executable != '');", out.UniqueIdentifier),
out.Queries.Open,
)
case "qgis":
require.Equal(t,
"SELECT 1 WHERE NOT EXISTS (SELECT 1 FROM apps a JOIN processes p ON p.path = concat(a.path, '/Contents/MacOS/', a.bundle_executable) WHERE a.bundle_identifier = 'org.qgis.qgis3' AND a.path LIKE '/Applications/QGIS-final-%.app' AND a.bundle_executable != '');",
out.Queries.Open,
)
case "qgis@ltr":
require.Equal(t,
"SELECT 1 WHERE NOT EXISTS (SELECT 1 FROM apps a JOIN processes p ON p.path = concat(a.path, '/Contents/MacOS/', a.bundle_executable) WHERE a.bundle_identifier = 'org.qgis.qgis3' AND a.path = '/Applications/QGIS-LTR.app' AND a.bundle_executable != '');",
out.Queries.Open,
)
default:
// The managed "is app open" query matches only the app's own executable, so
// in-bundle login items and helpers that outlive the app don't count as open.
Expand Down
10 changes: 10 additions & 0 deletions ee/maintained-apps/inputs/homebrew/qgis.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "QGIS",
"slug": "qgis/darwin",
"unique_identifier": "org.qgis.qgis3",
"token": "qgis",
"installer_format": "dmg",
"install_script_path": "ee/maintained-apps/inputs/homebrew/scripts/qgis-install.sh",
"uninstall_script_path": "ee/maintained-apps/inputs/homebrew/scripts/qgis-uninstall.sh",
"default_categories": ["Productivity"]
}
10 changes: 10 additions & 0 deletions ee/maintained-apps/inputs/homebrew/qgis@ltr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "QGIS LTR",
"slug": "qgis@ltr/darwin",
"unique_identifier": "org.qgis.qgis3",
"token": "qgis@ltr",
"installer_format": "dmg",
"install_script_path": "ee/maintained-apps/inputs/homebrew/scripts/qgis-ltr-install.sh",
"uninstall_script_path": "ee/maintained-apps/inputs/homebrew/scripts/qgis-ltr-uninstall.sh",
"default_categories": ["Productivity"]
}
62 changes: 62 additions & 0 deletions ee/maintained-apps/inputs/homebrew/scripts/qgis-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/bin/bash

# QGIS is closed if it's running, and unsaved project changes are lost. Each
# release installs as its own QGIS-final-<version>.app, so earlier releases are
# removed once the new one is in place. QGIS LTR (QGIS-LTR.app) is left alone.

APPDIR="/Applications"
TMPDIR=$(dirname "$(realpath "$INSTALLER_PATH")")

# QGIS and QGIS LTR share a bundle identifier, so match processes by path.
quit_app_at_path() {
local app_path="$1"
local pattern="^${app_path}/Contents/MacOS/"
pgrep -f "$pattern" >/dev/null || return 0
echo "Closing $app_path..."
pkill -TERM -f "$pattern"
for _ in {1..10}; do
pgrep -f "$pattern" >/dev/null || return 0
sleep 1
done
echo "$app_path did not close; forcing it to quit."
pkill -KILL -f "$pattern"
}

MOUNT_POINT=$(mktemp -d /tmp/dmg_mount_XXXXXX)
yes | hdiutil attach -plist -nobrowse -readonly -mountpoint "$MOUNT_POINT" "$INSTALLER_PATH" >/dev/null || exit 1
trap 'hdiutil detach "$MOUNT_POINT" >/dev/null 2>&1 || true' EXIT

NEW_APP=$(find "$MOUNT_POINT" -maxdepth 1 -name 'QGIS-final-*.app' -print -quit)
if [[ -z "$NEW_APP" ]]; then
echo "No QGIS-final-*.app found in the disk image."
exit 1
fi
APP_NAME=$(basename "$NEW_APP")

for app in "$APPDIR"/QGIS-final-*.app; do
[[ -d "$app" ]] && quit_app_at_path "$app"
done

sudo rm -rf "$TMPDIR/$APP_NAME.bkp"
if [[ -d "$APPDIR/$APP_NAME" ]]; then
sudo mv "$APPDIR/$APP_NAME" "$TMPDIR/$APP_NAME.bkp" || exit $?
fi
if ! sudo cp -R "$NEW_APP" "$APPDIR/"; then
# remove the partial copy so a failed install isn't inventoried as the new
# version, then restore the previous version if there was one
sudo rm -rf "$APPDIR/$APP_NAME"
if [[ -d "$TMPDIR/$APP_NAME.bkp" ]]; then
sudo mv "$TMPDIR/$APP_NAME.bkp" "$APPDIR/$APP_NAME"
fi
exit 1
fi
sudo rm -rf "$TMPDIR/$APP_NAME.bkp"

for app in "$APPDIR"/QGIS-final-*.app; do
if [[ -d "$app" && "$(basename "$app")" != "$APP_NAME" ]]; then
echo "Removing earlier release $app"
sudo rm -rf "$app"
fi
done

echo "Installed $APPDIR/$APP_NAME"
51 changes: 51 additions & 0 deletions ee/maintained-apps/inputs/homebrew/scripts/qgis-ltr-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash

# QGIS LTR is closed if it's running, and unsaved project changes are lost. It
# installs as QGIS-LTR.app so it can sit alongside QGIS, which is left alone.

APPDIR="/Applications"
TMPDIR=$(dirname "$(realpath "$INSTALLER_PATH")")
APP_PATH="$APPDIR/QGIS-LTR.app"

# QGIS and QGIS LTR share a bundle identifier, so match processes by path.
quit_app_at_path() {
local app_path="$1"
local pattern="^${app_path}/Contents/MacOS/"
pgrep -f "$pattern" >/dev/null || return 0
echo "Closing $app_path..."
pkill -TERM -f "$pattern"
for _ in {1..10}; do
pgrep -f "$pattern" >/dev/null || return 0
sleep 1
done
echo "$app_path did not close; forcing it to quit."
pkill -KILL -f "$pattern"
}

MOUNT_POINT=$(mktemp -d /tmp/dmg_mount_XXXXXX)
yes | hdiutil attach -plist -nobrowse -readonly -mountpoint "$MOUNT_POINT" "$INSTALLER_PATH" >/dev/null || exit 1
trap 'hdiutil detach "$MOUNT_POINT" >/dev/null 2>&1 || true' EXIT

if [[ ! -d "$MOUNT_POINT/QGIS.app" ]]; then
echo "No QGIS.app found in the disk image."
exit 1
fi

quit_app_at_path "$APP_PATH"

sudo rm -rf "$TMPDIR/QGIS-LTR.app.bkp"
if [[ -d "$APP_PATH" ]]; then
sudo mv "$APP_PATH" "$TMPDIR/QGIS-LTR.app.bkp" || exit $?
fi
if ! sudo cp -R "$MOUNT_POINT/QGIS.app" "$APP_PATH"; then
# remove the partial copy so a failed install isn't inventoried as the new
# version, then restore the previous version if there was one
sudo rm -rf "$APP_PATH"
if [[ -d "$TMPDIR/QGIS-LTR.app.bkp" ]]; then
sudo mv "$TMPDIR/QGIS-LTR.app.bkp" "$APP_PATH"
fi
exit 1
fi
sudo rm -rf "$TMPDIR/QGIS-LTR.app.bkp"

echo "Installed $APP_PATH"
24 changes: 24 additions & 0 deletions ee/maintained-apps/inputs/homebrew/scripts/qgis-ltr-uninstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

# Removes QGIS-LTR.app and closes it if it's running. QGIS and per-user QGIS
# data (profiles, plugins, caches), which QGIS also uses, are left in place.

APP_PATH="/Applications/QGIS-LTR.app"

# QGIS and QGIS LTR share a bundle identifier, so match processes by path.
quit_app_at_path() {
local app_path="$1"
local pattern="^${app_path}/Contents/MacOS/"
pgrep -f "$pattern" >/dev/null || return 0
echo "Closing $app_path..."
pkill -TERM -f "$pattern"
for _ in {1..10}; do
pgrep -f "$pattern" >/dev/null || return 0
sleep 1
done
echo "$app_path did not close; forcing it to quit."
pkill -KILL -f "$pattern"
}

quit_app_at_path "$APP_PATH"
sudo rm -rf "$APP_PATH"
29 changes: 29 additions & 0 deletions ee/maintained-apps/inputs/homebrew/scripts/qgis-uninstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

# Removes every QGIS-final-<version>.app and closes QGIS if it's running. QGIS
# LTR and per-user QGIS data (profiles, plugins, caches), which QGIS LTR also
# uses, are left in place.

APPDIR="/Applications"

# QGIS and QGIS LTR share a bundle identifier, so match processes by path.
quit_app_at_path() {
local app_path="$1"
local pattern="^${app_path}/Contents/MacOS/"
pgrep -f "$pattern" >/dev/null || return 0
echo "Closing $app_path..."
pkill -TERM -f "$pattern"
for _ in {1..10}; do
pgrep -f "$pattern" >/dev/null || return 0
sleep 1
done
echo "$app_path did not close; forcing it to quit."
pkill -KILL -f "$pattern"
}

for app in "$APPDIR"/QGIS-final-*.app; do
[[ -d "$app" ]] || continue
quit_app_at_path "$app"
echo "Removing $app"
sudo rm -rf "$app"
done
14 changes: 14 additions & 0 deletions ee/maintained-apps/inputs/winget/qgis.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "QGIS",
"slug": "qgis/windows",
"package_identifier": "OSGeo.QGIS",
"unique_identifier": "QGIS",
"fuzzy_match_name": true,
"exists_query": "SELECT 1 FROM programs WHERE name LIKE 'QGIS %' AND publisher = 'QGIS.org' AND version NOT LIKE '3.44.%';",
"installer_arch": "x64",
"installer_type": "msi",
"installer_scope": "machine",
"install_script_path": "ee/maintained-apps/inputs/winget/scripts/qgis_install.ps1",
"uninstall_script_path": "ee/maintained-apps/inputs/winget/scripts/qgis_uninstall.ps1",
"default_categories": ["Productivity"]
}
14 changes: 14 additions & 0 deletions ee/maintained-apps/inputs/winget/qgis@ltr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "QGIS LTR",
"slug": "qgis@ltr/windows",
"package_identifier": "OSGeo.QGIS_LTR",
"unique_identifier": "QGIS",
"fuzzy_match_name": true,
"exists_query": "SELECT 1 FROM programs WHERE name LIKE 'QGIS %' AND publisher = 'QGIS.org' AND version LIKE '3.44.%';",
"installer_arch": "x64",
"installer_type": "msi",
"installer_scope": "machine",
"install_script_path": "ee/maintained-apps/inputs/winget/scripts/qgis-ltr_install.ps1",
"uninstall_script_path": "ee/maintained-apps/inputs/winget/scripts/qgis-ltr_uninstall.ps1",
"default_categories": ["Productivity"]
}
48 changes: 48 additions & 0 deletions ee/maintained-apps/inputs/winget/scripts/qgis-ltr_install.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Each QGIS release installs side by side under its own product code, so
# installed QGIS LTR (3.44.x) releases are uninstalled first. Other QGIS
# releases are left in place.

$ltrSeries = '3.44.'
$logFile = "${env:TEMP}/fleet-install-software.log"

# MSI exit codes that indicate success. 3010 = ERROR_SUCCESS_REBOOT_REQUIRED,
# 1641 = ERROR_SUCCESS_REBOOT_INITIATED. Treat these as success rather than failure.
$successCodes = @(0, 3010, 1641)

try {

$uninstallRoots = @(
'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*',
'HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*'
)
$entries = @(Get-ItemProperty -Path $uninstallRoots -ErrorAction SilentlyContinue | Where-Object {
$_.DisplayName -like 'QGIS *' -and $_.Publisher -eq 'QGIS.org' -and
([string]$_.DisplayVersion).StartsWith($ltrSeries) -and
$_.PSChildName -match '^\{[0-9A-Fa-f-]+\}$'
})
foreach ($entry in $entries) {
Write-Host "Uninstalling $($entry.DisplayName) ($($entry.PSChildName))"
$process = Start-Process msiexec.exe -ArgumentList "/x $($entry.PSChildName) /qn /norestart" -PassThru -Wait
# 1605 = the release was already uninstalled
if (($successCodes + 1605) -notcontains $process.ExitCode) {
Write-Host "Uninstall of $($entry.DisplayName) failed with exit code $($process.ExitCode)"
Exit $process.ExitCode
}
}

$installProcess = Start-Process msiexec.exe `
-ArgumentList "/quiet /norestart /lv `"${logFile}`" /i `"${env:INSTALLER_PATH}`"" `
-PassThru -Verb RunAs -Wait

Get-Content $logFile -Tail 500

if ($successCodes -contains $installProcess.ExitCode) {
Exit 0
}

Exit $installProcess.ExitCode

} catch {
Write-Host "Error: $_"
Exit 1
}
Loading
Loading