Skip to content

Commit c1ec95a

Browse files
committed
Anna’s review feedback
1 parent 4df5b98 commit c1ec95a

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

download_latest.sh

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
set -o errexit
44

5+
MONGOSH_RELEASES_URL=https://downloads.mongodb.com/compass/mongosh.json
6+
57
for tool in jq curl; do
68
which "$tool" >/dev/null || {
79
echo >&2 "This script requires '$tool'."
@@ -25,24 +27,33 @@ case "$os" in
2527
exit 1
2628
esac
2729

30+
# normalize $arch:
2831
case "$arch" in
29-
amd64|x86_64)
30-
arch=x64
32+
amd64|x64)
33+
arch=x86_64
3134
;;
3235
aarch64)
3336
arch=arm64
37+
;;
38+
*)
39+
# Use uname’s reported architecture in the jq query.
3440
esac
3541

36-
urls=$(curl -fsSL https://api.github.com/repos/mongodb-js/mongosh/releases/latest | jq -r '.assets[] | .browser_download_url' | grep -v -e \.sig -e shared -e openssl)
37-
url=$(printf "%s" "$urls" | grep "\-${os}-${arch}" ||:)
42+
jq_query=$(cat <<EOF
43+
.versions[0].downloads[] |
44+
select(
45+
.distro == "$os" and
46+
.arch == "$arch" and
47+
(has("sharedOpenssl") | not)
48+
) |
49+
.archive.url
50+
EOF
51+
)
3852

39-
if [ -z "$url" ]; then
40-
cat <<EOL
41-
No download found for $os on $arch; download manually.
53+
url=$(curl -fsSL $MONGOSH_RELEASES_URL | jq -r "$jq_query")
4254

43-
URLs considered:
44-
$urls
45-
EOL
55+
if [ -z "$url" ]; then
56+
echo >&2 "No download found for $os on $arch; download manually."
4657
exit 1
4758
fi
4859

0 commit comments

Comments
 (0)