2024-11-15 01:22:47 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-11-15 18:11:52 -06:00
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"go.wit.com/lib/protobuf/zoopb"
|
|
|
|
"go.wit.com/log"
|
2024-11-15 01:22:47 -06:00
|
|
|
)
|
|
|
|
|
2024-11-15 18:11:52 -06:00
|
|
|
// init the installed package list
|
|
|
|
func initPackages() {
|
|
|
|
// Get the list of installed packages for the detected distro
|
|
|
|
newP, err := getPackageList(me.distro)
|
2024-11-15 01:22:47 -06:00
|
|
|
if err != nil {
|
2024-11-15 18:11:52 -06:00
|
|
|
fmt.Println("Error:", err)
|
|
|
|
return
|
2024-11-15 01:22:47 -06:00
|
|
|
}
|
|
|
|
|
2024-11-15 18:11:52 -06:00
|
|
|
// Print the installed packages and their versions
|
|
|
|
for pkg, version := range newP {
|
|
|
|
new1 := new(zoopb.Package)
|
|
|
|
new1.Name = pkg
|
|
|
|
new1.Version = version
|
2024-11-15 21:05:03 -06:00
|
|
|
if me.machine.Packages.Append(new1) {
|
2024-11-15 18:11:52 -06:00
|
|
|
// log.Info("added", new1.Name, "ok")
|
|
|
|
} else {
|
|
|
|
log.Info("added", new1.Name, "failed")
|
2024-11-15 01:22:47 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-11-18 09:41:08 -06:00
|
|
|
log.Info(me.hostname, "has distro", me.distro, "with", me.machine.Packages.Len(), "packages installed.")
|
2024-11-15 01:22:47 -06:00
|
|
|
}
|
2024-11-15 19:25:24 -06:00
|
|
|
|
|
|
|
func addNew(name string, version string) bool {
|
|
|
|
new1 := new(zoopb.Package)
|
|
|
|
new1.Name = name
|
|
|
|
new1.Version = version
|
2024-11-15 21:05:03 -06:00
|
|
|
return me.machine.Packages.Append(new1)
|
2024-11-15 19:25:24 -06:00
|
|
|
}
|
|
|
|
|
2024-11-18 09:41:08 -06:00
|
|
|
func updatePackages() string {
|
2024-11-15 19:25:24 -06:00
|
|
|
// Get the list of installed packages for the detected distro
|
|
|
|
newP, err := getPackageList(me.distro)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("Error:", err)
|
2024-11-18 09:41:08 -06:00
|
|
|
return fmt.Sprintln("getPackageList()", err)
|
2024-11-15 19:25:24 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
var newCounter, changeCounter int
|
|
|
|
// Print the installed packages and their versions
|
|
|
|
for pkg, version := range newP {
|
2024-11-15 21:05:03 -06:00
|
|
|
found := me.machine.Packages.FindByName(pkg)
|
2024-11-15 19:25:24 -06:00
|
|
|
if found == nil {
|
|
|
|
log.Info("adding new", pkg, version)
|
|
|
|
addNew(pkg, version)
|
|
|
|
newCounter += 1
|
|
|
|
} else {
|
|
|
|
found.Version = version
|
2024-11-15 21:05:03 -06:00
|
|
|
if me.machine.Packages.Update(found) {
|
2024-11-15 19:25:24 -06:00
|
|
|
changeCounter += 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-11-15 21:05:03 -06:00
|
|
|
footer := fmt.Sprintf("%s has distro %s with %d packages installed", me.hostname, me.distro, me.machine.Packages.Len())
|
2024-11-15 19:25:24 -06:00
|
|
|
if changeCounter != 0 {
|
|
|
|
footer += fmt.Sprintf(" (%d changed)", changeCounter)
|
|
|
|
}
|
|
|
|
if newCounter != 0 {
|
|
|
|
footer += fmt.Sprintf(" (%d new)", newCounter)
|
|
|
|
}
|
2024-11-18 09:41:08 -06:00
|
|
|
return footer
|
2024-11-15 19:25:24 -06:00
|
|
|
}
|