aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/Updater.md24
-rw-r--r--tools/updater/main.go37
2 files changed, 43 insertions, 18 deletions
diff --git a/doc/Updater.md b/doc/Updater.md
new file mode 100644
index 0000000..595ec9c
--- /dev/null
+++ b/doc/Updater.md
@@ -0,0 +1,24 @@
+## Updater
+
+### Manifest
+~~~sh
+find windows/ -type f | xargs sha512sum | sed 's/windows\///' > windows-sha512.txt
+~~~
+
+### Building
+
+You can build for the current system using:
+~~~sh
+go build
+~~~
+
+You can also cross-compile for other systems by setting GOOS and GOARCH. For a
+list of supported platforms, use `go tool dist list`.
+~~~sh
+GOOS=windows GOARCH=amd64 go build
+~~~
+
+#### Removing debug information
+~~~sh
+strip updater
+~~~
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)
}
}