Skip to content

Commit 3e1404b

Browse files
committed
Always output to stderr
1 parent 9fad15d commit 3e1404b

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

download_latest.sh

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,24 @@ set -o errexit
44

55
MONGOSH_RELEASES_URL=https://downloads.mongodb.com/compass/mongosh.json
66

7+
say() {
8+
echo >&2 "$@"
9+
}
10+
11+
sayf() {
12+
# shellcheck disable=SC2059
13+
printf >&2 "$@"
14+
}
15+
716
show_download_link() {
8-
echo >&2 "Download mongosh manually from:"
9-
echo >&2
10-
printf >&2 "\t%s\n", 'https://www.mongodb.com/try/download/shell'
17+
say "Download mongosh manually from:"
18+
say
19+
sayf "\t%s\n" 'https://www.mongodb.com/try/download/shell'
1120
}
1221

1322
for tool in jq curl; do
1423
which "$tool" >/dev/null || {
15-
echo >&2 "This script requires '$tool'."
24+
say "This script requires '$tool'."
1625
exit 1
1726
}
1827
done
@@ -29,7 +38,7 @@ case "$os" in
2938
ext=zip
3039
;;
3140
*)
32-
echo >&2 "❌ This script does not support this OS ($os)."
41+
say "❌ This script does not support this OS ($os)."
3342
show_download_link
3443

3544
exit 1
@@ -61,7 +70,7 @@ EOF
6170
url=$(curl -fsSL $MONGOSH_RELEASES_URL | jq -r "$jq_query")
6271

6372
if [ -z "$url" ]; then
64-
echo >&2 "❓ No download found for $os on $arch."
73+
say "❓ No download found for $os on $arch."
6574
show_download_link
6675
exit 1
6776
fi
@@ -70,16 +79,16 @@ case "$ext" in
7079
zip)
7180
file=$(mktemp)
7281

73-
echo "Downloading $url to $file"
82+
say "Downloading $url to $file"
7483
trap 'rm -f "$file"' EXIT
7584

7685
curl -fsSL "$url" > "$file"
77-
echo "Downloaded $ext file; extracting mongosh …"
86+
say "Downloaded $ext file; extracting mongosh …"
7887

7988
unzip -vj "$file" '*/bin/mongosh*'
8089
;;
8190
tgz)
82-
echo "Downloading & extracting from $url"
91+
say "Downloading & extracting from $url"
8392

8493
curl -fsSL "$url" | tar -xzf - \
8594
--transform "s/.*\///" \
@@ -88,9 +97,9 @@ case "$ext" in
8897

8998
;;
9099
*)
91-
echo >&2 "Bad file extension: $ext"
100+
say "Bad file extension: $ext"
92101
show_download_link
93102
exit 1
94103
esac
95104

96-
echo "✅ Success! 'mongosh' and its crypto library are now saved in this directory."
105+
say "✅ Success! 'mongosh' and its crypto library are now saved in this directory."

0 commit comments

Comments
 (0)