From fca9b170f96623acbd12d5182a4aa59e2a909e24 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 6 Jun 2019 20:56:14 -0700 Subject: [PATCH] move VERSION into the go binary Signed-off-by: Jeff Carr --- Makefile | 4 +-- VERSION | 1 - config.go | 2 -- gui-debug.go | 3 +- gui-splash.go | 9 ++++-- main.go | 13 ++++---- resources/VERSION | 1 + update.go => upgrade.go | 66 +++++++++++++++++++++++++++++++++-------- 8 files changed, 70 insertions(+), 29 deletions(-) delete mode 100644 VERSION create mode 100644 resources/VERSION rename update.go => upgrade.go (52%) diff --git a/Makefile b/Makefile index 7afdddd..953c4ca 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ GITCOMMIT = $(shell git rev-list -1 HEAD) GOVERSION = $(shell go version | cut -d' ' -f 3) BUILDTIME = $(shell date -u --iso-8601=seconds) -VERSION = $(shell cat VERSION) +VERSION = $(shell cat resources/VERSION) GO111MODULE=on @@ -14,7 +14,7 @@ run: ./cloud-control-panel build: - go build -ldflags "-X main.GITCOMMIT=${GITCOMMIT} -X main.VERSION=${VERSION}" + go build -ldflags "-X main.GITCOMMIT=${GITCOMMIT}" default-config: config-delete echo loading the test config diff --git a/VERSION b/VERSION deleted file mode 100644 index 724e8d9..0000000 --- a/VERSION +++ /dev/null @@ -1 +0,0 @@ -0.6.18 diff --git a/config.go b/config.go index c34a7cc..7046ac5 100644 --- a/config.go +++ b/config.go @@ -297,8 +297,6 @@ func parseConfig() { // my pid (cross platform) p, err := os.FindProcess(os.Getpid()) // send signal (cross platform) return p.Signal(syscall.SIGTERM) - update() - // for {} // os.Exit(0) } diff --git a/gui-debug.go b/gui-debug.go index 5d20342..f5b8950 100644 --- a/gui-debug.go +++ b/gui-debug.go @@ -8,6 +8,7 @@ import "os/exec" import "strings" import "git.wit.com/wit/gui" +import "git.wit.com/wit/shell" // import pb "git.wit.com/wit/witProtobuf" import "github.com/davecgh/go-spew/spew" @@ -47,7 +48,7 @@ func debugClick(b *gui.GuiButton) { Ybox3 := gui.NewBox(Ybox1, gui.Yaxis, "subdomain Y1 test") gui.NewLabel(Ybox3, "git rev-list: " + config.Gitref) gui.NewLabel(Ybox3, "go build version: " + config.Goversion) - gui.NewLabel(Ybox3, "build date: " + BUILDTIME) + gui.NewLabel(Ybox3, "build date: " + shell.Chomp(config.Builddate)) Ybox2 := gui.NewBox(hardXbox, gui.Yaxis, "subdomain Y test") makeColorButton(Ybox2, nil, nil, "COLOR73", "COLOR73", nil) diff --git a/gui-splash.go b/gui-splash.go index d56922a..eb7df0d 100644 --- a/gui-splash.go +++ b/gui-splash.go @@ -4,6 +4,7 @@ import "log" import "runtime" import "git.wit.com/wit/gui" +import "git.wit.com/wit/shell" import "github.com/andlabs/ui" import _ "github.com/andlabs/ui/winmanifest" @@ -24,12 +25,16 @@ func showSplashBox(gw *gui.GuiWindow) *gui.GuiBox { gui.NewLabel(box,"OS: " + runtime.GOOS) } - gui.NewLabel(box, "Version: " + config.Version) + if (config.Dirty) { + gui.NewLabel(box, "Version: " + config.Version + " (dirty)") + } else { + gui.NewLabel(box, "Version: " + config.Version) + } if (config.Debug) { gui.NewLabel(box, "git rev-list: " + config.Gitref) gui.NewLabel(box, "go build version: " + config.Goversion) - gui.NewLabel(box, "build date: " + BUILDTIME) + gui.NewLabel(box, "build date: " + shell.Chomp(config.Builddate)) } button := makeButton(box, nil, nil, "OK", "AREA", splashClick) diff --git a/main.go b/main.go index 8430b0c..dfd7e5d 100644 --- a/main.go +++ b/main.go @@ -21,9 +21,9 @@ import "github.com/gobuffalo/packr" import "github.com/davecgh/go-spew/spew" var GITCOMMIT string // this is passed in as an ldflag -var GOVERSION string // this is passed in as an ldflag -var BUILDTIME string // this is passed in as an ldflag -var VERSION string // this is passed in as an ldflag +// var GOVERSION string // this is passed in as an ldflag +// var BUILDTIME string // this is passed in as an ldflag +// var VERSION string // this is passed in as an ldflag var State string // used as a State machine var sigChan chan os.Signal @@ -114,11 +114,8 @@ func main() { // golang application IMHO parseConfig() - if (config.Dirty) { - config.Version = VERSION + " (dirty)" - } else { - config.Version = VERSION - } + // this checks to see if there is a newer upstream version + upgrade() for key, foo := range config.Accounts { log.Println("FOUND ACCOUNT = ", key, foo) diff --git a/resources/VERSION b/resources/VERSION new file mode 100644 index 0000000..4528c7c --- /dev/null +++ b/resources/VERSION @@ -0,0 +1 @@ +0.6.19 diff --git a/update.go b/upgrade.go similarity index 52% rename from update.go rename to upgrade.go index 3b36174..dd91d2e 100644 --- a/update.go +++ b/upgrade.go @@ -1,13 +1,7 @@ package main /* - This simply parses the command line arguments using the default golang - package called 'flag'. This can be used as a simple template to parse - command line arguments in other programs. - - It puts everything in a 'config' Protobuf which I think is a good - wrapper around the 'flags' package and doesn't need a whole mess of - global variables + Check to see if there is a new version to upgrade */ import "log" @@ -18,12 +12,59 @@ import "git.wit.com/wit/shell" // import "github.com/davecgh/go-spew/spew" -// -// This is what you call from main() -// -func update() { - version := shell.Run("cat VERSION") +func upgrade() { + mirrorsBUILDDATE := shell.Chomp(shell.Wget("https://mirrors.wit.com/cloud/control-panel/linux/BUILDDATE")) + // When this binary was built + myBUILDDATE, _ := packrBox.FindString("BUILDDATE") + myBUILDDATE = shell.Chomp(myBUILDDATE) + myBUILDVERSION, _ := packrBox.FindString("VERSION") + myBUILDVERSION = shell.Chomp(myBUILDVERSION) + config.Version = myBUILDVERSION + config.Builddate = shell.Int64(myBUILDDATE) + + log.Println() + log.Println("config.Dirty =", config.Dirty) + log.Println() + log.Println("myBUILDVERSION =", myBUILDVERSION) + log.Println("myBUILDDATE =", myBUILDDATE) + log.Println("mirrorsBUILDDATE =", mirrorsBUILDDATE) + log.Println() + log.Println("runtime.Version =", runtime.Version()) + log.Println("Number of CPUs =", runtime.NumCPU()) + log.Println("Number of GoRoutines =", runtime.NumGoroutine()) + log.Println("runtime.GOARCH =", runtime.GOARCH) + log.Println() + + log.Println("update() compare", mirrorsBUILDDATE, "to", myBUILDDATE) + if (! config.Dirty) { + // See if a newer version of this control panel exists + // if (epoch > time.now().Unix()) // seconds since epoch + if (shell.Int(mirrorsBUILDDATE) > shell.Int(myBUILDDATE)) { + log.Println("update() THERE IS A NEW UPSTREAM VERSION !!!") + log.Println("update() THERE IS A NEW UPSTREAM VERSION !!!") + log.Println("update() THERE IS A NEW UPSTREAM VERSION !!!") + time.Sleep(time.Second * 2) + } else { + log.Println("update() UPSTREAM VERSION IS OLDER THAN THIS") + } + } else { + if (shell.Int(mirrorsBUILDDATE) > shell.Int(myBUILDDATE)) { + log.Println("update() dirty=true THERE IS A NEW UPSTREAM VERSION !!!") + log.Println("update() dirty=true THERE IS A NEW UPSTREAM VERSION !!!") + log.Println("update() dirty=true THERE IS A NEW UPSTREAM VERSION !!!") + time.Sleep(time.Second * 2) + } else { + log.Println("update() dirty=true UPSTREAM VERSION IS OLDER THAN THIS") + } + } + time.Sleep(time.Second) + + // for {} + // os.Exit(0) +} + +func updateDebug() { mirrorsBUILDDATE := shell.Chomp(shell.Wget("https://mirrors.wit.com/cloud/control-panel/linux/BUILDDATE")) upstream := shell.Chomp(shell.Wget("https://mirrors.wit.com/cloud/control-panel/linux/VERSION")) upstreamEpoch := shell.Run("git log -1 --format=%at v" + upstream) @@ -33,7 +74,6 @@ func update() { myBUILDDATE = shell.Chomp(myBUILDDATE) log.Println() - log.Println("version =", version) log.Println("upstream =", upstream) log.Println("now() =", epoch) log.Println("myBUILDDATE =", myBUILDDATE)