Deployr 0.1.0: cross-platform application deployment CLI

Replaces Ninite for endpoint software: one catalog, one command line, and the
same behaviour on Windows, macOS and Linux. Single static binary, no server and
no agent, driven from an RMM script runner or by hand.

- catalog of ~50 apps compiled into the binary, extendable with YAML overlays
  in catalog.d or via --catalog, no rebuild required
- providers: winget, choco, brew, cask, apt, dnf/yum, zypper, pacman, flatpak,
  snap, plus direct vendor downloads (msi/exe/msu/dmg/pkg/deb/rpm/zip/tar.gz/
  AppImage)
- sources are tried in order and fall through, so one catalog entry covers
  winget on Windows, a cask on macOS and the vendor .deb on Debian
- provider-independent detection (registry, paths, commands) makes runs
  idempotent even for software installed by hand
- unattended by construction: stdin closed, silent flags, per-command timeouts
- handles the traps that break naive wrappers: winget missing under SYSTEM,
  Homebrew refusing root, 1641/3010 reboot exits, "already installed" reported
  as failure
- --json summary on stdout with progress on stderr, and RMM-friendly exit codes
  (0 ok, 1 failed, 2 usage, 3 privileges)

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
ClaudeandClaude Opus 5 committed 2026-08-26 16:55:13 -05:00
commit 4909edee2d
40 files changed
+6714

No files matched your search

+97
View File
@@ -0,0 +1,97 @@
// Package detect decides whether an application is already present on the
// machine, independently of which package manager (if any) put it there.
package detect
import (
"context"
"os/exec"
"path/filepath"
"runtime"
"strings"
"time"
"git.starwarslab.us/ATOM_IT/Deployr/internal/catalog"
"git.starwarslab.us/ATOM_IT/Deployr/internal/platform"
"git.starwarslab.us/ATOM_IT/Deployr/internal/run"
)
// Entry is one Windows uninstall-registry record.
type Entry struct {
DisplayName string
DisplayVersion string
Publisher string
UninstallString string
QuietUninstallString string
}
// Installed evaluates the detect rules and reports presence plus, when it can
// be determined cheaply, the installed version.
func Installed(d catalog.Detect) (bool, string) {
if d.Empty() {
return false, ""
}
if len(d.Registry) > 0 && runtime.GOOS == "windows" {
if entry, ok := FindRegistry(d.Registry); ok {
return true, entry.DisplayVersion
}
}
for _, p := range d.Paths {
if platform.PathExists(p) {
return true, bundleVersion(p)
}
}
for _, c := range d.Commands {
if run.Available(c) {
return true, ""
}
}
return false, ""
}
// bundleVersion reads CFBundleShortVersionString from a macOS .app bundle.
// Everything else has no cheap, universal version probe, so we report none
// rather than guessing.
func bundleVersion(path string) string {
if runtime.GOOS != "darwin" {
return ""
}
path = platform.ExpandPath(path)
if !strings.HasSuffix(path, ".app") {
return ""
}
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
out, err := exec.CommandContext(ctx, "/usr/bin/defaults", "read",
filepath.Join(path, "Contents", "Info"), "CFBundleShortVersionString").Output()
if err != nil {
return ""
}
return strings.TrimSpace(string(out))
}
// FindRegistry returns the first Windows uninstall entry whose DisplayName
// matches one of the patterns. Matching is a case-insensitive prefix test, so
// "Google Chrome" matches "Google Chrome" and "Google Chrome (64-bit)" alike.
func FindRegistry(patterns []string) (Entry, bool) {
if runtime.GOOS != "windows" || len(patterns) == 0 {
return Entry{}, false
}
entries := RegistryEntries()
for _, pattern := range patterns {
p := strings.ToLower(strings.TrimSpace(pattern))
if p == "" {
continue
}
for _, e := range entries {
name := strings.ToLower(e.DisplayName)
if strings.HasPrefix(name, p) || strings.Contains(name, p) {
return e, true
}
}
}
return Entry{}, false
}
+6
View File
@@ -0,0 +1,6 @@
//go:build !windows
package detect
// RegistryEntries has nothing to read outside Windows.
func RegistryEntries() []Entry { return nil }
+72
View File
@@ -0,0 +1,72 @@
package detect
import (
"sync"
"golang.org/x/sys/windows/registry"
)
var (
regOnce sync.Once
regCache []Entry
)
// uninstallRoots covers 64-bit, 32-bit-on-64-bit and per-user installs. Missing
// any one of them is the classic reason a "not installed" check is wrong.
var uninstallRoots = []struct {
key registry.Key
path string
flags uint32
}{
{registry.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall`, registry.READ | registry.WOW64_64KEY},
{registry.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall`, registry.READ | registry.WOW64_32KEY},
{registry.CURRENT_USER, `SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall`, registry.READ},
}
// RegistryEntries reads the Windows uninstall registry once per process.
func RegistryEntries() []Entry {
regOnce.Do(func() {
seen := map[string]bool{}
for _, root := range uninstallRoots {
k, err := registry.OpenKey(root.key, root.path, root.flags)
if err != nil {
continue
}
names, err := k.ReadSubKeyNames(-1)
k.Close()
if err != nil {
continue
}
for _, name := range names {
sub, err := registry.OpenKey(root.key, root.path+`\`+name, root.flags)
if err != nil {
continue
}
display, _, err := sub.GetStringValue("DisplayName")
if err != nil || display == "" {
sub.Close()
continue
}
// System components and update patches are noise.
if v, _, err := sub.GetIntegerValue("SystemComponent"); err == nil && v == 1 {
sub.Close()
continue
}
e := Entry{DisplayName: display}
e.DisplayVersion, _, _ = sub.GetStringValue("DisplayVersion")
e.Publisher, _, _ = sub.GetStringValue("Publisher")
e.UninstallString, _, _ = sub.GetStringValue("UninstallString")
e.QuietUninstallString, _, _ = sub.GetStringValue("QuietUninstallString")
sub.Close()
key := display + "\x00" + e.DisplayVersion
if seen[key] {
continue
}
seen[key] = true
regCache = append(regCache, e)
}
}
})
return regCache
}