diff options
Diffstat (limited to 'apt.go')
| -rw-r--r-- | apt.go | 49 |
1 files changed, 20 insertions, 29 deletions
@@ -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") } |
