zoopb/apt.go

80 lines
1.8 KiB
Go
Raw Normal View History

package zoopb
import (
"fmt"
"go.wit.com/log"
)
// init the installed package list
func (me *Machine) initPackages() {
// Get the list of installed packages for the detected distro
newP, err := getPackageList(me.Distro)
if err != nil {
fmt.Println("Error:", err)
return
}
2024-11-21 19:48:53 -06:00
if me.Packages == nil {
me.Packages = new(Packages)
}
// Print the installed packages and their versions
for pkg, version := range newP {
new1 := new(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")
}
}
2024-11-30 12:45:26 -06:00
log.Info(me.Hostname, "is", me.Distro, "with", me.Packages.Len(), "packages")
}
func (me *Machine) addNew(name string, version string) bool {
new1 := new(Package)
new1.Name = name
new1.Version = version
return me.Packages.Append(new1)
}
2024-12-01 22:37:23 -06:00
/*
2024-11-21 19:48:53 -06:00
func (me *Machine) UpdatePackages() string {
// Get the list of installed packages for the detected distro
newP, err := getPackageList(me.Distro)
if err != nil {
fmt.Println("Error:", err)
return fmt.Sprintln("getPackageList()", err)
}
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)
me.addNew(pkg, version)
newCounter += 1
} else {
found.Version = version
2024-12-01 18:18:11 -06:00
panic("redo this. broken after autogenpb. was never right anyway")
//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)
}
return footer
}
2024-12-01 22:37:23 -06:00
*/