-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathbw-install.sh
executable file
·187 lines (162 loc) · 4.04 KB
/
bw-install.sh
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/usr/bin/env bash
# Simple JuliaBinaryWrappers downloader for use with nightlies CI
#
# Copyright (c) 2020 Leorize <leorize+oss@disroot.org>
#
# This script is licensed under the MIT license.
usage() {
cat << EOF
Usage: $0 [-o folder] [-t triple] <pkg>...
Downloads and installs packages from JuliaBinaryWrappers.
<pkg> The package specification, can be just the package name (ie.
SQLite, OpenSSL) to get the latest version, or a tag name for an
exact version (ie. SQLite-v3.31.1+0, OpenSSL-v1.1.1+2).
Options:
-o folder Where to install the specified packages to. If not specified the
current folder will be used.
-t triple Specify the target triple for package downloads, if unspecified
will be automatically detected.
-h This help message.
EOF
}
detectTriple() {
case "$(uname -s)" in
Darwin)
if [[ $(uname -m) == x86_64 ]]; then
# Hardcode this triple due to later OSX uses never version sufficies
echo x86_64-apple-darwin14
else
echo Unsupported macOS version >&2
return 1
fi
;;
*)
result=$(gcc -dumpmachine)
case "$result" in
*-linux-*)
result=${result/-pc/}
result=${result/-unknown/}
;;
esac
echo "$result"
;;
esac
}
getAsset() {
pkg=${1%%-*}_jll.jl
version=${1##*-}
queryLatest='
query($repo: String!, $owner: String = "JuliaBinaryWrappers", $endCursor: String) {
repository(name: $repo, owner: $owner) {
releases(last: 1) {
nodes {
releaseAssets(first: 15, after: $endCursor) {
nodes {
...assetFields
}
pageInfo {
hasNextPage
endCursor
}
}
}
}
}
}
'
getAssetsLatest='.data | .repository | .releases | .nodes[0] | .releaseAssets | .nodes[]'
queryExact='
query($tag: String!, $repo: String!, $owner: String = "JuliaBinaryWrappers", $endCursor: String) {
repository(name: $repo, owner: $owner) {
release(tagName: $tag) {
releaseAssets(first: 15, after: $endCursor) {
nodes {
...assetFields
}
pageInfo {
hasNextPage
endCursor
}
}
}
}
}
'
getAssetsExact='.data | .repository | .release | .releaseAssets | .nodes[]'
assetFields='
fragment assetFields on ReleaseAsset {
downloadUrl
name
}
'
declare -a hubParams
if [[ $1 == $version ]]; then
hubParams+=(-F "query=$queryLatest$assetFields" -F "repo=$pkg")
getAssets=$getAssetsLatest
else
hubParams+=(-F "query=$queryExact$assetFields" -F "repo=$pkg" -F "tag=$1")
getAssets=$getAssetsExact
fi
resp=$(gh api graphql --paginate "${hubParams[@]}") || exit 1
if [[ $(jq 'has("errors")' <<< "$resp") == true ]]; then
jq -r '.errors[] | .message' <<< "$resp" >&2
return 1
fi
if [[ -z "$triple" ]]; then
triple=$(detectTriple) || return 1
fi
jq -sr --arg triple "$triple" \
'[ .[] | '"$getAssets"' | select(.name | contains($triple)) ]' <<< "$resp"
}
output=$PWD
triple=
while getopts "o:t:h" curopt; do
case "$curopt" in
'o')
output=$OPTARG
;;
't')
triple=$OPTARG
;;
'h')
usage
exit 0
;;
*)
usage
exit 1
;;
esac
done
shift $((OPTIND - 1))
if [[ $# -lt 1 ]]; then
echo "$0: missing required argument -- <pkg>"
usage
exit 1
fi
mkdir -p "$output" || exit 1
cd "$output" || exit 1
for pkg in "$@"; do
asset=$(getAsset "$pkg") || exit 1
case "$(jq 'length' <<< "$asset")" in
1)
;;
0)
echo "Package $pkg not found for triple: $triple"
exit 1
;;
*)
echo "Ambiguous triple '$triple'" >&2
exit 1
;;
esac
asset=$(jq -r '.[0]' <<< "$asset")
url=$(jq -r '.downloadUrl' <<< "$asset") || exit 1
name=$(jq -r '.name' <<< "$asset") || exit 1
echo "Downloading $name ($url)"
curl -L "$url" -o "$name" || exit 1
echo "Installing $pkg"
tar xf "$name" || exit 1
echo "Cleaning artifact $name"
rm -f "$name" || exit 1
done