From eb0f0041640dbc84964c5fb11d84fa071cdb27d9 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Fri, 21 Sep 2018 22:12:26 +0200 Subject: Add updater notes to documentation --- tools/updater/main.go | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) (limited to 'tools') 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) } } -- cgit v1.2.1