-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathbrook.tengo
116 lines (113 loc) · 3.6 KB
/
brook.tengo
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
os := import("os")
fmt := import("fmt")
text := import("text")
nami := import("nami")
json := import("json")
enum := import("enum")
b := nami.sh1(`curl`, `-L`, `https://api.github.com/repos/txthinking/brook/releases/latest`)
if is_error(b) {
fmt.println(b)
os.exit(1)
}
v := json.decode(b).tag_name
err := nami.write_file(text.join([nami.cache_dir, "version"], os.path_separator), v)
if is_error(err) {
fmt.println(err)
os.exit(1)
}
got := false
if nami.os == "darwin" && nami.arch == "arm64" {
got = true
err := nami.sh(`curl`, `-L`, `--progress-bar`, `/~https://github.com/txthinking/brook/releases/latest/download/brook_darwin_arm64`, `-o`, text.join([nami.cache_dir, "brook"], os.path_separator))
if is_error(err) {
fmt.println(err)
os.exit(1)
}
}
if nami.os == "darwin" && nami.arch == "amd64" {
got = true
err := nami.sh(`curl`, `-L`, `--progress-bar`, `/~https://github.com/txthinking/brook/releases/latest/download/brook_darwin_amd64`, `-o`, text.join([nami.cache_dir, "brook"], os.path_separator))
if is_error(err) {
fmt.println(err)
os.exit(1)
}
}
if nami.os == "windows" && nami.arch == "amd64" {
got = true
err := nami.sh(`curl`, `-L`, `--progress-bar`, `/~https://github.com/txthinking/brook/releases/latest/download/brook_windows_amd64.exe`, `-o`, text.join([nami.cache_dir, "brook.exe"], os.path_separator))
if is_error(err) {
fmt.println(err)
os.exit(1)
}
}
if nami.os == "linux" && (nami.arch == "amd64" || nami.arch == "arm64") {
got = true
i := []
c := []
joker := nami.sh1("which", "joker")
if joker != "" {
s := nami.sh1("joker", "list")
l := text.split(s, "\n")
for v in l {
l1 := text.re_split(`\s+`, text.trim_space(v), -1)
if is_error(l1) || len(l1) < 5 {
continue
}
if !text.has_suffix(l1[4], "brook") {
continue
}
i = append(i, l1[0])
c = append(c, text.join(enum.map(l1[4:], func(_, v){return "'"+v+"'"}), " "))
}
for v in i {
_ := nami.sh("joker", "stop", v)
}
err := nami.sh("sleep", "3")
if is_error(err) {
fmt.println(err)
os.exit(1)
}
}
if nami.arch == "amd64" {
err := nami.sh(`curl`, `-L`, `--progress-bar`, `/~https://github.com/txthinking/brook/releases/latest/download/brook_linux_amd64`, `-o`, text.join([nami.cache_dir, "brook"], os.path_separator))
if is_error(err) {
fmt.println(err)
os.exit(1)
}
}
if nami.arch == "arm64" {
err := nami.sh(`curl`, `-L`, `--progress-bar`, `/~https://github.com/txthinking/brook/releases/latest/download/brook_linux_arm64`, `-o`, text.join([nami.cache_dir, "brook"], os.path_separator))
if is_error(err) {
fmt.println(err)
os.exit(1)
}
}
err := nami.sh("cp", text.join([nami.cache_dir, "brook"], os.path_separator), text.join([nami.bin_dir, "brook"], os.path_separator))
if is_error(err) {
fmt.println(err)
os.exit(1)
}
err = nami.sh("cp", text.join([nami.cache_dir, "brook"], os.path_separator), text.join([nami.copied_dir, "brook"], os.path_separator))
if is_error(err) {
fmt.println(err)
os.exit(1)
}
err = nami.sh("chmod", "+x", text.join([nami.bin_dir, "brook"], os.path_separator))
if is_error(err) {
fmt.println(err)
os.exit(1)
}
if joker != "" {
for v in c {
err := nami.sh("sh", "-c", "joker " + v)
if is_error(err) {
fmt.println(err)
os.exit(1)
}
}
}
}
if !got {
fmt.println("brook does not support your OS or Arch now. PR welcome: /~https://github.com/txthinking/nami/blob/master/package")
os.exit(1)
}