execute the downloaded ELF binary
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
93501675b9
commit
1d9a1ad652
|
@ -0,0 +1,20 @@
|
|||
package main
|
||||
|
||||
// import "os/exec"
|
||||
import "log"
|
||||
import "github.com/go-cmd/cmd"
|
||||
|
||||
func main() {
|
||||
p := cmd.NewCmdOptions(
|
||||
cmd.Options{
|
||||
Buffered: false,
|
||||
Streaming: false,
|
||||
},
|
||||
"/bin/bash",
|
||||
"ping",
|
||||
"localhost",
|
||||
)
|
||||
log.Println("cmd p = ", p)
|
||||
p.Start()
|
||||
// for {}
|
||||
}
|
3
main.go
3
main.go
|
@ -64,6 +64,9 @@ type myButtonInfo struct {
|
|||
// a good example of using interface{}
|
||||
// https://github.com/Jeffail/tunny
|
||||
|
||||
// details on the correct use of LockOSThread:
|
||||
// https://github.com/golang/go/wiki/LockOSThread
|
||||
|
||||
func onExit(err error) {
|
||||
log.Println("Sleep for 1 second")
|
||||
time.Sleep(1 * 1000 * 1000 * 1000)
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
93501675b9e225b1dcf09c2548a52edb2ca18c54
|
88
upgrade.go
88
upgrade.go
|
@ -5,6 +5,7 @@ package main
|
|||
*/
|
||||
|
||||
import "log"
|
||||
import "os"
|
||||
import "time"
|
||||
import "runtime"
|
||||
|
||||
|
@ -13,30 +14,44 @@ import "git.wit.com/wit/shell"
|
|||
// import "github.com/davecgh/go-spew/spew"
|
||||
|
||||
func upgrade() {
|
||||
mirrorsBUILDDATE := shell.Chomp(shell.Wget("https://mirrors.wit.com/cloud/control-panel/linux/BUILDDATE"))
|
||||
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()
|
||||
|
||||
// When this binary was built
|
||||
myBUILDDATE, _ := packrBox.FindString("BUILDDATE")
|
||||
myBUILDDATE = shell.Chomp(myBUILDDATE)
|
||||
myBUILDVERSION, _ := packrBox.FindString("VERSION")
|
||||
myBUILDVERSION = shell.Chomp(myBUILDVERSION)
|
||||
|
||||
config.Version = myBUILDVERSION
|
||||
config.Builddate = shell.Int64(myBUILDDATE)
|
||||
config.Goversion = runtime.Version()
|
||||
|
||||
log.Println()
|
||||
log.Println("config.Dirty =", config.Dirty)
|
||||
log.Println("config.Goversion =", config.Goversion)
|
||||
log.Println()
|
||||
log.Println("upstreamVERSION =", upstreamVERSION)
|
||||
log.Println("builddateURL =", builddateURL)
|
||||
log.Println("now() =", epoch)
|
||||
log.Println("myBUILDVERSION =", myBUILDVERSION)
|
||||
log.Println("myBUILDDATE =", myBUILDDATE)
|
||||
log.Println("mirrorsBUILDDATE =", mirrorsBUILDDATE)
|
||||
log.Println()
|
||||
|
||||
log.Println("config.Dirty =", config.Dirty)
|
||||
log.Println("config.Version =", config.Version)
|
||||
log.Println("config.Goversion =", config.Goversion)
|
||||
log.Println()
|
||||
log.Println()
|
||||
log.Println("Number of CPUs =", runtime.NumCPU())
|
||||
log.Println("Number of GoRoutines =", runtime.NumGoroutine())
|
||||
log.Println("runtime.GOARCH =", runtime.GOARCH)
|
||||
log.Println()
|
||||
|
||||
// https://github.com/go-cmd/cmd/issues/20
|
||||
// TODO: look at go-cmd ?
|
||||
log.Println("update() compare", mirrorsBUILDDATE, "to", myBUILDDATE)
|
||||
if (! config.Dirty) {
|
||||
// See if a newer version of this control panel exists
|
||||
|
@ -46,6 +61,13 @@ func upgrade() {
|
|||
log.Println("update() THERE IS A NEW UPSTREAM VERSION !!!")
|
||||
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")
|
||||
|
||||
// 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)
|
||||
} else {
|
||||
log.Println("update() UPSTREAM VERSION IS OLDER THAN THIS")
|
||||
}
|
||||
|
@ -61,59 +83,5 @@ func upgrade() {
|
|||
}
|
||||
time.Sleep(time.Second)
|
||||
|
||||
// for {}
|
||||
// os.Exit(0)
|
||||
}
|
||||
|
||||
func updateDebug() {
|
||||
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")
|
||||
myBUILDDATE = shell.Chomp(myBUILDDATE)
|
||||
|
||||
log.Println()
|
||||
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()
|
||||
|
||||
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)
|
||||
for {}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue