Skip to content

Commit c9a3b96

Browse files
committed
add script: install-gcloud-cli.sh
1 parent 6df8ecd commit c9a3b96

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

install-gcloud-cli.sh

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
CLI_VERSION="481.0.0"
5+
arch=$(uname -sm)
6+
7+
function err_exit() {
8+
echo "Error: $1" >&2
9+
exit 1
10+
}
11+
12+
filename_ident=""
13+
case "$arch" in
14+
Darwin\ arm64) filename_ident="darwin-arm.tar.gz" ;;
15+
# add linux variants if needed
16+
*) err_exit "unsupported architecture: $arch" ;;
17+
esac
18+
19+
filename="google-cloud-sdk-${CLI_VERSION}-${filename_ident}"
20+
url="https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/${filename}"
21+
22+
echo
23+
echo "cli_version: $CLI_VERSION"
24+
echo "arch: $arch"
25+
echo "pwd: $(pwd)"
26+
echo "url: $url"
27+
echo
28+
29+
echo "continue?"
30+
read -p "[y/N] " -r
31+
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
32+
echo "exiting."
33+
exit 1
34+
fi
35+
36+
echo
37+
38+
# check if google-cloud-sdk already exists
39+
if [ -d "google-cloud-sdk" ]; then
40+
41+
# ask user if they want to overwrite
42+
read -p "google-cloud-sdk directory already exists. do you want to overwrite it? [y/N] " -r
43+
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
44+
echo "exiting."
45+
exit 1
46+
fi
47+
echo "removing old google-cloud-sdk directory..."
48+
rm -rvf "google-cloud-sdk"
49+
fi
50+
51+
echo "downloading..."
52+
curl -#SLO "$url"
53+
54+
echo "extracting..."
55+
tar -xzf "$filename"
56+
57+
echo "cleaning up tarball..."
58+
rm -v "$filename"
59+
60+
echo "done."
61+
echo
62+
echo "please ensure that the 'google-cloud-sdk/bin' directory is in your PATH:"
63+
echo "$(pwd)/google-cloud-sdk/bin"

0 commit comments

Comments
 (0)