attempt to put BUILDTIME in packr resources/ dir

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2019-06-06 20:02:26 -07:00
parent 35c06f515b
commit 77c4c9d69e
4 changed files with 33 additions and 77 deletions

View File

@ -252,7 +252,7 @@ func parseConfig() {
config.Dirty = true config.Dirty = true
} }
buf := wget("https://mirrors.wit.com/cloud/control-panel/VERSION") buf := shell.Wget("https://mirrors.wit.com/cloud/control-panel/VERSION")
upstream := shell.Chomp(buf) upstream := shell.Chomp(buf)
epoch := shell.Run("git log -1 --format=%at v" + version) epoch := shell.Run("git log -1 --format=%at v" + version)

View File

@ -1,6 +1,7 @@
package main package main
import "log" import "log"
import "fmt"
import "os" import "os"
import "time" import "time"
import "reflect" import "reflect"
@ -97,6 +98,10 @@ func lookupAAAA(hostname string) string {
func main() { func main() {
go handleErrors() go handleErrors()
epoch := fmt.Sprintf("%d", time.Now().Unix())
shell.Write("./resources/BUILDDATE", epoch)
// for {}
// This puts all the files in that directory in the binary // This puts all the files in that directory in the binary
// This directory includes the default config file if there is not already one // This directory includes the default config file if there is not already one
packrBox = packr.NewBox("./resources") packrBox = packr.NewBox("./resources")

View File

@ -13,19 +13,7 @@ package main
import "log" import "log"
import "time" import "time"
import "runtime" import "runtime"
// import "os"
// import "os/user"
// import "flag"
// import "fmt"
// import "runtime/debug"
// import "io/ioutil"
// import "strings"
// import "reflect"
// import "bytes"
// import "sys"
// import "github.com/golang/protobuf/jsonpb"
// import pb "git.wit.com/wit/witProtobuf"
import "git.wit.com/wit/shell" import "git.wit.com/wit/shell"
// import "github.com/davecgh/go-spew/spew" // import "github.com/davecgh/go-spew/spew"
@ -36,17 +24,13 @@ import "git.wit.com/wit/shell"
func update() { func update() {
version := shell.Run("cat VERSION") version := shell.Run("cat VERSION")
mirrorsBUILDDATE := shell.Chomp(wget("https://mirrors.wit.com/cloud/control-panel/linux/BUILDDATE")) mirrorsBUILDDATE := shell.Chomp(shell.Wget("https://mirrors.wit.com/cloud/control-panel/linux/BUILDDATE"))
upstream := shell.Chomp(wget("https://mirrors.wit.com/cloud/control-panel/linux/VERSION")) upstream := shell.Chomp(shell.Wget("https://mirrors.wit.com/cloud/control-panel/linux/VERSION"))
upstreamEpoch := shell.Run("git log -1 --format=%at v" + upstream) upstreamEpoch := shell.Run("git log -1 --format=%at v" + upstream)
epoch := time.Now().Unix() epoch := time.Now().Unix()
myBUILDDATE, _ := packrBox.FindString("BUILDDATE") myBUILDDATE, _ := packrBox.FindString("BUILDDATE")
myBUILDDATE = shell.Chomp(myBUILDDATE)
if (! config.Dirty) {
// See if a newer version of this control panel exists
// if (epoch > time.now().Unix()) // seconds since epoch
}
log.Println() log.Println()
log.Println("version =", version) log.Println("version =", version)
@ -66,6 +50,29 @@ func update() {
log.Println("runtime.GOARCH =", runtime.GOARCH) log.Println("runtime.GOARCH =", runtime.GOARCH)
log.Println() log.Println()
for {} 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")
}
}
// for {}
// os.Exit(0) // os.Exit(0)
} }

56
wget.go
View File

@ -1,56 +0,0 @@
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
*/
import "os"
import "net/http"
import "bytes"
import "io"
/*
import "git.wit.com/wit/shell"
import "github.com/davecgh/go-spew/spew"
*/
func wget(url string) (*bytes.Buffer) {
buf := new(bytes.Buffer)
// Get the data
resp, err := http.Get(url)
if err != nil {
errChan <- err
return buf
}
defer resp.Body.Close()
buf.ReadFrom(resp.Body)
return buf
}
func wgetToFile(filepath string, url string) error {
// Get the data
resp, err := http.Get(url)
if err != nil {
return err
}
defer resp.Body.Close()
// Create the file
out, err := os.Create(filepath)
if err != nil {
return err
}
defer out.Close()
// Write the body to file
_, err = io.Copy(out, resp.Body)
return err
}