summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apt.go30
-rw-r--r--argv.go15
-rw-r--r--doDebian.go1
-rw-r--r--doInstall.go131
-rw-r--r--doRdate.go4
-rw-r--r--doUpgrade.go23
-rw-r--r--exit.go7
-rw-r--r--main.go7
-rw-r--r--upgrade.go35
9 files changed, 172 insertions, 81 deletions
diff --git a/apt.go b/apt.go
new file mode 100644
index 0000000..ee7935f
--- /dev/null
+++ b/apt.go
@@ -0,0 +1,30 @@
+// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
+// Use of this source code is governed by the GPL 3.0
+
+package main
+
+import (
+ "go.wit.com/log"
+)
+
+func aptInstall(pkgname string) {
+ cmd := []string{"apt", "install", "-y", pkgname}
+ log.Info("Running:", cmd)
+ exitOnError(cmd)
+}
+
+func aptRemove(pkgname string) {
+ if pkgname == "mirrors.wit.com" {
+ return
+ }
+ cmd := []string{"apt", "remove", "-y", pkgname}
+ log.Info("Running:", cmd)
+ exitOnError(cmd)
+}
+
+func aptUpdate() {
+ cmd := []string{"apt", "update"}
+ exitOnError(cmd)
+
+ aptInstall("wit-tools")
+}
diff --git a/argv.go b/argv.go
index a8a656f..3393089 100644
--- a/argv.go
+++ b/argv.go
@@ -12,6 +12,7 @@ import (
"os"
"go.wit.com/lib/debugger"
+ "go.wit.com/lib/fhelp"
"go.wit.com/lib/gui/logsettings"
"go.wit.com/lib/gui/prep"
"go.wit.com/log"
@@ -29,6 +30,7 @@ type args struct {
Test *EmptyCmd `arg:"subcommand:test" help:"test build everything first"`
Clone *EmptyCmd `arg:"subcommand:repomap-clone" help:"go-clone from a gowebd repomap"`
Rdate *EmptyCmd `arg:"subcommand:rdate" help:"standard rdate"`
+ Zoo *EmptyCmd `arg:"subcommand:zoo" help:"WIT Private Cloud info"`
Upgrade *UpgradeCmd `arg:"subcommand:upgrade" help:"apt upgrade packages installed from mirrors.wit.com"`
RepoMap string `arg:"--repomap" help:"location of the repomap"`
Release bool `arg:"--release" help:"use go-deb --release"`
@@ -104,8 +106,19 @@ func (args) Appname() string {
}
func (a args) DoAutoComplete(pb *prep.Auto) {
+ base := []string{"--version", "build", "debian", "upgrade", "git", "--force"}
+ if _, err := fhelp.CheckCmd("zood"); err == nil {
+ base = append(base, "zoo")
+ }
+ if _, err := fhelp.CheckCmd("forge"); err == nil {
+ base = append(base, "forge")
+ }
+ if areSuperuser() {
+ base = append(base, "upgrade")
+ base = append(base, "rdate")
+ }
if pb.Cmd == "" {
- pb.Autocomplete3([]string{"--version", "push", "build", "debian", "upgrade", "macos", "git", "rdate", "--force"})
+ pb.Autocomplete3(base)
} else {
pb.SubCommand(pb.Goargs...)
}
diff --git a/doDebian.go b/doDebian.go
index 33e3f8d..ebdd4f3 100644
--- a/doDebian.go
+++ b/doDebian.go
@@ -44,6 +44,7 @@ func doDebian() {
me.forge.PrintForgedTable(found)
if argv.DryRun {
+ doInstallScan()
okExit("")
}
diff --git a/doInstall.go b/doInstall.go
index 42adc99..cac93d0 100644
--- a/doInstall.go
+++ b/doInstall.go
@@ -13,6 +13,37 @@ import (
"go.wit.com/log"
)
+func doInstallRepo(check *gitpb.Repo) error {
+ repotype := check.GetRepoType()
+ if repotype == "binary" || repotype == "plugin" {
+ // we only want to process things that can be compiled with 'go build'
+ } else {
+ // log.Info("skipping repo", check.GetGoPath(), repotype)
+ return nil
+ }
+
+ if me.forge.Config.IsReadOnly(check.GetGoPath()) {
+ // ignore read only stuff
+ return nil
+ }
+
+ if argv.Verbose {
+ verbose := []string{"-v", "-x"}
+ if err := me.forge.Install(check, verbose); err != nil {
+ log.Warn("INSTALL FAILED", check.GetGoPath(), err)
+ failed[check] = fmt.Sprintf("%s %s %v", "go install", check.GetGoPath(), err)
+ return err
+ }
+ } else {
+ if err := me.forge.Install(check, nil); err != nil {
+ log.Warn("INSTALL FAILED", check.GetGoPath(), err)
+ failed[check] = fmt.Sprintf("%s %s %v", "go install", check.GetGoPath(), err)
+ return err
+ }
+ }
+ return nil
+}
+
func doInstall() error {
initForge() // make sure forge is init'd here
@@ -147,33 +178,85 @@ func doInstall() error {
return nil
}
-func doInstallRepo(check *gitpb.Repo) error {
- repotype := check.GetRepoType()
- if repotype == "binary" || repotype == "plugin" {
- // we only want to process things that can be compiled with 'go build'
- } else {
- // log.Info("skipping repo", check.GetGoPath(), repotype)
- return nil
- }
+func doInstallScan() {
+ initForge() // make sure forge is init'd here
- if me.forge.Config.IsReadOnly(check.GetGoPath()) {
- // ignore read only stuff
- return nil
- }
+ all := me.forge.Repos.SortByFullPath()
+ for all.Scan() {
+ check := all.Next()
- if argv.Verbose {
- verbose := []string{"-v", "-x"}
- if err := me.forge.Install(check, verbose); err != nil {
- log.Warn("INSTALL FAILED", check.GetGoPath(), err)
- failed[check] = fmt.Sprintf("%s %s %v", "go install", check.GetGoPath(), err)
- return err
+ repotype := check.GetRepoType()
+ if repotype == "binary" || repotype == "plugin" {
+ // we only want to process things that can be compiled with 'go build'
+ } else {
+ // log.Info("skipping repo", check.GetGoPath(), repotype)
+ continue
}
- } else {
- if err := me.forge.Install(check, nil); err != nil {
- log.Warn("INSTALL FAILED", check.GetGoPath(), err)
- failed[check] = fmt.Sprintf("%s %s %v", "go install", check.GetGoPath(), err)
- return err
+
+ if me.forge.Config.IsReadOnly(check.GetGoPath()) {
+ // ignore read only stuff
+ continue
+ }
+
+ // var cmd []string
+ var start string
+ var end string
+
+ // add te repotype
+ end += check.GetRepoType()
+
+ manufactured := check.GetCurrentVersion()
+ ver := trimNonNumericFromStart(manufactured)
+ name := me.forge.Config.DebName(check.GetGoPath())
+ var realver string
+ if installedPackage := me.machine.FindInstalledByName(name); installedPackage != nil {
+ realver = installedPackage.Version
+ }
+ if actualp := me.machine.FindByVersion(name, ver); actualp != nil {
+ end += " (version match) " + actualp.Version + " " + ver + " "
+ state[check] = "on mirrors"
+ } else {
+ if realver != "" {
+ end += fmt.Sprintf(" (version miss) %s vs %s ", realver, ver)
+ }
+ // end += "" + ver + " "
+ }
+ if me.machine.IsInstalled(name) {
+ if actualp := me.machine.FindInstalledByName(name); actualp != nil {
+ if ver != actualp.Version {
+ end += "(installed " + actualp.Version + ") "
+ } else {
+ end += "(installed ok) "
+ }
+ } else {
+ end += "(installed) "
+ }
+ }
+
+ debname := name + "_" + ver + "_amd64.deb"
+ debnames[check] = debname
+ outdir := getOutdir(check)
+ _, err := os.Stat(filepath.Join(outdir, debname))
+ if err == nil {
+ // log.Info("exists", filepath.Join(outdir, debname))
+ state[check] = "in incoming"
+ } else {
+ // log.Info(debname, "does not exist")
+ }
+
+ if state[check] == "" {
+ state[check] = "need to build"
+ }
+ start = fmt.Sprintf("%-15s %-20s %-50s", state[check], ver, debname)
+
+ if state[check] == "need to build" {
+ end += " (will build) "
+ }
+
+ log.Info(start, end)
+ if name == "" {
+ // err := fmt.Sprintf("name is blank error %+v", repo)
+ log.Warn("name is blank error", check.GetGoPath())
}
}
- return nil
}
diff --git a/doRdate.go b/doRdate.go
index ac66119..a33b022 100644
--- a/doRdate.go
+++ b/doRdate.go
@@ -9,11 +9,11 @@ func doRdate() {
checkSuperuser()
if _, err := fhelp.CheckCmd("rdate"); err != nil {
- exitOnError([]string{"apt", "install", "rdate"})
+ aptInstall("rdate")
}
if _, err := fhelp.CheckCmd("hwclock"); err != nil {
- exitOnError([]string{"apt", "install", "util-linux-extra"})
+ aptInstall("util-linux-extra")
}
exitOnError([]string{"rdate", "rdate.grid.wit.com"})
diff --git a/doUpgrade.go b/doUpgrade.go
index fda9a04..61006b9 100644
--- a/doUpgrade.go
+++ b/doUpgrade.go
@@ -11,26 +11,18 @@ import (
)
func doUpgrade() error {
- var cmd []string
-
if !argv.DryRun {
checkSuperuser()
- cmd = []string{"apt", "update"}
- exitOnError(cmd)
-
- cmd = []string{"apt", "install", "wit-tools"}
- exitOnError(cmd)
+ aptUpdate()
}
me.machine, _ = zoopb.InitMachine()
- // doAptUpgrade()
fmt.Println("Installed Packages:")
loop := me.machine.Wit.SortByName()
for loop.Scan() {
p := loop.Next()
- // log.Info("apt install", p.Name)
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
@@ -56,17 +48,10 @@ func doUpgrade() error {
}
if argv.Force {
- cmd := []string{"apt", "remove", "-y", p.Name}
- log.Info("Running:", cmd)
- exitOnError(cmd)
-
- cmd = []string{"apt", "install", "-y", p.Name}
- log.Info("Running:", cmd)
- exitOnError(cmd)
+ aptRemove(p.Name)
+ aptInstall(p.Name)
} else {
- cmd := []string{"apt", "install", "-y", p.Name}
- log.Info("Running:", cmd)
- exitOnError(cmd)
+ aptInstall(p.Name)
}
}
okExit("installed")
diff --git a/exit.go b/exit.go
index 22054cc..9228476 100644
--- a/exit.go
+++ b/exit.go
@@ -18,6 +18,13 @@ func checkSuperuser() {
}
}
+func areSuperuser() bool {
+ if os.Getuid() == 0 {
+ return true
+ }
+ return false
+}
+
func exitOnError(cmd []string) {
var err error
log.Info("Running:", cmd)
diff --git a/main.go b/main.go
index bb60324..f68a334 100644
--- a/main.go
+++ b/main.go
@@ -60,6 +60,13 @@ func main() {
doUpgrade()
}
+ if argv.Zoo != nil {
+ if areSuperuser() {
+ exitOnErrorRealtime([]string{"journalctl", "-n", "100", "-f", "_SYSTEMD_UNIT=zood.service"})
+ }
+ okExit("do something here")
+ }
+
if argv.ListPkgs != nil {
doAptList()
log.DaemonMode(true)
diff --git a/upgrade.go b/upgrade.go
index ed44b12..286ad3d 100644
--- a/upgrade.go
+++ b/upgrade.go
@@ -9,41 +9,6 @@ import (
"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.machine.Wit.SortByName()
- for loop.Scan() {
- p := loop.Next()
- // log.Info("apt install", p.Name)
- if p.Name == "" {
- log.Info("something wrong. p.Name was blank", p)
- continue
- }
- if me.machine.IsInstalled(p.Name) {
- cmd := []string{"apt", "install", p.Name}
- if argv.DryRun {
- log.Info("--dry-run", cmd)
- } else {
- log.Info("Running:", cmd)
- shell.RunRealtime([]string{"apt", "install", p.Name})
- }
- }
- }
- okExit("installed")
-}
-*/
-
func doAptList() {
log.DaemonMode(true)
defer log.DaemonMode(false)