aboutsummaryrefslogtreecommitdiff
path: root/tools/updater/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'tools/updater/main.go')
-rw-r--r--tools/updater/main.go109
1 files changed, 55 insertions, 54 deletions
diff --git a/tools/updater/main.go b/tools/updater/main.go
index f4feb62..1b2cc4c 100644
--- a/tools/updater/main.go
+++ b/tools/updater/main.go
@@ -1,63 +1,64 @@
package main
import (
- "flag"
- "fmt"
- "os"
- "net/http"
- "bufio"
- "strings"
+ "bufio"
+ "flag"
+ "fmt"
+ "net/http"
+ "os"
+ "strings"
)
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")
- //dryRunFlag := flag.Bool("dry-run", false, "Dry run")
-
- flag.Parse()
-
- // 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)
- }
-
- response, err := http.Get(manifestPath)
- if err != nil {
- panic(err)
- }
- defer response.Body.Close()
-
- scanner := bufio.NewScanner(response.Body)
- for scanner.Scan() {
- s := strings.Split(scanner.Text(), " ")
-
- filepath := s[1]
- checksum := s[0]
-
- state, err := checkFile(filepath, checksum)
- if err != nil {
- panic(err)
- }
-
- if(state) {
- fmt.Printf("[%s] passed\n", filepath)
- } else {
- fmt.Printf("[%s] missing or mismatching\n", filepath)
- downloadFile(filepath, repoPath + filepath)
- }
- }
+ 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")
+ dryRunFlag := flag.Bool("dry-run", false, "Dry run: only check files, do not download")
+ flag.Parse()
+
+ // 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)
+ }
+
+ response, err := http.Get(manifestPath)
+ if err != nil {
+ panic(err)
+ }
+ defer response.Body.Close()
+
+ scanner := bufio.NewScanner(response.Body)
+ for scanner.Scan() {
+ s := strings.Split(scanner.Text(), " ")
+
+ filepath := s[1]
+ checksum := s[0]
+
+ state, err := checkFile(filepath, checksum)
+ if err != nil {
+ panic(err)
+ }
+
+ if state {
+ fmt.Printf("[%s] passed\n", filepath)
+ } else {
+ fmt.Printf("[%s] missing or mismatching\n", filepath)
+ if !*dryRunFlag {
+ downloadFile(filepath, repoPath+filepath)
+ }
+ }
+ }
}