2019-06-06 20:56:15 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
/*
|
2019-06-06 22:56:14 -05:00
|
|
|
Check to see if there is a new version to upgrade
|
2019-06-06 20:56:15 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
import "log"
|
2019-06-09 16:34:18 -05:00
|
|
|
import "os"
|
2019-06-06 20:56:15 -05:00
|
|
|
import "time"
|
|
|
|
import "runtime"
|
|
|
|
|
|
|
|
import "git.wit.com/wit/shell"
|
|
|
|
|
|
|
|
// import "github.com/davecgh/go-spew/spew"
|
|
|
|
|
2019-06-06 22:56:14 -05:00
|
|
|
func upgrade() {
|
2019-06-09 16:34:18 -05:00
|
|
|
filename := "cloud-control-panel"
|
|
|
|
mirrors := "https://mirrors.wit.com/cloud/control-panel/"
|
|
|
|
upstreamVERSION := shell.Chomp(shell.Wget(mirrors + "VERSION"))
|
|
|
|
filenameURL := mirrors + "linux/cloud-control-panel-v" + upstreamVERSION
|
|
|
|
builddateURL := mirrors + "linux/cloud-control-panel-v" + upstreamVERSION + ".BUILDDATE"
|
|
|
|
mirrorsBUILDDATE := shell.Chomp(shell.Wget(builddateURL))
|
|
|
|
epoch := time.Now().Unix()
|
2019-06-06 22:56:14 -05:00
|
|
|
|
2019-06-14 07:18:13 -05:00
|
|
|
myBUILDDATE, _ := packrBox.FindString("build.DATE")
|
2019-06-06 22:56:14 -05:00
|
|
|
myBUILDDATE = shell.Chomp(myBUILDDATE)
|
|
|
|
myBUILDVERSION, _ := packrBox.FindString("VERSION")
|
|
|
|
myBUILDVERSION = shell.Chomp(myBUILDVERSION)
|
2019-06-09 16:34:18 -05:00
|
|
|
|
2019-06-06 22:56:14 -05:00
|
|
|
config.Version = myBUILDVERSION
|
|
|
|
config.Builddate = shell.Int64(myBUILDDATE)
|
2019-06-06 23:23:43 -05:00
|
|
|
config.Goversion = runtime.Version()
|
2019-06-06 22:56:14 -05:00
|
|
|
|
|
|
|
log.Println()
|
2019-06-09 16:34:18 -05:00
|
|
|
log.Println("upstreamVERSION =", upstreamVERSION)
|
|
|
|
log.Println("builddateURL =", builddateURL)
|
|
|
|
log.Println("now() =", epoch)
|
2019-06-06 22:56:14 -05:00
|
|
|
log.Println("myBUILDVERSION =", myBUILDVERSION)
|
|
|
|
log.Println("myBUILDDATE =", myBUILDDATE)
|
|
|
|
log.Println("mirrorsBUILDDATE =", mirrorsBUILDDATE)
|
|
|
|
log.Println()
|
|
|
|
|
2019-06-06 20:56:15 -05:00
|
|
|
log.Println("config.Dirty =", config.Dirty)
|
2019-06-09 16:34:18 -05:00
|
|
|
log.Println("config.Version =", config.Version)
|
|
|
|
log.Println("config.Goversion =", config.Goversion)
|
|
|
|
log.Println()
|
2019-06-06 20:56:15 -05:00
|
|
|
log.Println()
|
|
|
|
log.Println("Number of CPUs =", runtime.NumCPU())
|
|
|
|
log.Println("Number of GoRoutines =", runtime.NumGoroutine())
|
|
|
|
log.Println("runtime.GOARCH =", runtime.GOARCH)
|
|
|
|
log.Println()
|
|
|
|
|
2019-06-09 16:34:18 -05:00
|
|
|
// https://github.com/go-cmd/cmd/issues/20
|
|
|
|
// TODO: look at go-cmd ?
|
2019-06-06 22:02:26 -05:00
|
|
|
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)
|
2019-06-09 16:34:18 -05:00
|
|
|
shell.WgetToFile("/tmp/" + filename, filenameURL)
|
|
|
|
shell.Run("chmod +x /tmp/cloud-control-panel")
|
|
|
|
|
|
|
|
// execute the new version here and never return
|
|
|
|
// TODO: figure out how to nohup here and properly exit
|
|
|
|
shell.Exec("/tmp/cloud-control-panel")
|
|
|
|
os.Exit(0)
|
2019-06-06 22:02:26 -05:00
|
|
|
} 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")
|
|
|
|
}
|
|
|
|
}
|
2019-06-09 16:34:18 -05:00
|
|
|
time.Sleep(time.Second)
|
2019-06-06 22:02:26 -05:00
|
|
|
|
2019-06-11 01:39:34 -05:00
|
|
|
// for {}
|
2019-06-06 20:56:15 -05:00
|
|
|
}
|