From 4df5b98c5c9620d9ed18ff45a5d32bfece574f8e Mon Sep 17 00:00:00 2001 From: Felipe Gasper Date: Wed, 10 Sep 2025 14:05:31 -0400 Subject: [PATCH 1/6] add download script --- README.md | 6 ++++ download_latest.sh | 74 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100755 download_latest.sh diff --git a/README.md b/README.md index ac735138ab..52c31e58df 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,12 @@ Once downloaded, you will have to extract the binary and add it to your PATH variable. For detailed instructions for each of our supported platforms, please visit [installation documentation](https://www.mongodb.com/docs/mongodb-shell/install#mdb-shell-install). +You can also run `download_latest.sh` to download a `mongosh` binary. You can use +this script without cloning the repository thus: +``` +curl -sSL https://raw.githubusercontent.com/mongodb-js/mongosh/refs/heads/main/download_latest.sh | sh +``` + ## CLI Usage diff --git a/download_latest.sh b/download_latest.sh new file mode 100755 index 0000000000..9ea70e6af1 --- /dev/null +++ b/download_latest.sh @@ -0,0 +1,74 @@ +#!/bin/sh + +set -o errexit + +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 + +case "$arch" in + amd64|x86_64) + arch=x64 + ;; + aarch64) + arch=arm64 +esac + +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) +url=$(printf "%s" "$urls" | grep "\-${os}-${arch}" ||:) + +if [ -z "$url" ]; then + cat < "$file" + echo "Downloaded $ext file; extracting mongosh …" + + unzip -j "$file" '*/mongosh' + ;; + tgz) + echo "Downloading & extracting from $url …" + + curl -fsSL "$url" | tar -xzf - \ + --transform "s/.*\///" \ + --wildcards "**/mongosh" + + ;; + *) + echo >&2 "Bad file extension: $ext" + exit 1 +esac + +echo "Success! 'mongosh' is now saved in this directory." From c1ec95ae1f85677650a09dc7aa1b057b374fb5f9 Mon Sep 17 00:00:00 2001 From: Felipe Gasper Date: Thu, 11 Sep 2025 09:00:11 -0400 Subject: [PATCH 2/6] =?UTF-8?q?Anna=E2=80=99s=20review=20feedback?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- download_latest.sh | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/download_latest.sh b/download_latest.sh index 9ea70e6af1..c3d54bc9f0 100755 --- a/download_latest.sh +++ b/download_latest.sh @@ -2,6 +2,8 @@ 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'." @@ -25,24 +27,33 @@ case "$os" in exit 1 esac +# normalize $arch: case "$arch" in - amd64|x86_64) - arch=x64 + amd64|x64) + arch=x86_64 ;; aarch64) arch=arm64 + ;; + *) + # Use uname’s reported architecture in the jq query. esac -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) -url=$(printf "%s" "$urls" | grep "\-${os}-${arch}" ||:) +jq_query=$(cat <&2 "No download found for $os on $arch; download manually." exit 1 fi From 588c5e2275b17198048e152a100769569f5e1100 Mon Sep 17 00:00:00 2001 From: Felipe Gasper Date: Thu, 11 Sep 2025 10:46:00 -0400 Subject: [PATCH 3/6] Update README.md Co-authored-by: Anna Henningsen --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 52c31e58df..cae6cc24a3 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ variable. For detailed instructions for each of our supported platforms, please You can also run `download_latest.sh` to download a `mongosh` binary. You can use this script without cloning the repository thus: ``` -curl -sSL https://raw.githubusercontent.com/mongodb-js/mongosh/refs/heads/main/download_latest.sh | sh +curl -fsSL https://raw.githubusercontent.com/mongodb-js/mongosh/refs/heads/main/download_latest.sh | sh ``` ## CLI Usage From 50bddd8890cbe31a5d9c595a912d10e52db0e8b3 Mon Sep 17 00:00:00 2001 From: Felipe Gasper Date: Thu, 11 Sep 2025 10:46:08 -0400 Subject: [PATCH 4/6] Update download_latest.sh Co-authored-by: Anna Henningsen --- download_latest.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/download_latest.sh b/download_latest.sh index c3d54bc9f0..4c9b926371 100755 --- a/download_latest.sh +++ b/download_latest.sh @@ -62,7 +62,7 @@ case "$ext" in file=$(mktemp) echo "Downloading $url to $file …" - trap 'rm -f $file' EXIT + trap 'rm -f "$file"' EXIT curl -fsSL "$url" > "$file" echo "Downloaded $ext file; extracting mongosh …" From e8d4af8298a5f1ef0ed8c86e8466c889ce11b67e Mon Sep 17 00:00:00 2001 From: Felipe Gasper Date: Fri, 12 Sep 2025 09:32:55 -0400 Subject: [PATCH 5/6] Extract the crypto library as well. --- download_latest.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/download_latest.sh b/download_latest.sh index c3d54bc9f0..7a31133499 100755 --- a/download_latest.sh +++ b/download_latest.sh @@ -67,14 +67,15 @@ case "$ext" in curl -fsSL "$url" > "$file" echo "Downloaded $ext file; extracting mongosh …" - unzip -j "$file" '*/mongosh' + unzip -vj "$file" '*/bin/mongosh*' ;; tgz) echo "Downloading & extracting from $url …" curl -fsSL "$url" | tar -xzf - \ --transform "s/.*\///" \ - --wildcards "**/mongosh" + --wildcards "**/bin/mongosh*" \ + | sed -E 's/^.*[/]//' ;; *) @@ -82,4 +83,4 @@ case "$ext" in exit 1 esac -echo "Success! 'mongosh' is now saved in this directory." +echo "Success! 'mongosh' and its crypto library are now saved in this directory." From 9fad15ddfe496cb8af21143bbca00066d4a306d7 Mon Sep 17 00:00:00 2001 From: Felipe Gasper Date: Fri, 12 Sep 2025 09:41:24 -0400 Subject: [PATCH 6/6] prettify & add manual download link --- download_latest.sh | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/download_latest.sh b/download_latest.sh index 741df36b30..d396f59dec 100755 --- a/download_latest.sh +++ b/download_latest.sh @@ -4,6 +4,12 @@ set -o errexit MONGOSH_RELEASES_URL=https://downloads.mongodb.com/compass/mongosh.json +show_download_link() { + echo >&2 "Download mongosh manually from:" + echo >&2 + printf >&2 "\t%s\n", 'https://www.mongodb.com/try/download/shell' +} + for tool in jq curl; do which "$tool" >/dev/null || { echo >&2 "This script requires '$tool'." @@ -23,7 +29,9 @@ case "$os" in ext=zip ;; *) - echo >&2 "This script does not support this OS ($os). Download mongosh manually." + echo >&2 "❌ This script does not support this OS ($os)." + show_download_link + exit 1 esac @@ -53,7 +61,8 @@ 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." + echo >&2 "❓ No download found for $os on $arch." + show_download_link exit 1 fi @@ -80,7 +89,8 @@ case "$ext" in ;; *) echo >&2 "Bad file extension: $ext" + show_download_link exit 1 esac -echo "Success! 'mongosh' and its crypto library are now saved in this directory." +echo "✅ Success! 'mongosh' and its crypto library are now saved in this directory."