From 31894509d503df68be49b244b55d8f97311d76ed Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Tue, 11 Sep 2018 12:09:34 +0200 Subject: Updater: add --dry-run parameter - go fmt pass --- tools/updater/main.go | 109 +++++++++++++++++++++++++------------------------- 1 file changed, 55 insertions(+), 54 deletions(-) (limited to 'tools/updater/main.go') 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) + } + } + } } -- cgit v1.2.1