Compare commits
No commits in common. "782a29b4fc3ea87d826a9e44ab5636b1b2d6c67e" and "9458636b69cbc6b8beaab8e87187df390f64c2db" have entirely different histories.
782a29b4fc
...
9458636b69
@ -4,7 +4,7 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
)
|
)
|
||||||
|
|
||||||
// PackageManager abstracts distro package handling.
|
// PackageManager is an abstraction over distro package tooling.
|
||||||
type PackageManager interface {
|
type PackageManager interface {
|
||||||
Distro() string
|
Distro() string
|
||||||
InstallPackages(pkgs ...string) error
|
InstallPackages(pkgs ...string) error
|
||||||
@ -16,12 +16,9 @@ type PackageManager interface {
|
|||||||
/* ------------------------------------------------------------------ */
|
/* ------------------------------------------------------------------ */
|
||||||
|
|
||||||
type aptManager struct {
|
type aptManager struct {
|
||||||
logf func(string, ...any) // logger from App
|
logf func(string, ...any)
|
||||||
updated bool // true after first apt-update
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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 {
|
func newPackageManager(logf func(string, ...any)) PackageManager {
|
||||||
return &aptManager{logf: logf}
|
return &aptManager{logf: logf}
|
||||||
}
|
}
|
||||||
@ -34,27 +31,11 @@ func (a *aptManager) ExecExists(bin string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *aptManager) InstallPackages(pkgs ...string) error {
|
func (a *aptManager) InstallPackages(pkgs ...string) error {
|
||||||
if len(pkgs) == 0 {
|
args := append([]string{"-y", "install"}, pkgs...)
|
||||||
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...,
|
|
||||||
)
|
|
||||||
cmd := exec.Command("apt-get", args...)
|
cmd := exec.Command("apt-get", args...)
|
||||||
cmd.Env = append(cmd.Env, "DEBIAN_FRONTEND=noninteractive")
|
cmd.Env = append(cmd.Env, "DEBIAN_FRONTEND=noninteractive")
|
||||||
|
cmd.Stdout = nil
|
||||||
|
cmd.Stderr = nil
|
||||||
a.logf("apt install %v", pkgs)
|
a.logf("apt install %v", pkgs)
|
||||||
return cmd.Run()
|
return cmd.Run()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user