From fb372aad6f0cca032c1ed7577cd7747b4daca7fb Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 20 Jan 2025 01:40:14 -0600 Subject: code rearange --- buildDeb.go | 79 --------------------------------------------------------- doAptUpgrade.go | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++ doDebian.go | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ main.go | 26 ++----------------- 4 files changed, 151 insertions(+), 103 deletions(-) delete mode 100644 buildDeb.go create mode 100644 doAptUpgrade.go create mode 100644 doDebian.go diff --git a/buildDeb.go b/buildDeb.go deleted file mode 100644 index 2761eb7..0000000 --- a/buildDeb.go +++ /dev/null @@ -1,79 +0,0 @@ -package main - -import ( - "fmt" - "os" - "path/filepath" - - "go.wit.com/lib/protobuf/gitpb" - "go.wit.com/log" -) - -func buildDeb() { - if argv.DryRun { - return - } - log.DaemonMode(true) - defer log.DaemonMode(false) - - all := me.forge.Repos.SortByFullPath() - for all.Scan() { - var cmd []string - check := all.Next() - - if state[check] != "need to build" { - // log.Info("skipping build for", check.GetGoPath(), state[check]) - continue - } - - outdir := getOutdir(check) - os.MkdirAll(outdir, 0755) - - _, err := os.Stat(filepath.Join(outdir, debnames[check])) - if err == nil { - if debnames[check] == "" { - log.Info("something went wrong. .deb blank", check.GetGoPath()) - } - // already built - continue - } - - if argv.Release { - cmd = []string{"go-deb", "--release", "--auto", "--forge", check.GetGoPath(), "--dir", outdir} - } else { - cmd = []string{"go-deb", "--auto", "--no-gui", "--forge", check.GetGoPath(), "--dir", outdir} - } - if me.forge.Config.IsPrivate(check.GetGoPath()) { - cmd = []string{"go-deb", "--auto", "--forge", check.GetGoPath(), "--dir", outdir} - } - log.Info("build cmd:", cmd) - if r := check.RunRealtime(cmd); r.Error != nil { - log.Info("go-deb failed error:", r.Error, check.GetGoPath()) - failed[check] = fmt.Sprint("godeb failed", cmd, "with", r.Exit, r.Error) - } else if r.Exit != 0 { - log.Info("go-deb failed exit =", r.Exit, check.GetGoPath()) - failed[check] = fmt.Sprint("godeb failed", cmd, "with", r.Exit, r.Error) - } else { - log.Info("build worked") - } - } -} - -func getOutdir(repo *gitpb.Repo) string { - if repo.GetLastTag() != repo.GetMasterVersion() { - return "/home/jcarr/incoming-devel" - } - - if repo.GetCurrentBranchVersion() != repo.GetMasterVersion() { - return "/home/jcarr/incoming-devel" - } - - if repo.CheckDirty() { - return "/home/jcarr/incoming-devel" - } - - if me.forge.Config.IsPrivate(repo.GetGoPath()) { - return "/home/jcarr/incoming-private" - } - return "/home/jcarr/incoming" -} diff --git a/doAptUpgrade.go b/doAptUpgrade.go new file mode 100644 index 0000000..0245625 --- /dev/null +++ b/doAptUpgrade.go @@ -0,0 +1,70 @@ +package main + +import ( + "fmt" + + "go.wit.com/lib/gui/shell" + "go.wit.com/log" +) + +func doAptUpgrade() { + if argv.DryRun { + log.Info("--dry-run", []string{"apt", "update"}) + } else { + result := shell.Run([]string{"apt", "update"}) + if result.Error != nil { + log.Info("apt update error:", result.Error) + badExit(result.Error) + } + } + + fmt.Println("Installed Packages:") + loop := me.forge.Machine.Wit.SortByName() + for loop.Scan() { + p := loop.Next() + // log.Info("apt install", name) + if me.forge.Machine.IsInstalled(p.Name) { + if argv.DryRun { + log.Info("--dry-run", []string{"apt", "install", p.Name}) + } else { + shell.RunRealtime([]string{"apt", "install", p.Name}) + } + } + } + okExit("installed") +} + +func doAptList() { + log.DaemonMode(true) + defer log.DaemonMode(false) + fmt.Println("Installed Packages:") + loop := me.forge.Machine.Wit.SortByName() + for loop.Scan() { + p := loop.Next() + var end string + var version string + if me.forge.Config.IsPrivate(p.Name) { + end += "(private) " + } + if actualp := me.forge.Machine.FindVersion(p.Name, p.Version); actualp != nil { + // end += "(version match) " + } else { + end += "(version mismatch) " + actualp.Version + " " + version + " " + } + if actualp := me.forge.Machine.FindInstalledByName(p.Name); actualp != nil { + if p.Version != actualp.Version { + end += "(installed " + actualp.Version + " vs " + p.Version + ") " + } else { + end += "(installed ok) " + } + version = actualp.Version + } + if me.forge.Config.IsReadOnly(p.Name) { + // end += " (readonly) " + } else { + end += "(writable) " + } + log.Printf("%-30s %-8s %s\n", p.Name, p.Version, end) // p.PkgName) + } + okExit("") +} diff --git a/doDebian.go b/doDebian.go new file mode 100644 index 0000000..2761eb7 --- /dev/null +++ b/doDebian.go @@ -0,0 +1,79 @@ +package main + +import ( + "fmt" + "os" + "path/filepath" + + "go.wit.com/lib/protobuf/gitpb" + "go.wit.com/log" +) + +func buildDeb() { + if argv.DryRun { + return + } + log.DaemonMode(true) + defer log.DaemonMode(false) + + all := me.forge.Repos.SortByFullPath() + for all.Scan() { + var cmd []string + check := all.Next() + + if state[check] != "need to build" { + // log.Info("skipping build for", check.GetGoPath(), state[check]) + continue + } + + outdir := getOutdir(check) + os.MkdirAll(outdir, 0755) + + _, err := os.Stat(filepath.Join(outdir, debnames[check])) + if err == nil { + if debnames[check] == "" { + log.Info("something went wrong. .deb blank", check.GetGoPath()) + } + // already built + continue + } + + if argv.Release { + cmd = []string{"go-deb", "--release", "--auto", "--forge", check.GetGoPath(), "--dir", outdir} + } else { + cmd = []string{"go-deb", "--auto", "--no-gui", "--forge", check.GetGoPath(), "--dir", outdir} + } + if me.forge.Config.IsPrivate(check.GetGoPath()) { + cmd = []string{"go-deb", "--auto", "--forge", check.GetGoPath(), "--dir", outdir} + } + log.Info("build cmd:", cmd) + if r := check.RunRealtime(cmd); r.Error != nil { + log.Info("go-deb failed error:", r.Error, check.GetGoPath()) + failed[check] = fmt.Sprint("godeb failed", cmd, "with", r.Exit, r.Error) + } else if r.Exit != 0 { + log.Info("go-deb failed exit =", r.Exit, check.GetGoPath()) + failed[check] = fmt.Sprint("godeb failed", cmd, "with", r.Exit, r.Error) + } else { + log.Info("build worked") + } + } +} + +func getOutdir(repo *gitpb.Repo) string { + if repo.GetLastTag() != repo.GetMasterVersion() { + return "/home/jcarr/incoming-devel" + } + + if repo.GetCurrentBranchVersion() != repo.GetMasterVersion() { + return "/home/jcarr/incoming-devel" + } + + if repo.CheckDirty() { + return "/home/jcarr/incoming-devel" + } + + if me.forge.Config.IsPrivate(repo.GetGoPath()) { + return "/home/jcarr/incoming-private" + } + return "/home/jcarr/incoming" +} diff --git a/main.go b/main.go index b741233..7c52b7d 100644 --- a/main.go +++ b/main.go @@ -55,33 +55,11 @@ func main() { } if argv.Upgrade != nil { - if argv.DryRun { - log.Info("--dry-run", []string{"apt", "update"}) - } else { - result := shell.Run([]string{"apt", "update"}) - if result.Error != nil { - log.Info("apt update error:", result.Error) - badExit(result.Error) - } - } - - fmt.Println("Installed Packages:") - loop := me.forge.Machine.Wit.SortByName() - for loop.Scan() { - p := loop.Next() - // log.Info("apt install", name) - if me.forge.Machine.IsInstalled(p.Name) { - if argv.DryRun { - log.Info("--dry-run", []string{"apt", "install", p.Name}) - } else { - shell.RunRealtime([]string{"apt", "install", p.Name}) - } - } - } - okExit("installed") + doAptUpgrade() } if argv.ListPkgs != nil { + doAptList() log.DaemonMode(true) defer log.DaemonMode(false) fmt.Println("Installed Packages:") -- cgit v1.2.3