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

+36
View File
@@ -0,0 +1,36 @@
//go:build !windows
package platform
import (
"os"
"os/exec"
"runtime"
"strings"
)
// IsElevated reports whether the process is running as root.
func IsElevated() bool { return os.Geteuid() == 0 }
// ConsoleUser returns the user logged in at the macOS GUI console. Homebrew
// refuses to run as root, so a root-context run (RMM, MDM) has to drop to this
// user to touch brew. Returns "" when there is no console user or on Linux.
func ConsoleUser() string {
if runtime.GOOS != "darwin" {
return ""
}
out, err := exec.Command("/usr/bin/stat", "-f", "%Su", "/dev/console").Output()
if err != nil {
return ""
}
u := strings.TrimSpace(string(out))
if u == "" || u == "root" {
return ""
}
return u
}
// PrivilegeHint explains how to obtain the rights deployr needs.
func PrivilegeHint() string {
return "re-run deployr with sudo, or configure passwordless sudo for the account your RMM uses"
}
+18
View File
@@ -0,0 +1,18 @@
package platform
import "golang.org/x/sys/windows"
// IsElevated reports whether the process holds an elevated token. Under the
// SYSTEM account (how RMM agents run scripts) this is true.
func IsElevated() bool {
tok := windows.GetCurrentProcessToken()
return tok.IsElevated()
}
// ConsoleUser is meaningless on Windows.
func ConsoleUser() string { return "" }
// PrivilegeHint explains how to obtain the rights deployr needs.
func PrivilegeHint() string {
return "run deployr from an elevated (Administrator) shell, or as SYSTEM via your RMM"
}
+151
View File
@@ -0,0 +1,151 @@
// Package platform answers the "where am I running and with what rights"
// questions: OS/arch, elevation, and the well-known directories deployr uses
// for logs, downloads and catalog overlays.
package platform
import (
"os"
"path/filepath"
"regexp"
"runtime"
"strings"
)
// OS returns the normalized operating system name: windows, darwin or linux.
func OS() string { return runtime.GOOS }
// Arch returns the normalized CPU architecture: amd64, arm64, 386, arm.
func Arch() string { return runtime.GOARCH }
// Supported reports whether deployr knows how to operate on this OS.
func Supported() bool {
switch runtime.GOOS {
case "windows", "darwin", "linux":
return true
}
return false
}
// Hostname is the machine name, or "unknown" when it cannot be determined.
func Hostname() string {
h, err := os.Hostname()
if err != nil || h == "" {
return "unknown"
}
return h
}
// DataDir is the machine-wide state directory. It falls back to a per-user
// directory when the system location is not writable, so an unelevated run
// still works for user-scope package managers.
func DataDir() string {
return firstWritable(systemDataDir(), userDir("deployr"))
}
// LogDir is where run logs are written.
func LogDir() string {
return firstWritable(systemLogDir(), filepath.Join(userDir("deployr"), "logs"))
}
// CacheDir holds downloaded installers.
func CacheDir() string {
return firstWritable(filepath.Join(systemDataDir(), "cache"), filepath.Join(userDir("deployr"), "cache"))
}
// CatalogDirs lists the directories scanned for catalog overlay files
// (*.yaml / *.yml), in increasing order of precedence.
func CatalogDirs() []string {
dirs := []string{filepath.Join(systemDataDir(), "catalog.d")}
if runtime.GOOS != "windows" {
dirs = append(dirs, "/etc/deployr/catalog.d")
}
dirs = append(dirs, filepath.Join(userDir("deployr"), "catalog.d"))
return dirs
}
func systemDataDir() string {
switch runtime.GOOS {
case "windows":
pd := os.Getenv("ProgramData")
if pd == "" {
pd = `C:\ProgramData`
}
return filepath.Join(pd, "Deployr")
case "darwin":
return "/Library/Application Support/Deployr"
default:
return "/var/lib/deployr"
}
}
func systemLogDir() string {
switch runtime.GOOS {
case "windows":
return filepath.Join(systemDataDir(), "logs")
case "darwin":
return "/Library/Logs/Deployr"
default:
return "/var/log/deployr"
}
}
func userDir(name string) string {
base, err := os.UserCacheDir()
if err != nil || base == "" {
base = os.TempDir()
}
return filepath.Join(base, name)
}
// firstWritable returns the first candidate directory that exists or can be
// created, falling back to the last candidate unconditionally.
func firstWritable(candidates ...string) string {
for i, dir := range candidates {
if dir == "" {
continue
}
if err := os.MkdirAll(dir, 0o755); err == nil {
return dir
}
if i == len(candidates)-1 {
return dir
}
}
return os.TempDir()
}
var winVar = regexp.MustCompile(`%([A-Za-z_][A-Za-z0-9_()]*)%`)
// ExpandPath resolves ~, $VAR/${VAR} and Windows-style %VAR% in a path.
// Unset variables expand to empty, matching shell behaviour.
func ExpandPath(p string) string {
if p == "" {
return ""
}
if strings.HasPrefix(p, "~") {
if home, err := os.UserHomeDir(); err == nil {
p = filepath.Join(home, strings.TrimPrefix(p, "~"))
}
}
p = winVar.ReplaceAllStringFunc(p, func(m string) string {
return os.Getenv(strings.Trim(m, "%"))
})
p = os.ExpandEnv(p)
return filepath.Clean(p)
}
// PathExists reports whether a file or directory exists at the expanded path.
// Glob metacharacters are honoured so a catalog can match e.g.
// "%ProgramFiles%/Mozilla Firefox/firefox.exe".
func PathExists(p string) bool {
p = ExpandPath(p)
if p == "" {
return false
}
if strings.ContainsAny(p, "*?[") {
matches, err := filepath.Glob(p)
return err == nil && len(matches) > 0
}
_, err := os.Stat(p)
return err == nil
}
+98
View File
@@ -0,0 +1,98 @@
package platform
import (
"os"
"path/filepath"
"runtime"
"strings"
"testing"
)
func TestExpandPathWindowsStyleVariables(t *testing.T) {
t.Setenv("DEPLOYR_TEST_DIR", filepath.Join("C:", "Apps"))
got := ExpandPath("%DEPLOYR_TEST_DIR%/tool/bin.exe")
want := filepath.Clean(filepath.Join("C:", "Apps", "tool", "bin.exe"))
if got != want {
t.Errorf("ExpandPath = %q, want %q", got, want)
}
}
func TestExpandPathUnixStyleVariables(t *testing.T) {
t.Setenv("DEPLOYR_TEST_DIR", filepath.Join("/opt", "apps"))
got := ExpandPath("$DEPLOYR_TEST_DIR/tool")
want := filepath.Clean(filepath.Join("/opt", "apps", "tool"))
if got != want {
t.Errorf("ExpandPath = %q, want %q", got, want)
}
}
// Variable names with parentheses are common on Windows -- %ProgramFiles(x86)%
// is the one that matters -- so the expander has to accept them.
func TestExpandPathHandlesParenthesisedVariables(t *testing.T) {
t.Setenv("DEPLOYR_TEST(x86)", "/legacy")
got := ExpandPath("%DEPLOYR_TEST(x86)%/app")
if !strings.Contains(got, "legacy") {
t.Errorf("ExpandPath = %q, want it to contain the expanded value", got)
}
}
func TestExpandPathTilde(t *testing.T) {
home, err := os.UserHomeDir()
if err != nil {
t.Skip("no home directory in this environment")
}
if got := ExpandPath("~/deployr"); got != filepath.Clean(filepath.Join(home, "deployr")) {
t.Errorf("ExpandPath = %q", got)
}
}
func TestExpandPathEmpty(t *testing.T) {
if got := ExpandPath(""); got != "" {
t.Errorf("ExpandPath(\"\") = %q, want an empty string", got)
}
}
func TestPathExists(t *testing.T) {
dir := t.TempDir()
file := filepath.Join(dir, "present.txt")
if err := os.WriteFile(file, []byte("x"), 0o644); err != nil {
t.Fatal(err)
}
if !PathExists(file) {
t.Error("an existing file should be detected")
}
if PathExists(filepath.Join(dir, "absent.txt")) {
t.Error("a missing file should not be detected")
}
if !PathExists(filepath.Join(dir, "*.txt")) {
t.Error("a glob matching a file should be detected")
}
if PathExists(filepath.Join(dir, "*.log")) {
t.Error("a glob matching nothing should not be detected")
}
if PathExists("") {
t.Error("an empty path should not be detected")
}
}
func TestDirectoriesAreAbsolute(t *testing.T) {
for name, dir := range map[string]string{
"data": DataDir(),
"logs": LogDir(),
"cache": CacheDir(),
} {
if !filepath.IsAbs(dir) {
t.Errorf("%s dir %q is not absolute", name, dir)
}
}
if len(CatalogDirs()) == 0 {
t.Error("there should be at least one catalog overlay directory")
}
}
func TestSupported(t *testing.T) {
if !Supported() {
t.Errorf("%s should be a supported platform", runtime.GOOS)
}
}