Files
ClaudeandClaude Opus 5 4909edee2d 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>
2026-08-26 16:55:13 -05:00

73 lines
2.0 KiB
Go

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
}