aboutsummaryrefslogtreecommitdiff
path: root/tools/updater
diff options
context:
space:
mode:
Diffstat (limited to 'tools/updater')
-rw-r--r--tools/updater/main.go37
1 files changed, 19 insertions, 18 deletions
diff --git a/tools/updater/main.go b/tools/updater/main.go
index 1b2cc4c..deaad87 100644
--- a/tools/updater/main.go
+++ b/tools/updater/main.go
@@ -5,7 +5,7 @@ import (
"flag"
"fmt"
"net/http"
- "os"
+ "runtime"
"strings"
)
@@ -13,32 +13,35 @@ func main() {
helpFlag := flag.Bool("help", false, "Show help information")
verboseFlag := flag.Bool("verbose", false, "Print more information")
repoFlag := flag.String("repo", "https://neueland.iserlohn-fortress.net/smolbote/downloads", "Repository path")
+ platformFlag := flag.String("platform", runtime.GOOS, "Platform")
dryRunFlag := flag.Bool("dry-run", false, "Dry run: only check files, do not download")
flag.Parse()
+ manifestPath := fmt.Sprintf("%s/%s-sha512.txt", *repoFlag, *platformFlag)
+ repoPath := fmt.Sprintf("%s/%s/", *repoFlag, *platformFlag)
+
// help flag --> show usage and exit
if *helpFlag {
fmt.Println("Usage:")
flag.PrintDefaults()
- os.Exit(0)
- }
- manifestPath := *repoFlag + "/windows-sha512.txt"
- repoPath := *repoFlag + "/windows/"
-
- if *verboseFlag {
- fmt.Println("repoFlag =", *repoFlag)
- fmt.Println("manifest =", manifestPath)
- fmt.Println("repoPath =", repoPath)
+ fmt.Println("Paths:")
+ fmt.Println(" manifest ", manifestPath)
+ fmt.Println(" repository ", repoPath)
+ return
}
response, err := http.Get(manifestPath)
if err != nil {
panic(err)
+ } else if response.StatusCode != 200 {
+ fmt.Printf("Could not get manifest: %s\n", response.Status)
+ return
}
defer response.Body.Close()
+ // read through manifest
scanner := bufio.NewScanner(response.Body)
for scanner.Scan() {
s := strings.Split(scanner.Text(), " ")
@@ -46,16 +49,14 @@ func main() {
filepath := s[1]
checksum := s[0]
- state, err := checkFile(filepath, checksum)
- if err != nil {
+ if same, err := checkFile(filepath, checksum); err != nil {
panic(err)
- }
-
- if state {
- fmt.Printf("[%s] passed\n", filepath)
} else {
- fmt.Printf("[%s] missing or mismatching\n", filepath)
- if !*dryRunFlag {
+ if *verboseFlag {
+ fmt.Printf("[%s]: %t\n", filepath, same)
+ }
+
+ if !same && !*dryRunFlag {
downloadFile(filepath, repoPath+filepath)
}
}