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

+183
View File
@@ -0,0 +1,183 @@
package catalog
import "testing"
func TestEmbeddedCatalogLoads(t *testing.T) {
cat, err := Embedded()
if err != nil {
t.Fatalf("embedded catalog does not parse: %v", err)
}
if len(cat.Apps) == 0 {
t.Fatal("embedded catalog is empty")
}
}
// TestEveryTargetHasDetection guards the property the engine relies on to be
// idempotent: without detect rules it cannot tell an app is already installed.
func TestEveryTargetHasDetection(t *testing.T) {
cat, err := Embedded()
if err != nil {
t.Fatal(err)
}
for _, app := range cat.Apps {
for _, goos := range app.Platforms() {
if app.TargetFor(goos).Detect.Empty() {
t.Errorf("%s/%s has no detect rules", app.ID, goos)
}
}
}
}
func TestProfilesReferenceRealApps(t *testing.T) {
cat, err := Embedded()
if err != nil {
t.Fatal(err)
}
for name, members := range cat.Profiles {
if len(members) == 0 {
t.Errorf("profile %q is empty", name)
}
for _, id := range members {
if _, ok := cat.Get(id); !ok {
t.Errorf("profile %q references unknown app %q", name, id)
}
}
}
}
func TestResolveExpandsProfilesAndDeduplicates(t *testing.T) {
cat, err := Embedded()
if err != nil {
t.Fatal(err)
}
apps, unknown := cat.Resolve([]string{"@standard", "chrome", "chrome"})
if len(unknown) != 0 {
t.Fatalf("unexpected unknown names: %v", unknown)
}
seen := map[string]int{}
for _, a := range apps {
seen[a.ID]++
}
if seen["chrome"] != 1 {
t.Errorf("chrome resolved %d times, want 1", seen["chrome"])
}
if len(apps) < len(cat.Profiles["standard"]) {
t.Errorf("resolved %d apps, expected at least the %d in @standard", len(apps), len(cat.Profiles["standard"]))
}
}
func TestResolveReportsUnknownNames(t *testing.T) {
cat, err := Embedded()
if err != nil {
t.Fatal(err)
}
_, unknown := cat.Resolve([]string{"chrome", "definitely-not-an-app", "@nope"})
if len(unknown) != 2 {
t.Fatalf("got unknown=%v, want 2 entries", unknown)
}
}
func TestAliasesResolve(t *testing.T) {
cat, err := Embedded()
if err != nil {
t.Fatal(err)
}
app, ok := cat.Get("notepad++")
if !ok {
t.Fatal("alias notepad++ did not resolve")
}
if app.ID != "notepadplusplus" {
t.Errorf("alias resolved to %q", app.ID)
}
}
func TestOverlayReplacesAppAndAddsProfile(t *testing.T) {
base, err := Embedded()
if err != nil {
t.Fatal(err)
}
overlay, err := Parse([]byte(`
apps:
- id: chrome
name: Google Chrome
windows:
sources:
- provider: choco
id: googlechrome
detect:
registry: ["Google Chrome"]
profiles:
onboarding: [chrome]
`), "test overlay")
if err != nil {
t.Fatal(err)
}
base.merge(overlay)
base.reindex()
app, ok := base.Get("chrome")
if !ok {
t.Fatal("chrome missing after merge")
}
sources := app.Windows.Sources
if len(sources) != 1 || sources[0].Provider != "choco" {
t.Errorf("overlay did not replace the shipped entry: %+v", sources)
}
if app.Darwin != nil {
t.Error("overlay replace should be wholesale, not a deep merge")
}
if _, ok := base.Profiles["onboarding"]; !ok {
t.Error("overlay profile was not added")
}
}
func TestValidateRejectsBadEntries(t *testing.T) {
cases := map[string]string{
"missing id": "apps:\n - name: No ID\n windows:\n sources:\n - provider: winget\n id: X\n",
"no platforms": "apps:\n - id: x\n name: X\n",
"no sources": "apps:\n - id: x\n name: X\n windows:\n sources: []\n",
"direct wthout url": "apps:\n - id: x\n name: X\n windows:\n sources:\n - provider: direct\n kind: msi\n",
"provider no id": "apps:\n - id: x\n name: X\n windows:\n sources:\n - provider: winget\n",
}
for name, doc := range cases {
if _, err := Parse([]byte(doc), "test"); err == nil {
t.Errorf("%s: expected a validation error", name)
}
}
}
func TestParseRejectsUnknownFields(t *testing.T) {
// A typo in a catalog key must fail loudly rather than be ignored.
_, err := Parse([]byte("apps:\n - id: x\n name: X\n windowz:\n sources: []\n"), "test")
if err == nil {
t.Fatal("expected an error for an unknown field")
}
}
func TestSourceURLForArch(t *testing.T) {
src := Source{
URL: "https://example.test/default.msi",
URLs: map[string]string{"arm64": "https://example.test/arm.msi"},
}
if got := src.URLFor("arm64"); got != "https://example.test/arm.msi" {
t.Errorf("arm64 URL = %q", got)
}
if got := src.URLFor("amd64"); got != "https://example.test/default.msi" {
t.Errorf("amd64 fallback URL = %q", got)
}
}
func TestSourceSupportsArch(t *testing.T) {
unrestricted := Source{}
if !unrestricted.SupportsArch("riscv64") {
t.Error("a source with no arch list should support every arch")
}
restricted := Source{Arch: []string{"amd64"}}
if restricted.SupportsArch("arm64") {
t.Error("arm64 should not match an amd64-only source")
}
if !restricted.SupportsArch("amd64") {
t.Error("amd64 should match an amd64-only source")
}
}
File diff suppressed because it is too large. Load diff
+245
View File
@@ -0,0 +1,245 @@
package catalog
import (
_ "embed"
"fmt"
"os"
"path/filepath"
"sort"
"strings"
"gopkg.in/yaml.v3"
"git.starwarslab.us/ATOM_IT/Deployr/internal/platform"
)
//go:embed data/apps.yaml
var embeddedYAML []byte
// Parse reads a catalog document.
func Parse(data []byte, origin string) (*Catalog, error) {
var c Catalog
dec := yaml.NewDecoder(strings.NewReader(string(data)))
dec.KnownFields(true)
if err := dec.Decode(&c); err != nil {
return nil, fmt.Errorf("%s: %w", origin, err)
}
if err := c.validate(origin); err != nil {
return nil, err
}
return &c, nil
}
// Embedded returns the catalog compiled into the binary.
func Embedded() (*Catalog, error) {
c, err := Parse(embeddedYAML, "embedded catalog")
if err != nil {
return nil, err
}
c.reindex()
return c, nil
}
// Load returns the embedded catalog with overlays merged over it. Overlays are
// read from the well-known catalog.d directories and then from extra (files or
// directories), so an operator can add or override apps without rebuilding.
func Load(extra []string) (*Catalog, error) {
base, err := Embedded()
if err != nil {
return nil, err
}
var files []string
for _, dir := range platform.CatalogDirs() {
files = append(files, yamlFilesIn(dir)...)
}
for _, p := range extra {
p = platform.ExpandPath(p)
info, err := os.Stat(p)
if err != nil {
return nil, fmt.Errorf("catalog %q: %w", p, err)
}
if info.IsDir() {
files = append(files, yamlFilesIn(p)...)
} else {
files = append(files, p)
}
}
for _, f := range files {
data, err := os.ReadFile(f)
if err != nil {
return nil, fmt.Errorf("catalog %q: %w", f, err)
}
overlay, err := Parse(data, f)
if err != nil {
return nil, err
}
base.merge(overlay)
}
base.reindex()
return base, nil
}
func yamlFilesIn(dir string) []string {
var out []string
for _, pattern := range []string{"*.yaml", "*.yml"} {
matches, err := filepath.Glob(filepath.Join(dir, pattern))
if err == nil {
out = append(out, matches...)
}
}
sort.Strings(out)
return out
}
// merge applies an overlay: apps are replaced whole by ID, profiles by name.
// Replacing rather than deep-merging keeps overrides predictable — what you
// read in the overlay file is exactly what will run.
func (c *Catalog) merge(overlay *Catalog) {
for _, app := range overlay.Apps {
replaced := false
for i, existing := range c.Apps {
if strings.EqualFold(existing.ID, app.ID) {
c.Apps[i] = app
replaced = true
break
}
}
if !replaced {
c.Apps = append(c.Apps, app)
}
}
if len(overlay.Profiles) > 0 && c.Profiles == nil {
c.Profiles = map[string][]string{}
}
for name, apps := range overlay.Profiles {
c.Profiles[name] = apps
}
}
func (c *Catalog) validate(origin string) error {
seen := map[string]bool{}
for _, app := range c.Apps {
switch {
case app.ID == "":
return fmt.Errorf("%s: an app entry is missing an id", origin)
case seen[strings.ToLower(app.ID)]:
return fmt.Errorf("%s: duplicate app id %q", origin, app.ID)
case app.Name == "":
return fmt.Errorf("%s: app %q is missing a name", origin, app.ID)
case len(app.Platforms()) == 0:
return fmt.Errorf("%s: app %q defines no platform targets", origin, app.ID)
}
seen[strings.ToLower(app.ID)] = true
for _, goos := range app.Platforms() {
t := app.TargetFor(goos)
if len(t.Sources) == 0 {
return fmt.Errorf("%s: app %q has no %s sources", origin, app.ID, goos)
}
for i, s := range t.Sources {
if s.Provider == "" {
return fmt.Errorf("%s: app %q %s source %d has no provider", origin, app.ID, goos, i+1)
}
if s.Provider == "direct" && s.URL == "" && len(s.URLs) == 0 {
return fmt.Errorf("%s: app %q %s direct source has no url", origin, app.ID, goos)
}
if s.Provider != "direct" && s.ID == "" {
return fmt.Errorf("%s: app %q %s %s source has no id", origin, app.ID, goos, s.Provider)
}
}
}
}
return nil
}
func (c *Catalog) reindex() {
c.index = make(map[string]*App, len(c.Apps)*2)
for _, app := range c.Apps {
c.index[strings.ToLower(app.ID)] = app
for _, alias := range app.Aliases {
c.index[strings.ToLower(alias)] = app
}
}
sort.Slice(c.Apps, func(i, j int) bool {
return strings.ToLower(c.Apps[i].ID) < strings.ToLower(c.Apps[j].ID)
})
}
// Get looks up an app by ID or alias.
func (c *Catalog) Get(name string) (*App, bool) {
app, ok := c.index[strings.ToLower(strings.TrimSpace(name))]
return app, ok
}
// Resolve expands a list of command-line names into apps. A name prefixed with
// "@" refers to a profile. Unknown names are returned separately so the caller
// can report all of them at once rather than dying on the first.
func (c *Catalog) Resolve(names []string) (apps []*App, unknown []string) {
seen := map[string]bool{}
add := func(app *App) {
if !seen[app.ID] {
seen[app.ID] = true
apps = append(apps, app)
}
}
for _, raw := range names {
name := strings.TrimSpace(raw)
if name == "" {
continue
}
if strings.HasPrefix(name, "@") {
members, ok := c.Profiles[strings.TrimPrefix(name, "@")]
if !ok {
unknown = append(unknown, name)
continue
}
for _, m := range members {
if app, ok := c.Get(m); ok {
add(app)
} else {
unknown = append(unknown, m)
}
}
continue
}
if app, ok := c.Get(name); ok {
add(app)
continue
}
unknown = append(unknown, name)
}
return apps, unknown
}
// ForPlatform returns every app installable on the given GOOS.
func (c *Catalog) ForPlatform(goos string) []*App {
var out []*App
for _, app := range c.Apps {
if app.TargetFor(goos) != nil {
out = append(out, app)
}
}
return out
}
// Suggest returns catalog IDs similar to name, for "did you mean" output.
func (c *Catalog) Suggest(name string) []string {
name = strings.ToLower(strings.TrimPrefix(name, "@"))
var out []string
for _, app := range c.Apps {
id := strings.ToLower(app.ID)
if strings.Contains(id, name) || strings.Contains(name, id) ||
strings.Contains(strings.ToLower(app.Name), name) {
out = append(out, app.ID)
}
}
sort.Strings(out)
if len(out) > 5 {
out = out[:5]
}
return out
}
@@ -0,0 +1,75 @@
// This test needs internal/provider, which imports internal/catalog, so it
// lives in the external test package to avoid an import cycle.
package catalog_test
import (
"testing"
"git.starwarslab.us/ATOM_IT/Deployr/internal/catalog"
"git.starwarslab.us/ATOM_IT/Deployr/internal/provider"
)
// TestSourcesUseKnownProviders catches a typo in a catalog source before it
// turns into a runtime "unknown provider" on someone's endpoint.
func TestSourcesUseKnownProviders(t *testing.T) {
cat, err := catalog.Embedded()
if err != nil {
t.Fatal(err)
}
for _, app := range cat.Apps {
for _, goos := range app.Platforms() {
for _, src := range app.TargetFor(goos).Sources {
p, ok := provider.Get(src.Provider)
if !ok {
t.Errorf("%s/%s: unknown provider %q", app.ID, goos, src.Provider)
continue
}
supported := false
for _, os := range p.OSes() {
if os == goos {
supported = true
break
}
}
if !supported {
t.Errorf("%s: provider %q cannot run on %s", app.ID, src.Provider, goos)
}
}
}
}
}
// TestDirectSourcesAreInstallable checks the two rules the direct provider
// enforces at runtime: an exe needs silent switches, and a zip needs somewhere
// to go. Catching these here beats catching them on an endpoint.
func TestDirectSourcesAreInstallable(t *testing.T) {
cat, err := catalog.Embedded()
if err != nil {
t.Fatal(err)
}
for _, app := range cat.Apps {
for _, goos := range app.Platforms() {
for _, src := range app.TargetFor(goos).Sources {
if src.Provider != "direct" {
continue
}
kind := src.Kind
if kind == "" {
kind = provider.InferKind(src.URLFor("amd64"))
}
switch kind {
case "":
t.Errorf("%s/%s: cannot infer installer kind from %q; set kind", app.ID, goos, src.URL)
case "exe":
if len(src.SilentArgs) == 0 {
t.Errorf("%s/%s: exe source has no silent_args", app.ID, goos)
}
case "zip":
if src.Dest == "" && goos != "darwin" {
t.Errorf("%s/%s: zip source has no dest", app.ID, goos)
}
}
}
}
}
}
+178
View File
@@ -0,0 +1,178 @@
// Package catalog defines the application catalog: what deployr knows how to
// install, and by which route on each operating system.
package catalog
import (
"sort"
"strings"
)
// Catalog is a merged view of the embedded catalog plus any overlays.
type Catalog struct {
Apps []*App `yaml:"apps"`
Profiles map[string][]string `yaml:"profiles,omitempty"`
index map[string]*App
}
// App is one installable product.
type App struct {
ID string `yaml:"id"`
Name string `yaml:"name"`
Description string `yaml:"description,omitempty"`
Homepage string `yaml:"homepage,omitempty"`
Categories []string `yaml:"categories,omitempty"`
// Aliases are alternative names accepted on the command line.
Aliases []string `yaml:"aliases,omitempty"`
Windows *Target `yaml:"windows,omitempty"`
Darwin *Target `yaml:"darwin,omitempty"`
Linux *Target `yaml:"linux,omitempty"`
}
// Target is the per-OS install recipe.
type Target struct {
// Sources are tried in order; the first one whose provider is present on
// the machine wins, and a failure falls through to the next unless the
// caller asked for strict mode.
Sources []Source `yaml:"sources"`
// Detect is how we decide the app is already present, independent of
// which route installed it.
Detect Detect `yaml:"detect,omitempty"`
// Notes surface caveats to the operator (licensing, reboot, etc).
Notes string `yaml:"notes,omitempty"`
}
// Source is a single install route.
type Source struct {
// Provider is winget, choco, brew, cask, apt, dnf, pacman, zypper,
// flatpak, snap or direct.
Provider string `yaml:"provider"`
// ID is the package identifier for the provider.
ID string `yaml:"id,omitempty"`
// Args are extra arguments appended to the install command.
Args []string `yaml:"args,omitempty"`
// Arch restricts this source to specific GOARCH values.
Arch []string `yaml:"arch,omitempty"`
// Repo is an optional remote name (flatpak) or tap (brew).
Repo string `yaml:"repo,omitempty"`
// The fields below apply to the "direct" provider: a vendor download.
URL string `yaml:"url,omitempty"`
// URLs maps GOARCH to a download URL when the vendor ships per-arch builds.
URLs map[string]string `yaml:"urls,omitempty"`
// Kind is msi, exe, msu, dmg, pkg, deb, rpm or zip. Inferred from the URL
// when empty.
Kind string `yaml:"kind,omitempty"`
// SilentArgs are the vendor's unattended-install switches (exe installers).
SilentArgs []string `yaml:"silent_args,omitempty"`
// SHA256 pins the download. Evergreen "latest" URLs cannot be pinned, so
// this is optional unless --require-checksum is passed.
SHA256 string `yaml:"sha256,omitempty"`
// AppName is the bundle to copy out of a dmg/zip, e.g. "Firefox.app".
AppName string `yaml:"app_name,omitempty"`
// Dest is the extraction target for zip payloads.
Dest string `yaml:"dest,omitempty"`
// UninstallID lets uninstall fall back to a different identifier, e.g. the
// registry DisplayName for something installed from a vendor MSI.
UninstallID string `yaml:"uninstall_id,omitempty"`
}
// URLFor returns the download URL for a GOARCH.
func (s Source) URLFor(arch string) string {
if u, ok := s.URLs[arch]; ok && u != "" {
return u
}
if u, ok := s.URLs["default"]; ok && u != "" {
return u
}
return s.URL
}
// SupportsArch reports whether this source applies to the given GOARCH.
func (s Source) SupportsArch(arch string) bool {
if len(s.Arch) == 0 {
return true
}
for _, a := range s.Arch {
if strings.EqualFold(a, arch) {
return true
}
}
return false
}
// Detect describes presence checks that do not depend on a package manager.
type Detect struct {
// Commands are executables that must resolve on PATH.
Commands []string `yaml:"commands,omitempty"`
// Paths are files or directories (globs allowed, env vars expanded).
Paths []string `yaml:"paths,omitempty"`
// Registry are Windows uninstall-entry DisplayName prefixes.
Registry []string `yaml:"registry,omitempty"`
}
// Empty reports whether there is nothing to check.
func (d Detect) Empty() bool {
return len(d.Commands) == 0 && len(d.Paths) == 0 && len(d.Registry) == 0
}
// TargetFor returns the recipe for a GOOS, or nil when unsupported.
func (a *App) TargetFor(goos string) *Target {
switch goos {
case "windows":
return a.Windows
case "darwin":
return a.Darwin
case "linux":
return a.Linux
}
return nil
}
// Platforms lists the operating systems this app supports, sorted.
func (a *App) Platforms() []string {
var out []string
for _, goos := range []string{"windows", "darwin", "linux"} {
if a.TargetFor(goos) != nil {
out = append(out, goos)
}
}
return out
}
// HasCategory reports category membership, case-insensitively.
func (a *App) HasCategory(c string) bool {
for _, have := range a.Categories {
if strings.EqualFold(have, c) {
return true
}
}
return false
}
// Categories returns every category in the catalog, sorted and deduplicated.
func (c *Catalog) Categories() []string {
seen := map[string]bool{}
var out []string
for _, a := range c.Apps {
for _, cat := range a.Categories {
if !seen[cat] {
seen[cat] = true
out = append(out, cat)
}
}
}
sort.Strings(out)
return out
}
// ProfileNames returns profile names, sorted.
func (c *Catalog) ProfileNames() []string {
out := make([]string, 0, len(c.Profiles))
for name := range c.Profiles {
out = append(out, name)
}
sort.Strings(out)
return out
}