Compare commits

..

No commits in common. "782a29b4fc3ea87d826a9e44ab5636b1b2d6c67e" and "9458636b69cbc6b8beaab8e87187df390f64c2db" have entirely different histories.

View File

@ -4,7 +4,7 @@ import (
"os/exec"
)
// PackageManager abstracts distro package handling.
// PackageManager is an abstraction over distro package tooling.
type PackageManager interface {
Distro() string
InstallPackages(pkgs ...string) error
@ -16,12 +16,9 @@ type PackageManager interface {
/* ------------------------------------------------------------------ */
type aptManager struct {
logf func(string, ...any) // logger from App
updated bool // true after first apt-update
logf func(string, ...any)
}
// newPackageManager is called once in app.go; the same instance is
// passed to every collector, so apt-update can be executed exactly once.
func newPackageManager(logf func(string, ...any)) PackageManager {
return &aptManager{logf: logf}
}
@ -34,27 +31,11 @@ func (a *aptManager) ExecExists(bin string) bool {
}
func (a *aptManager) InstallPackages(pkgs ...string) error {
if len(pkgs) == 0 {
return nil
}
// refresh package index only the first time we install anything
if !a.updated {
a.logf("apt update")
if err := exec.Command(
"apt-get", "-qq", "-y", "update",
).Run(); err != nil {
return err
}
a.updated = true
}
args := append(
[]string{"-qq", "-y", "--no-install-recommends", "install"},
pkgs...,
)
args := append([]string{"-y", "install"}, pkgs...)
cmd := exec.Command("apt-get", args...)
cmd.Env = append(cmd.Env, "DEBIAN_FRONTEND=noninteractive")
cmd.Stdout = nil
cmd.Stderr = nil
a.logf("apt install %v", pkgs)
return cmd.Run()
}