package main import ( "flag" "fmt" "os" "net/http" "bufio" "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) } } }