working on an auto-update methodology
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
44a34afe88
commit
e1b30b97cc
23
config.go
23
config.go
|
@ -19,6 +19,7 @@ import "runtime"
|
||||||
import "io/ioutil"
|
import "io/ioutil"
|
||||||
import "strings"
|
import "strings"
|
||||||
import "reflect"
|
import "reflect"
|
||||||
|
import "bytes"
|
||||||
|
|
||||||
import "github.com/golang/protobuf/jsonpb"
|
import "github.com/golang/protobuf/jsonpb"
|
||||||
import pb "git.wit.com/wit/witProtobuf"
|
import pb "git.wit.com/wit/witProtobuf"
|
||||||
|
@ -251,12 +252,34 @@ func parseConfig() {
|
||||||
config.Dirty = true
|
config.Dirty = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
buf, _ := wget("https://mirrors.wit.com/cloud/control-panel/VERSION")
|
||||||
|
upstream := chompBytesBuffer(buf)
|
||||||
|
|
||||||
|
_, epoch, _ := shell.Run("git log -1 --format=%at v" + version)
|
||||||
|
// epoch = chomp(epoch)
|
||||||
|
|
||||||
|
if (! config.Dirty) {
|
||||||
|
// See if a newer version of this control panel exists
|
||||||
|
|
||||||
|
// if (epoch > time.Date().Unix())
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Println("epoch =", epoch)
|
||||||
|
log.Println("version =", version)
|
||||||
|
log.Println("upstream =", upstream)
|
||||||
log.Println("tagref =", tagref)
|
log.Println("tagref =", tagref)
|
||||||
log.Println("config.Gitref =", config.Gitref)
|
log.Println("config.Gitref =", config.Gitref)
|
||||||
log.Println("config.Goversion =", config.Goversion)
|
log.Println("config.Goversion =", config.Goversion)
|
||||||
log.Println("config.Dirty =", config.Dirty)
|
log.Println("config.Dirty =", config.Dirty)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func chompBytesBuffer(buf *bytes.Buffer) string {
|
||||||
|
var bytesSplice []byte
|
||||||
|
bytesSplice = buf.Bytes()
|
||||||
|
|
||||||
|
return chomp(string(bytesSplice))
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: fix this to chomp \n \r NULL \t and ' '
|
// TODO: fix this to chomp \n \r NULL \t and ' '
|
||||||
func chomp(s string) string {
|
func chomp(s string) string {
|
||||||
// var bytesBuffer bytes.Buffer
|
// var bytesBuffer bytes.Buffer
|
||||||
|
|
|
@ -0,0 +1,68 @@
|
||||||
|
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 "os"
|
||||||
|
import "net/http"
|
||||||
|
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) {
|
||||||
|
buf := new(bytes.Buffer)
|
||||||
|
|
||||||
|
// Get the data
|
||||||
|
resp, err := http.Get(url)
|
||||||
|
if err != nil {
|
||||||
|
return buf, err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
buf.ReadFrom(resp.Body)
|
||||||
|
// newStr := buf.String()
|
||||||
|
// tmp := string(resp.Body)
|
||||||
|
return buf, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func wgetToFile(filepath string, url string) error {
|
||||||
|
// Get the data
|
||||||
|
resp, err := http.Get(url)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
// Create the file
|
||||||
|
out, err := os.Create(filepath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer out.Close()
|
||||||
|
|
||||||
|
// Write the body to file
|
||||||
|
_, err = io.Copy(out, resp.Body)
|
||||||
|
return err
|
||||||
|
}
|
Loading…
Reference in New Issue