diff --git a/.gitignore b/.gitignore index 96c791e..5ffb722 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ # built. what version was built, etc # TODO: find a better way (not via ldflags) resources/build +resources/BUILDDATE cloud-control-panel diff --git a/Makefile b/Makefile index f58f2e7..5fbd5b5 100644 --- a/Makefile +++ b/Makefile @@ -48,7 +48,9 @@ tag-version: git tag v${VERSION} git push --tags # https://mirrors.wit.com/cloud/control-panel/ - scp VERSION root@mirrors.wit.com:/data/mirrors/cloud/control-panel/ + scp VERSION root@mirrors.wit.com:/data/mirrors/cloud/control-panel/linux/ + # date +%s > resources/BUILDDATE + scp resources/BUILDDATE root@mirrors.wit.com:/data/mirrors/cloud/control-panel/linux/ scp README root@mirrors.wit.com:/data/mirrors/cloud/control-panel/ # should update every go dependancy (?) diff --git a/config.go b/config.go index 2aac3f8..a8ee2ae 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 := wget("https://mirrors.wit.com/cloud/control-panel/VERSION") upstream := shell.Chomp(buf) epoch := shell.Run("git log -1 --format=%at v" + version) @@ -297,6 +297,8 @@ 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/update.go b/update.go new file mode 100644 index 0000000..782171a --- /dev/null +++ b/update.go @@ -0,0 +1,71 @@ +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 "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" + +// +// This is what you call from main() +// +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")) + 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 + } + + log.Println() + log.Println("version =", version) + log.Println("upstream =", upstream) + log.Println("now() =", epoch) + log.Println("myBUILDDATE =", myBUILDDATE) + log.Println("upstreamEpoch =", upstreamEpoch) + log.Println("mirrorsBUILDDATE =", mirrorsBUILDDATE) + log.Println() + log.Println("config.Gitref =", config.Gitref) + log.Println("config.Goversion =", config.Goversion) + log.Println("config.Dirty =", config.Dirty) + 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() + + for {} + // os.Exit(0) +} diff --git a/wget.go b/wget.go index c0ca656..a4fac3c 100644 --- a/wget.go +++ b/wget.go @@ -16,35 +16,23 @@ import "bytes" import "io" /* -import "log" -import "os/user" -import "flag" -import "fmt" -import "runtime" -import "strings" -import "reflect" - -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" */ -func wget(url string) (*bytes.Buffer, error) { +func wget(url string) (*bytes.Buffer) { buf := new(bytes.Buffer) // Get the data resp, err := http.Get(url) if err != nil { - return buf, err + errChan <- err + return buf } defer resp.Body.Close() buf.ReadFrom(resp.Body) - // newStr := buf.String() - // tmp := string(resp.Body) - return buf, err + return buf } func wgetToFile(filepath string, url string) error {