diff --git a/config.go b/config.go index a8ee2ae..c34a7cc 100644 --- a/config.go +++ b/config.go @@ -252,7 +252,7 @@ func parseConfig() { 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) epoch := shell.Run("git log -1 --format=%at v" + version) diff --git a/main.go b/main.go index 8bb6166..8430b0c 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import "log" +import "fmt" import "os" import "time" import "reflect" @@ -97,6 +98,10 @@ func lookupAAAA(hostname string) string { func main() { 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 directory includes the default config file if there is not already one packrBox = packr.NewBox("./resources") diff --git a/update.go b/update.go index 782171a..3b36174 100644 --- a/update.go +++ b/update.go @@ -13,19 +13,7 @@ package main import "log" import "time" 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 "github.com/davecgh/go-spew/spew" @@ -36,17 +24,13 @@ import "git.wit.com/wit/shell" func update() { version := shell.Run("cat VERSION") - mirrorsBUILDDATE := shell.Chomp(wget("https://mirrors.wit.com/cloud/control-panel/linux/BUILDDATE")) - upstream := shell.Chomp(wget("https://mirrors.wit.com/cloud/control-panel/linux/VERSION")) + 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) epoch := time.Now().Unix() myBUILDDATE, _ := packrBox.FindString("BUILDDATE") - - if (! config.Dirty) { - // See if a newer version of this control panel exists - // if (epoch > time.now().Unix()) // seconds since epoch - } + myBUILDDATE = shell.Chomp(myBUILDDATE) log.Println() log.Println("version =", version) @@ -66,6 +50,29 @@ func update() { log.Println("runtime.GOARCH =", runtime.GOARCH) 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) } diff --git a/wget.go b/wget.go deleted file mode 100644 index a4fac3c..0000000 --- a/wget.go +++ /dev/null @@ -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 -}