-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy path7z.tengo
73 lines (71 loc) · 3.12 KB
/
7z.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
os := import("os")
fmt := import("fmt")
text := import("text")
nami := import("nami")
json := import("json")
b := nami.sh1("sh", "-c", "curl https://7-zip.org/download.html | grep 'Download 7-Zip' | cut -d' ' -f3 | head -n 1")
if is_error(b) {
fmt.println(b)
os.exit(1)
}
v := text.trim_space(string(b))
if nami.os == "darwin" {
v = "21.07"
}
if nami.os == "linux" {
v = "23.01"
}
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" {
got = true
err := nami.sh("curl", "-L", "--progress-bar", "https://7-zip.org/a/7z"+text.replace(v, ".", "", 1)+"-mac.tar.xz", "-o", text.join([nami.tmp_dir, "_.txz"], os.path_separator))
if is_error(err) {
fmt.println(err)
os.exit(1)
}
nami.sh("rm", "-rf", text.join([nami.tmp_dir, "_"], os.path_separator))
nami.sh("mkdir", text.join([nami.tmp_dir, "_"], os.path_separator))
nami.sh("tar", "Jxvf", text.join([nami.tmp_dir, "_.txz"], os.path_separator), "-C", text.join([nami.tmp_dir, "_"], os.path_separator))
nami.sh("mv", text.join([nami.tmp_dir, "_", "7zz"], os.path_separator), text.join([nami.cache_dir, "7z"], os.path_separator))
}
if nami.os == "linux" && nami.arch == "amd64" {
got = true
err := nami.sh("curl", "-L", "--progress-bar", "https://7-zip.org/a/7z"+text.replace(v, ".", "", 1)+"-linux-x64.tar.xz", "-o", text.join([nami.tmp_dir, "_.txz"], os.path_separator))
if is_error(err) {
fmt.println(err)
os.exit(1)
}
nami.sh("rm", "-rf", text.join([nami.tmp_dir, "_"], os.path_separator))
nami.sh("mkdir", text.join([nami.tmp_dir, "_"], os.path_separator))
nami.sh("tar", "Jxvf", text.join([nami.tmp_dir, "_.txz"], os.path_separator), "-C", text.join([nami.tmp_dir, "_"], os.path_separator))
nami.sh("mv", text.join([nami.tmp_dir, "_", "7zzs"], os.path_separator), text.join([nami.cache_dir, "7z"], os.path_separator))
}
if nami.os == "linux" && nami.arch == "arm64" {
got = true
err := nami.sh("curl", "-L", "--progress-bar", "https://7-zip.org/a/7z"+text.replace(v, ".", "", 1)+"-linux-arm64.tar.xz", "-o", text.join([nami.tmp_dir, "_.txz"], os.path_separator))
if is_error(err) {
fmt.println(err)
os.exit(1)
}
nami.sh("rm", "-rf", text.join([nami.tmp_dir, "_"], os.path_separator))
nami.sh("mkdir", text.join([nami.tmp_dir, "_"], os.path_separator))
nami.sh("tar", "Jxvf", text.join([nami.tmp_dir, "_.txz"], os.path_separator), "-C", text.join([nami.tmp_dir, "_"], os.path_separator))
nami.sh("mv", text.join([nami.tmp_dir, "_", "7zzs"], os.path_separator), text.join([nami.cache_dir, "7z"], os.path_separator))
}
if nami.os == "windows" && nami.arch == "amd64" {
got = true
err := nami.sh("curl", "-L", "--progress-bar", "https://7-zip.org/a/7zr.exe", "-o", text.join([nami.cache_dir, "7z.exe"], os.path_separator))
if is_error(err) {
fmt.println(err)
os.exit(1)
}
}
if !got {
fmt.println("7z does not support your OS or Arch now. PR welcome: https://github.com/txthinking/nami/blob/master/package")
os.exit(1)
}