-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
97 lines (73 loc) · 1.48 KB
/
main.go
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package main
import (
"flag"
"fmt"
"log"
"os"
"sync"
)
var (
addonsDir string
debug bool
fast bool
headless bool
)
func init() {
flag.StringVar(&addonsDir, "addons-dir", "./addons", "Addons directory")
flag.BoolVar(&fast, "fast", false, "Run everything in parallel")
flag.BoolVar(&debug, "debug", false, "Debug output")
flag.BoolVar(&headless, "headless", false, "Run without Chrome GUI")
}
type downloadedAddon struct {
addon string
file string
sum string
}
func must(err error) {
if err != nil {
log.Fatal(err)
}
}
func main() {
flag.Parse()
cfg, err := ParseConfig(fmt.Sprintf("%s/addons.yaml", addonsDir))
must(err)
tmpDir := fmt.Sprintf("%s/tmp", addonsDir)
_ = os.Mkdir(tmpDir, os.ModePerm)
curse := Curse(tmpDir, debug, headless)
unpacker := NewUnpacker()
var wg sync.WaitGroup
urls := cfg.URLs
for _, addon := range cfg.CurseForge {
urls = append(urls, FormatURL(addon))
}
for _, url := range urls {
wg.Add(1)
f := func(url string) {
defer wg.Done()
file, sum, err := curse.DownloadFile(url)
must(err)
unpacker.AddFile(url, file, sum)
}
if fast {
go f(url)
} else {
f(url)
}
}
gh := GitHub(addonsDir)
for folder, name := range cfg.GitHub {
wg.Add(1)
go func(folder, name string) {
defer wg.Done()
err := gh.Update(folder, name)
must(err)
}(folder, name)
}
wg.Wait()
defer unpacker.Cleanup()
err = unpacker.Unpack(addonsDir)
must(err)
err = unpacker.SaveCache(addonsDir)
must(err)
}