1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
package main
import (
"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: 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)
}
}
}
}
|