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"
|
|
|
|
|
2021-08-09 00:35:28 -05:00
|
|
|
import "git.wit.org/wit/shell"
|
2019-06-06 20:56:15 -05:00
|
|
|
|
|
|
|
// 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"
|
2019-06-14 08:34:23 -05:00
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
filename = "cloud-control-panel.exe"
|
|
|
|
}
|
|
|
|
|
2021-08-09 00:35:28 -05:00
|
|
|
mirrors := "https://mirrors.wit.org/cloud/control-panel/"
|
2019-06-09 16:34:18 -05:00
|
|
|
upstreamVERSION := shell.Chomp(shell.Wget(mirrors + "VERSION"))
|
2019-06-14 08:34:23 -05:00
|
|
|
|
|
|
|
dir := "/v" + upstreamVERSION + "/linux/"
|
|
|
|
|
|
|
|
// TODO: confirm this is correct for MacOS and Windows
|
|
|
|
if runtime.GOOS == "linux" {
|
|
|
|
log.Println("upgrade() OS: Linux")
|
|
|
|
dir = "/v" + upstreamVERSION + "/linux/"
|
|
|
|
} else if runtime.GOOS == "windows" {
|
|
|
|
log.Println("upgrade() OS: Windows")
|
|
|
|
dir = "/v" + upstreamVERSION + "/windows/"
|
|
|
|
} else if runtime.GOOS == "darwin" {
|
|
|
|
log.Println("upgrade() OS: " + runtime.GOOS)
|
|
|
|
dir = "/v" + upstreamVERSION + "/macos/"
|
|
|
|
}
|
|
|
|
|
|
|
|
filenameURL := mirrors + dir + filename
|
|
|
|
builddateURL := mirrors + dir + "BUILDDATE"
|
|
|
|
|
2019-06-09 16:34:18 -05:00
|
|
|
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)
|
2019-06-14 08:34:23 -05:00
|
|
|
shell.Run("chmod +x /tmp/" + filename)
|
2019-06-09 16:34:18 -05:00
|
|
|
|
|
|
|
// execute the new version here and never return
|
|
|
|
// TODO: figure out how to nohup here and properly exit
|
2019-06-14 08:34:23 -05:00
|
|
|
shell.Exec("/tmp/" + filename)
|
2019-06-09 16:34:18 -05:00
|
|
|
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
|
|
|
}
|