A new "driver" provider installs Windows printer and scanner drivers through the same catalog, UI and profiles as everything else: stage the package into the driver store with pnputil, then register it with the print spooler so it turns up in Add Printer. Driver names are matched by PREFIX against the names read out of the package's own INF files. Vendors stamp the version into the name -- "HP Universal Printing PCL 6 (v7.1.0)" -- so an exact name in a catalog goes stale at the next release, and a wrong one is unrecoverable without knowing what the package contains. When a prefix matches nothing, the error lists the names the package actually provides, which turns a dead end into a one-line fix. INF parsing handles what real files are, not what the spec suggests: Windows ships its own printer INFs as UTF-16LE and vendor packages follow suit, so reading them as UTF-8 finds nothing at all. Verified against every prn*.inf on a stock Windows install -- that test is what caught the encoding bug, since the hand-written sample parsed fine. Scanners are TWAIN/WIA rather than spooler drivers, so there is nothing to register: leaving driver_match unset means stage-only. Detection falls back to the uninstall entry, because a TWAIN data source has no spooler record. Packages come from a driver share rather than the web. Vendor URLs are version-pinned and several are EULA-gated, so nothing stable can be shipped in a catalog; a UNC path or local folder is used in place with no download at all, which is faster and is what a shop wants anyway. $DEPLOYR_DRIVERS names the share, and an unset variable is reported by name rather than surfacing three layers down as "no such file". Ships universal drivers for HP, Xerox, Ricoh, Sharp, Canon, Kyocera, Konica Minolta, Lexmark, Brother, Toshiba, Epson, Muratec and Zebra, plus scanner packages for the fi series, ScanSnap, Canon DR, Epson, Brother, Visioneer and Kodak Alaris. Profiles: @printers, @printers-all, @scanners. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
132 lines
3.8 KiB
Go
132 lines
3.8 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{})
|
|
register(&printerDriver{})
|
|
}
|
|
|
|
// 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
|
|
}
|