Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion cmd/maintained-apps/validate/app_commander.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type AppCommander struct {
Name string
Slug string
UniqueIdentifier string
ExistsQuery string
Version string
AppPath string
UninstallScript string
Expand Down Expand Up @@ -94,7 +95,7 @@ func (ac *AppCommander) uninstallApp(ctx context.Context) bool {
}
ac.appLogger.DebugContext(ctx, fmt.Sprintf("Output: %s", output))

existance, err := appExists(ctx, ac.appLogger, ac.Name, ac.UniqueIdentifier, ac.Version, ac.AppPath)
existance, err := appExists(ctx, ac.appLogger, ac.Name, ac.UniqueIdentifier, ac.Version, ac.AppPath, ac.ExistsQuery)
if err != nil {
ac.appLogger.ErrorContext(ctx, fmt.Sprintf("Error checking if app exists after uninstall: %v", err))
return false
Expand Down
2 changes: 1 addition & 1 deletion cmd/maintained-apps/validate/darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func checkVersionMatch(expectedVersion, foundVersion, foundBundledVersion string
return false
}

func appExists(ctx context.Context, logger *slog.Logger, appName, uniqueAppIdentifier, appVersion, appPath string) (bool, error) {
func appExists(ctx context.Context, logger *slog.Logger, appName, uniqueAppIdentifier, appVersion, appPath, _ string) (bool, error) {
execTimeout, cancel := context.WithTimeout(ctx, 30*time.Second)
defer cancel()

Expand Down
15 changes: 14 additions & 1 deletion cmd/maintained-apps/validate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ func run(cfg *Config) error {
ac.Name = app.Name
ac.Slug = app.Slug
ac.UniqueIdentifier = app.UniqueIdentifier
ac.ExistsQuery = maintainedApp.AutomaticInstallQuery
// default version to maintained app version
ac.Version = maintainedApp.Version
ac.InstallScript = maintainedApp.InstallScript
Expand Down Expand Up @@ -240,7 +241,7 @@ func run(cfg *Config) error {
warnApp()
}

existance, err := appExists(ctx, appLogger, ac.Name, ac.UniqueIdentifier, ac.Version, ac.AppPath)
existance, err := appExists(ctx, appLogger, ac.Name, ac.UniqueIdentifier, ac.Version, ac.AppPath, ac.ExistsQuery)
if err != nil {
appLogger.ErrorContext(ctx, fmt.Sprintf("Error checking if app exists: %v", err))
appWithError = append(appWithError, ac.Name)
Expand Down Expand Up @@ -493,3 +494,15 @@ func validateSqlInput(input string) error {

return nil
}

var programsExistsQueryRegex = regexp.MustCompile(`(?is)^\s*SELECT\s+1\s+FROM\s+programs\s+WHERE\s+(.+?);?\s*$`)

// programsExistsWhereClause returns the WHERE clause of an exists query shaped
// "SELECT 1 FROM programs WHERE ...", or "" for any other shape.
func programsExistsWhereClause(existsQuery string) string {
m := programsExistsQueryRegex.FindStringSubmatch(existsQuery)
if m == nil {
return ""
}
return m[1]
}
28 changes: 28 additions & 0 deletions cmd/maintained-apps/validate/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,31 @@ func TestValidateSqlInput(t *testing.T) {
})
}
}

func TestProgramsExistsWhereClause(t *testing.T) {
testCases := []struct {
query string
want string
}{
{"", ""},
{
"SELECT 1 FROM programs WHERE name LIKE 'QGIS %' AND publisher = 'QGIS.org' AND version LIKE '3.44.%';",
"name LIKE 'QGIS %' AND publisher = 'QGIS.org' AND version LIKE '3.44.%'",
},
{
"select 1 from programs where name = 'Foo'",
"name = 'Foo'",
},
{
"SELECT 1 FROM apps WHERE bundle_identifier = 'com.example.foo';",
"",
},
{
"SELECT 1 WHERE EXISTS (SELECT 1 FROM programs WHERE name = 'Foo') OR NOT EXISTS (SELECT 1 FROM system_info WHERE cpu_type LIKE 'ARM%');",
"",
},
}
for _, tc := range testCases {
require.Equal(t, tc.want, programsExistsWhereClause(tc.query), tc.query)
}
}
9 changes: 8 additions & 1 deletion cmd/maintained-apps/validate/windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func normalizeVersion(version string) string {
return strings.Join(parts, ".")
}

func appExists(ctx context.Context, logger *slog.Logger, appName, uniqueIdentifier, appVersion, appPath string) (bool, error) {
func appExists(ctx context.Context, logger *slog.Logger, appName, uniqueIdentifier, appVersion, appPath, existsQuery string) (bool, error) {
execTimeout, cancel := context.WithTimeout(ctx, 30*time.Second)
defer cancel()

Expand Down Expand Up @@ -70,6 +70,13 @@ func appExists(ctx context.Context, logger *slog.Logger, appName, uniqueIdentifi
if appPath != "" {
query += fmt.Sprintf(" OR install_location LIKE '%%%s%%'", appPath)
}
// Some DisplayNames contain neither the catalog name nor the
// unique_identifier (e.g. QGIS LTR installs as "QGIS 3.44.14 'Solothurn'"),
// so also match the manifest's exists query, which is how Fleet detects the
// app. It comes from the manifest, so it isn't run through validateSqlInput.
if clause := programsExistsWhereClause(existsQuery); clause != "" {
query += ` OR (` + clause + `)`
}
cmd := exec.CommandContext(execTimeout, "osqueryi", "--json", query)
output, err := cmd.CombinedOutput()
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions ee/maintained-apps/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ go run cmd/maintained-apps/main.go --slug="box-drive/windows" --debug
| `install_script_path` | string | Filepath to a custom install script (`.ps1`). Overrides the generated install script. Script must be placed in `inputs/winget/scripts/`. For `.msi` apps, the ingestor automatically generates install scripts. Do not add scripts unless you need to override the generated behavior. For `.exe` apps, you must provide PowerShell scripts that run the installer file directly. Fleet stores the installer and sends it to the host at install time; your script must execute it using the `INSTALLER_PATH` environment variable. |
| `uninstall_script_path` | string | Filepath to a custom uninstall script (`.ps1`). Overrides the generated uninstall script. Script must be placed in `inputs/winget/scripts/`. For `.msi` apps, the ingestor automatically generates uninstall scripts. Do not add scripts unless you need to override the generated behavior. For `.exe` apps, you must provide a script to uninstall the app. Scripts for `.exe` apps are vendor-specific. Use the vendor’s documented silent uninstall switch or the registered UninstallString (if available), ensuring the script runs silently and returns the installer’s exit code. |
| `fuzzy_match_name` | boolean | If the `unique_identifier` doesn't match the `DisplayName`, use `fuzzy_match_name` to specify that Fleet uses "fuzzy matching" to match the Fleet-maintained app and the inventoried software. For example, for Pritunl, the `unique_identifier` is "Pritunl" and the inventories software's `DisplayName` is "Pritunl Client". With `fuzzy_match_name` set to true, Pritunl app will be matched to the inventories software. |
| `ignore_upgrade_code` | boolean | Set to `true` when the vendor gives every MSI build a new `UpgradeCode` (e.g., QGIS). Fleet links a Windows Fleet-maintained app to its software title by upgrade code, so a per-build code would move the app to a new title with each update. With this set, the title is linked by `unique_identifier` instead, so give each app that sets it a distinct `unique_identifier`. |
| `requires_client_os` | boolean | Set to `true` when the installer refuses to run on Windows Server SKUs (e.g., Dell Display and Peripheral Manager). Fleet's ingestion ignores this field; CI reads it to route validation to the `windows-11-arm` runner (the only GitHub-hosted client-OS Windows runner) instead of the default Windows Server x64 runner. |

#### Windows troubleshooting
Expand Down
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)
}
if input.Token == "chatgpt" {
// The patch policy generated below inherits this match.
out.Queries.Exists = fmt.Sprintf("SELECT 1 FROM apps WHERE %s;", chatGPTBundleMatch(""))
Expand Down Expand Up @@ -389,10 +393,24 @@ func (i *brewIngester) ingestOne(ctx context.Context, input inputApp) (*maintain
chatGPTBundleMatch("a."),
)
}
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'",
}

// chatGPTBundleMatch matches the ChatGPT app under both of its bundle identifiers.
// OpenAI rebuilt ChatGPT on the Codex app, so current builds report com.openai.codex
// while hosts that haven't updated still report com.openai.chat. The discontinued
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", "kicad", "chatgpt", "4k-slideshow-maker", "4k-stogram", "4k-video-downloader", "4k-video-to-mp3", "4k-youtube-to-mp3", "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", "kicad", "chatgpt", "4k-slideshow-maker", "4k-stogram", "4k-video-downloader", "4k-video-to-mp3", "4k-youtube-to-mp3", "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: "kicad", UniqueIdentifier: "org.kicad.kicad", InstallerFormat: "dmg", Name: "KiCad", Slug: "kicad/darwin"}},
{"", inputApp{Token: "chatgpt", UniqueIdentifier: "com.openai.chat", InstallerFormat: "zip", Name: "ChatGPT Desktop", Slug: "chatgpt/darwin"}},
{"", inputApp{Token: "4k-slideshow-maker", UniqueIdentifier: "com.openmedia.4kslideshowmaker", InstallerFormat: "dmg", Name: "4K Slideshow Maker", Slug: "4k-slideshow-maker/darwin"}}, //nolint:gosec // G101: cask token, not a credential
Expand Down Expand Up @@ -266,6 +268,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,
)
case "chatgpt":
// ChatGPT reports com.openai.codex since OpenAI rebuilt it on the Codex app;
// older installs still report com.openai.chat, so both are matched. The
Expand Down Expand Up @@ -296,6 +311,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,
)
case "kicad":
// KiCad's editors also run as standalone apps nested in KiCad.app, so they count as open too.
require.Equal(t,
Expand Down
9 changes: 8 additions & 1 deletion ee/maintained-apps/ingesters/winget/ingester.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,9 @@ func (i *wingetIngester) ingestOne(ctx context.Context, input inputApp) (*mainta
}
}
}
if input.IgnoreUpgradeCode {
upgradeCode = ""
}
if uninstallScript == "" && upgradeCode != "" {
var err error
uninstallScript, err = buildUpgradeCodeBasedUninstallScript(upgradeCode)
Expand Down Expand Up @@ -657,7 +660,11 @@ type inputApp struct {
// (e.g. python.org installers report "3.14.5150.0" for version "3.14.5").
UseDisplayVersionForPatch bool `json:"use_display_version_for_patch"`
// Whether to use "no_check" instead of the app's hash (e.g. for non-pinned download URLs)
IgnoreHash bool `json:"ignore_hash"`
IgnoreHash bool `json:"ignore_hash"`
// IgnoreUpgradeCode leaves the MSI UpgradeCode out of the manifest, for apps that mint
// a new one every build (e.g. QGIS). Fleet resolves a Windows FMA's software title by
// its upgrade code, so a per-build code would move the app to a new title on each update.
IgnoreUpgradeCode bool `json:"ignore_upgrade_code"`
DefaultCategories []string `json:"default_categories"`
Frozen bool `json:"frozen"`
PatchPolicyPath string `json:"patch_policy_path"`
Expand Down
28 changes: 28 additions & 0 deletions ee/maintained-apps/ingesters/winget/ingester_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,29 @@ func TestIngestValidations(t *testing.T) {
upgradeCode: "{ABCDEF}",
},
},
{
name: "ignore upgrade code",
inputApp: inputApp{
Name: "Foo",
UniqueIdentifier: "Foo",
PackageIdentifier: "Foo",
InstallerArch: "x64",
Slug: "foo/windows",
InstallScriptPath: path.Join(tempDir, "install_script.ps1"),
UninstallScriptPath: path.Join(tempDir, "uninstall_script.ps1"),
InstallerType: "msi",
InstallerScope: "machine",
IgnoreUpgradeCode: true,
},
cfg: serverConfig{
productCode: "{ABCDEF}",
installerType: "msi",
installerScope: "machine",
installerArch: "x64",
installerProdCode: "{ACBDEF}",
upgradeCode: "{ABCDEF}",
},
},
{
name: "wrong installer type",
wantErr: "failed to find installer for app",
Expand Down Expand Up @@ -516,6 +539,11 @@ func TestIngestValidations(t *testing.T) {
if c.wantPatchedContains != "" {
require.Contains(t, out.Queries.Patched, c.wantPatchedContains)
}
if c.inputApp.IgnoreUpgradeCode {
require.Empty(t, out.UpgradeCode)
} else {
require.Equal(t, c.cfg.upgradeCode, out.UpgradeCode)
}
// The managed "is app open" query matches a process named "<title>.exe".
require.Equal(t,
"SELECT 1 WHERE NOT EXISTS (SELECT 1 FROM processes WHERE LOWER(name) = 'foo.exe');",
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"
Loading
Loading