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>
131 lines
3.7 KiB
Go
131 lines
3.7 KiB
Go
// Package provider wraps the package managers and installer formats deployr can
|
|
// drive. Every provider answers the same five questions — am I present, can I
|
|
// install, update, uninstall, and what version is here — so the engine can walk
|
|
// a catalog entry's sources without caring which route wins.
|
|
package provider
|
|
|
|
import (
|
|
"context"
|
|
"sort"
|
|
"strings"
|
|
"time"
|
|
|
|
"git.starwarslab.us/ATOM_IT/Deployr/internal/catalog"
|
|
"git.starwarslab.us/ATOM_IT/Deployr/internal/logx"
|
|
)
|
|
|
|
// Opts is the ambient configuration for a provider operation.
|
|
type Opts struct {
|
|
DryRun bool
|
|
Timeout time.Duration
|
|
Log *logx.Logger
|
|
CacheDir string
|
|
Arch string
|
|
RequireChecksum bool
|
|
// Detect carries the app's presence rules, which the direct provider needs
|
|
// to locate an uninstall entry it did not create.
|
|
Detect catalog.Detect
|
|
// KeepDownloads leaves fetched installers in the cache directory.
|
|
KeepDownloads bool
|
|
}
|
|
|
|
// Outcome describes what a provider actually did.
|
|
type Outcome struct {
|
|
// Version installed, when the provider can report it.
|
|
Version string
|
|
// RebootRequired is set when the installer returned 3010/1641.
|
|
RebootRequired bool
|
|
// NoOp is set when the request was already satisfied.
|
|
NoOp bool
|
|
// Message is a short human explanation, e.g. "already up to date".
|
|
Message string
|
|
}
|
|
|
|
// Provider is one install route.
|
|
type Provider interface {
|
|
// Name is the identifier used in catalog sources.
|
|
Name() string
|
|
// OSes lists the GOOS values this provider can operate on.
|
|
OSes() []string
|
|
// Label is a human description for `deployr doctor`.
|
|
Label() string
|
|
// Available reports whether this route is usable on this machine right now.
|
|
Available(ctx context.Context, o Opts) bool
|
|
// Install makes the package present.
|
|
Install(ctx context.Context, src catalog.Source, o Opts) (Outcome, error)
|
|
// Update brings an installed package to the latest version.
|
|
Update(ctx context.Context, src catalog.Source, o Opts) (Outcome, error)
|
|
// Uninstall removes the package.
|
|
Uninstall(ctx context.Context, src catalog.Source, o Opts) (Outcome, error)
|
|
// Query returns the version this provider believes is installed.
|
|
Query(ctx context.Context, src catalog.Source, o Opts) (string, bool)
|
|
}
|
|
|
|
var registry = map[string]Provider{}
|
|
|
|
func register(p Provider) { registry[p.Name()] = p }
|
|
|
|
func init() {
|
|
register(&winget{})
|
|
register(&choco{})
|
|
register(&brew{cask: false})
|
|
register(&brew{cask: true})
|
|
register(newApt())
|
|
register(&rpmMgr{name: "dnf", bins: []string{"dnf5", "dnf", "yum"}})
|
|
register(&rpmMgr{name: "zypper", bins: []string{"zypper"}})
|
|
register(&pacman{})
|
|
register(&flatpak{})
|
|
register(&snap{})
|
|
register(&direct{})
|
|
}
|
|
|
|
// Get returns the provider registered under name.
|
|
func Get(name string) (Provider, bool) {
|
|
p, ok := registry[strings.ToLower(strings.TrimSpace(name))]
|
|
return p, ok
|
|
}
|
|
|
|
// All returns every provider, sorted by name.
|
|
func All() []Provider {
|
|
out := make([]Provider, 0, len(registry))
|
|
for _, p := range registry {
|
|
out = append(out, p)
|
|
}
|
|
sort.Slice(out, func(i, j int) bool { return out[i].Name() < out[j].Name() })
|
|
return out
|
|
}
|
|
|
|
// ForOS returns the providers that can run on a GOOS, sorted by name.
|
|
func ForOS(goos string) []Provider {
|
|
var out []Provider
|
|
for _, p := range All() {
|
|
for _, os := range p.OSes() {
|
|
if os == goos {
|
|
out = append(out, p)
|
|
break
|
|
}
|
|
}
|
|
}
|
|
return out
|
|
}
|
|
|
|
// Names lists every registered provider name.
|
|
func Names() []string {
|
|
out := make([]string, 0, len(registry))
|
|
for name := range registry {
|
|
out = append(out, name)
|
|
}
|
|
sort.Strings(out)
|
|
return out
|
|
}
|
|
|
|
// Windows installers signal "done, but reboot" rather than failing.
|
|
const (
|
|
exitRebootInitiated = 1641
|
|
exitRebootRequired = 3010
|
|
)
|
|
|
|
func isRebootExit(code int) bool {
|
|
return code == exitRebootInitiated || code == exitRebootRequired
|
|
}
|