summaryrefslogtreecommitdiff
path: root/apt.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-11-15 19:25:24 -0600
committerJeff Carr <[email protected]>2024-11-15 19:25:24 -0600
commit1e9ee55a8e098ada869fd5870c2eed9938421485 (patch)
tree32a154be37490abe2d9bcda240e5da8a3ae58bcc /apt.go
parent9e4045f35e7b037f60b0a89a4368b9c4f77aa48d (diff)
connects to zookeeper
Diffstat (limited to 'apt.go')
-rw-r--r--apt.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/apt.go b/apt.go
index bdac375..9f88164 100644
--- a/apt.go
+++ b/apt.go
@@ -30,3 +30,44 @@ func initPackages() {
log.Info(me.hostname, "has distro", me.distro, "with", me.packages.Len(), "packages installed")
}
+
+func addNew(name string, version string) bool {
+ new1 := new(zoopb.Package)
+ new1.Name = name
+ new1.Version = version
+ return me.packages.Append(new1)
+}
+
+func updatePackages() {
+ // Get the list of installed packages for the detected distro
+ newP, err := getPackageList(me.distro)
+ if err != nil {
+ fmt.Println("Error:", err)
+ return
+ }
+
+ var newCounter, changeCounter int
+ // Print the installed packages and their versions
+ for pkg, version := range newP {
+ found := me.packages.FindByName(pkg)
+ if found == nil {
+ log.Info("adding new", pkg, version)
+ addNew(pkg, version)
+ newCounter += 1
+ } else {
+ found.Version = version
+ if me.packages.Update(found) {
+ changeCounter += 1
+ }
+ }
+ }
+
+ footer := fmt.Sprintf("%s has distro %s with %d packages installed", me.hostname, me.distro, me.packages.Len())
+ if changeCounter != 0 {
+ footer += fmt.Sprintf(" (%d changed)", changeCounter)
+ }
+ if newCounter != 0 {
+ footer += fmt.Sprintf(" (%d new)", newCounter)
+ }
+ log.Info(footer)
+}