aboutsummaryrefslogtreecommitdiff
path: root/tools/updater/updater.go
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-02-09 16:54:50 +0100
committerAqua-sama <aqua@iserlohn-fortress.net>2018-02-09 16:54:50 +0100
commitec24323a8f7c060585bf7981e4ed431a3c177204 (patch)
tree79d419bb77881441786a6a4f14579dd8f9eaf1f5 /tools/updater/updater.go
parentConnected WebView::newBookmark signal (diff)
downloadsmolbote-ec24323a8f7c060585bf7981e4ed431a3c177204.tar.xz
Rewrote the updater
Diffstat (limited to 'tools/updater/updater.go')
-rw-r--r--tools/updater/updater.go145
1 files changed, 0 insertions, 145 deletions
diff --git a/tools/updater/updater.go b/tools/updater/updater.go
deleted file mode 100644
index 07be93a..0000000
--- a/tools/updater/updater.go
+++ /dev/null
@@ -1,145 +0,0 @@
-package main
-
-import (
- "fmt"
- "strings"
- "flag"
- "errors"
- "net/http"
- "os"
- "io"
- "io/ioutil"
- "encoding/json"
-)
-
-type VersionMeta struct {
- Poi VersionData `json:"poi"`
-}
-
-type VersionData struct {
- Version string `json:"version"`
- Patch int `json:"patch"`
- Commit string `json:"commit"`
-}
-
-func parseJson(name string) (ver VersionMeta, err error) {
- var reader io.Reader
-
- if strings.HasPrefix(name, "https://") {
- // Grabbing stuff over https
- resp, e := http.Get(name)
- if resp.StatusCode != 200 {
- e = errors.New("HTTP response not OK")
- }
- if e != nil {
- fmt.Println("| Error encountered getting version.json: ", e)
- }
- defer resp.Body.Close()
- reader = resp.Body
- err = e
-
- } else {
- // FIXME Assuming we're grabbing a local file
- r, e := os.Open(name)
- if e != nil {
- fmt.Println("| Error opening file: ", e)
- }
- defer r.Close()
- reader = r
- err = e
- }
-
- if err == nil {
- body, err := ioutil.ReadAll(reader)
- if err != nil {
- fmt.Println("| Error encountered reading body")
- }
-
- err = json.Unmarshal(body, &ver)
- }
-
- return
-}
-
-// left > right r -> 1
-// left = right r -> 0
-// left < right r -> -1
-func compareVersion(left, right string) (ret int) {
- if strings.Compare(left, right) == 0 {
- ret = 0
- return
- }
-
- l := strings.Split(left, ".")
- r := strings.Split(right, ".")
-
- for i := 0; i < 3; i++ {
- if l[i] > r[i] {
- ret = 1
- break
- } else if l[i] < r[i] {
- ret = -1
- break
- }
- }
-
- return
-}
-
-func main() {
- fmt.Println("[ smolbote updater ]")
-
- // read local version.json
- localFlag := flag.Bool("local", true, "Read local version.json")
- // read remote version.json
- remoteFlag := flag.Bool("remote", true, "Read remote version.json")
- // download update
- downloadFlag := flag.Bool("download", false, "Download update")
- // install update
- installFlag := flag.Bool("install", false, "Install update")
-
- flag.Parse()
-
- var local VersionMeta
- var remote VersionMeta
- var err error
-
- if *localFlag {
- fmt.Println("+ Reading local version.json")
- local, err = parseJson("version.json")
- if err == nil {
- fmt.Println(fmt.Sprintf("| Got poi [%s-%d-%s]", local.Poi.Version, local.Poi.Patch, local.Poi.Commit))
- } else {
- // there has been an error reading the local version.json
- *localFlag = false
- }
- fmt.Println("\\ done")
- }
-
- if *remoteFlag {
- fmt.Println("+ Reading remote version.json")
- remote, err = parseJson("https://neueland.iserlohn-fortress.net/smolbote/version")
- if err == nil {
- fmt.Println(fmt.Sprintf("| Got poi [%s-%d-%s]", remote.Poi.Version, remote.Poi.Patch, remote.Poi.Commit))
- }
-
- comp := compareVersion(local.Poi.Version, remote.Poi.Version)
- if comp >= 0 {
- fmt.Println("| poi up to poi")
- } else { // comp < 0
- fmt.Println("| poi out of poi")
- }
-
- fmt.Println("\\ done")
- }
-
- if *downloadFlag {
- fmt.Println("+ Downloading update")
- fmt.Println("\\ done")
- }
-
- if *installFlag {
- fmt.Println("+ Installing update")
- fmt.Println("\\ done")
- }
-}