-
Notifications
You must be signed in to change notification settings - Fork 79
feat: add a download script to facilitate easy use in CI MONGOSH-2687 #2532
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
4df5b98
c1ec95a
588c5e2
50bddd8
e8d4af8
8a9f8cc
9fad15d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#!/bin/sh | ||
|
||
set -o errexit | ||
|
||
MONGOSH_RELEASES_URL=https://downloads.mongodb.com/compass/mongosh.json | ||
|
||
for tool in jq curl; do | ||
which "$tool" >/dev/null || { | ||
echo >&2 "This script requires '$tool'." | ||
exit 1 | ||
} | ||
done | ||
|
||
os=$(uname -o | tr '[:upper:]' '[:lower:]') | ||
arch=$(uname -m) | ||
|
||
case "$os" in | ||
*linux) | ||
ext=tgz | ||
os=linux | ||
;; | ||
darwin) | ||
ext=zip | ||
;; | ||
*) | ||
echo >&2 "This script does not support this OS ($os). Download mongosh manually." | ||
exit 1 | ||
esac | ||
|
||
# normalize $arch: | ||
case "$arch" in | ||
amd64|x64) | ||
arch=x86_64 | ||
;; | ||
aarch64) | ||
arch=arm64 | ||
addaleax marked this conversation as resolved.
Show resolved
Hide resolved
|
||
;; | ||
*) | ||
# Use uname’s reported architecture in the jq query. | ||
esac | ||
|
||
jq_query=$(cat <<EOF | ||
.versions[0].downloads[] | | ||
select( | ||
.distro == "$os" and | ||
.arch == "$arch" and | ||
(has("sharedOpenssl") | not) | ||
) | | ||
.archive.url | ||
EOF | ||
) | ||
|
||
url=$(curl -fsSL $MONGOSH_RELEASES_URL | jq -r "$jq_query") | ||
|
||
if [ -z "$url" ]; then | ||
echo >&2 "No download found for $os on $arch; download manually." | ||
exit 1 | ||
fi | ||
|
||
case "$ext" in | ||
zip) | ||
file=$(mktemp) | ||
|
||
echo "Downloading $url to $file …" | ||
trap 'rm -f $file' EXIT | ||
FGasper marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
curl -fsSL "$url" > "$file" | ||
echo "Downloaded $ext file; extracting mongosh …" | ||
|
||
unzip -j "$file" '*/mongosh' | ||
;; | ||
tgz) | ||
echo "Downloading & extracting from $url …" | ||
|
||
curl -fsSL "$url" | tar -xzf - \ | ||
addaleax marked this conversation as resolved.
Show resolved
Hide resolved
|
||
--transform "s/.*\///" \ | ||
--wildcards "**/mongosh" | ||
|
||
|
||
;; | ||
*) | ||
echo >&2 "Bad file extension: $ext" | ||
exit 1 | ||
esac | ||
|
||
echo "Success! 'mongosh' is now saved in this directory." |
Uh oh!
There was an error while loading. Please reload this page.