try to make the upgrade cross platform
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
a2e90b1e9e
commit
eeba0d7c0d
10
config.go
10
config.go
|
@ -16,15 +16,12 @@ import "os/user"
|
|||
import "flag"
|
||||
import "fmt"
|
||||
import "runtime"
|
||||
// import "runtime/debug"
|
||||
import "io/ioutil"
|
||||
import "strings"
|
||||
// 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"
|
||||
|
||||
|
@ -131,11 +128,13 @@ func PBtoJSON() string {
|
|||
return stuff
|
||||
}
|
||||
|
||||
/*
|
||||
func writeToFile(filename string, a string) {
|
||||
f, _ := os.Create(filename)
|
||||
f.WriteString(a)
|
||||
f.Close()
|
||||
}
|
||||
*/
|
||||
|
||||
func saveConfig() {
|
||||
filename := config.Filename
|
||||
|
@ -146,7 +145,8 @@ func saveConfig() {
|
|||
stuff, _ := marshaler.MarshalToString(config)
|
||||
log.Println(stuff)
|
||||
|
||||
writeToFile(filename, stuff)
|
||||
// writeToFile(filename, stuff)
|
||||
shell.Write(filename, stuff)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
28
upgrade.go
28
upgrade.go
|
@ -15,10 +15,30 @@ import "git.wit.com/wit/shell"
|
|||
|
||||
func upgrade() {
|
||||
filename := "cloud-control-panel"
|
||||
if runtime.GOOS == "windows" {
|
||||
filename = "cloud-control-panel.exe"
|
||||
}
|
||||
|
||||
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"
|
||||
|
||||
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"
|
||||
|
||||
mirrorsBUILDDATE := shell.Chomp(shell.Wget(builddateURL))
|
||||
epoch := time.Now().Unix()
|
||||
|
||||
|
@ -62,11 +82,11 @@ func upgrade() {
|
|||
log.Println("update() THERE IS A NEW UPSTREAM VERSION !!!")
|
||||
time.Sleep(time.Second * 2)
|
||||
shell.WgetToFile("/tmp/" + filename, filenameURL)
|
||||
shell.Run("chmod +x /tmp/cloud-control-panel")
|
||||
shell.Run("chmod +x /tmp/" + filename)
|
||||
|
||||
// execute the new version here and never return
|
||||
// TODO: figure out how to nohup here and properly exit
|
||||
shell.Exec("/tmp/cloud-control-panel")
|
||||
shell.Exec("/tmp/" + filename)
|
||||
os.Exit(0)
|
||||
} else {
|
||||
log.Println("update() UPSTREAM VERSION IS OLDER THAN THIS")
|
||||
|
|
Loading…
Reference in New Issue