diff options
| author | Jeff Carr <[email protected]> | 2025-10-05 12:04:43 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-10-05 12:04:43 -0500 |
| commit | 71b54e6dd01fae2ecb5cc29890b12bbd1299aa6c (patch) | |
| tree | 88229d805725204cf0a7e1f05d77b22ab27d9ac2 | |
| parent | 47bbda6e304cb1cae8ee0a8ce5c840df8a47a5a9 (diff) | |
knows what to upgrade and what not to upgradev0.1.17
| -rw-r--r-- | apt.go | 4 | ||||
| -rw-r--r-- | doUpgrade.go | 61 |
2 files changed, 24 insertions, 41 deletions
@@ -50,5 +50,7 @@ func aptUpdate() { badExit(err) } - aptInstall("wit-tools") + if found := me.machine.FindInstalledByName("wit-tools"); found == nil { + aptInstall("wit-tools") + } } diff --git a/doUpgrade.go b/doUpgrade.go index 6fa6bdf..8dece7c 100644 --- a/doUpgrade.go +++ b/doUpgrade.go @@ -49,52 +49,33 @@ func doUpgrade() error { aptUpdate() } - var installed []string - - installable := zoopb.NewPackages() - fmt.Println("Installed Packages:") - loop := me.machine.Wit.SortByName() - for loop.Scan() { - p := loop.Next() - if p.Name == "" { - log.Infof("odd /var/lib/apt/ list parse error. p.Name was blank (should be the package name) p=%v\n", p) - continue - } - installable.Append(p) - if !me.machine.IsInstalled(p.Name) { - continue - } - - found := me.machine.FindInstalledByName(p.Name) - - if found.Version == p.Version { - log.Info("name version already installed", p.Name, found.Version) - if !argv.Force { - continue - } - } else { - log.Info("name ver diff", p.Name, found.Version, p.Version) - } - - if argv.DryRun { - log.Info("should install package", p.Name) - continue - } + me.machine.PrintTable(me.machine.Wit) - installed = append(installed, p.Name) - } - installable.PrintTable() - me.sh.GoodExit("") if argv.Force { // force remove the packages. can be used if binaries change but versions didn't - for _, pkgname := range installed { - aptRemove(pkgname) + for p := range me.machine.Wit.IterByName() { + if me.machine.IsInstalled(p.Name) { + aptRemove(p.Name) + } } } - for _, pkgname := range installed { - aptInstall(pkgname) + + for p := range me.machine.Wit.IterByName() { + if me.machine.WillUpgrade(p) { + if argv.DryRun { + log.Info("Would install here without --dry-run") + continue + } + if argv.Force { + aptInstall(p.Name) + continue + } + if _, err := aptInstall(p.Name); err != nil { + me.sh.BadExit("damn it", err) + } + } } - okExit("installed") + me.sh.GoodExit("installed") return nil } |
