summaryrefslogtreecommitdiff
path: root/apt.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-11-15 18:11:52 -0600
committerJeff Carr <[email protected]>2024-11-15 18:11:52 -0600
commit9e4045f35e7b037f60b0a89a4368b9c4f77aa48d (patch)
tree48a33398f5437ca41f18b2c159af3a30a7a66ef1 /apt.go
parent76db985cf1c3ca4ff792b82f6209e00ba5679b58 (diff)
use zoopb protobufs
Diffstat (limited to 'apt.go')
-rw-r--r--apt.go49
1 files changed, 20 insertions, 29 deletions
diff --git a/apt.go b/apt.go
index 7369d62..bdac375 100644
--- a/apt.go
+++ b/apt.go
@@ -1,41 +1,32 @@
package main
import (
- "bufio"
- "os/exec"
- "strings"
+ "fmt"
+
+ "go.wit.com/lib/protobuf/zoopb"
+ "go.wit.com/log"
)
-func getInstalledPackages() (map[string]string, error) {
- // Run the dpkg-query command to list installed packages and versions
- cmd := exec.Command("dpkg-query", "-W", "-f=${Package} ${Version}\n")
- stdout, err := cmd.StdoutPipe()
+// init the installed package list
+func initPackages() {
+ // Get the list of installed packages for the detected distro
+ newP, err := getPackageList(me.distro)
if err != nil {
- return nil, err
- }
-
- // Start the command execution
- if err := cmd.Start(); err != nil {
- return nil, err
+ fmt.Println("Error:", err)
+ return
}
- defer cmd.Wait()
-
- // Create a map to store package names and versions
- installedPackages := make(map[string]string)
- // Use a scanner to read the output of the command line by line
- scanner := bufio.NewScanner(stdout)
- for scanner.Scan() {
- line := scanner.Text()
- // Split each line into package name and version
- parts := strings.SplitN(line, " ", 2)
- if len(parts) == 2 {
- packageName := parts[0]
- version := parts[1]
- installedPackages[packageName] = version
+ // Print the installed packages and their versions
+ for pkg, version := range newP {
+ new1 := new(zoopb.Package)
+ new1.Name = pkg
+ new1.Version = version
+ if me.packages.Append(new1) {
+ // log.Info("added", new1.Name, "ok")
+ } else {
+ log.Info("added", new1.Name, "failed")
}
}
- // Return the map with package names and versions
- return installedPackages, scanner.Err()
+ log.Info(me.hostname, "has distro", me.distro, "with", me.packages.Len(), "packages installed")
}