-
Notifications
You must be signed in to change notification settings - Fork 597
/
shared.jq
67 lines (65 loc) · 1.65 KB
/
shared.jq
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
# converts a bashbrew architecture to apk's strings
def apkArch:
{
# https://dl-cdn.alpinelinux.org/alpine/edge/main/
# https://wiki.alpinelinux.org/wiki/Architecture#Alpine_Hardware_Architecture_.28.22arch.22.29_Support
# https://pkgs.alpinelinux.org/packages ("Arch" dropdown)
amd64: "x86_64",
arm32v6: "armhf",
arm32v7: "armv7",
arm64v8: "aarch64",
i386: "x86",
ppc64le: "ppc64le",
riscv64: "riscv64",
s390x: "s390x",
}[.]
;
# RUN set -eux; \
# ...
# {{
# download({
# arches: .arches,
# urlKey: "dockerUrl",
# #sha256Key: "sha256",
# target: "docker.tgz",
# #missingArchWarning: true,
# })
# }}; \
# ...
def download(opts):
(opts.sha256Key | not) as $notSha256
| [
"apkArch=\"$(apk --print-arch)\";
case \"$apkArch\" in"
,
(
opts.arches | to_entries[]
| .key as $bashbrewArch
| ($bashbrewArch | apkArch) as $apkArch
| .value
| .[opts.urlKey] as $url
| (if $notSha256 then "none" else .[opts.sha256Key] end) as $sha256
| select($apkArch and $url and $sha256)
| ("
\($apkArch | @sh))
url=\($url | @sh);"
+ if $notSha256 then "" else "
sha256=\($sha256 | @sh);"
end + "
;;"
)
)
,
"
*) echo >&2 \"\(if opts.missingArchWarning then "warning" else "error" end): unsupported \(opts.target | @sh) architecture ($apkArch)\(if opts.missingArchWarning then "; skipping" else "" end)\"; exit \(if opts.missingArchWarning then 0 else 1 end) ;;
esac;
wget -O \(opts.target | @sh) \"$url\";"
,
if $notSha256 then "" else "
echo \"$sha256 *\"\(opts.target | @sh) | sha256sum -c -;"
end
] | add
| rtrimstr(";")
| gsub("(?<=[^[:space:]])\n"; " \\\n")
| gsub("(?<=[[:space:]])\n"; "\\\n")
;