Skip to content

Commit 1be0204

Browse files
committed
gcloud cli: add running the bundled install script
1 parent cc73a97 commit 1be0204

File tree

1 file changed

+30
-11
lines changed

1 file changed

+30
-11
lines changed

install-gcloud-cli.sh

+30-11
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
set -euo pipefail
33

44
CLI_VERSION="481.0.0"
5+
SDK_DIR="google-cloud-sdk"
56
arch=$(uname -sm)
7+
base_dir=$(pwd)
68

79
function err_exit() {
810
echo "Error: $1" >&2
@@ -16,8 +18,8 @@ Darwin\ arm64) filename_ident="darwin-arm.tar.gz" ;;
1618
*) err_exit "unsupported architecture: $arch" ;;
1719
esac
1820

19-
filename="google-cloud-sdk-${CLI_VERSION}-${filename_ident}"
20-
url="https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/${filename}"
21+
tarball="google-cloud-sdk-${CLI_VERSION}-${filename_ident}"
22+
url="https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/${tarball}"
2123

2224
echo
2325
echo "cli_version: $CLI_VERSION"
@@ -26,40 +28,57 @@ echo "pwd: $(pwd)"
2628
echo "url: $url"
2729
echo
2830

29-
echo "continue?"
30-
read -p "[y/N] " -r
31+
read -p "continue? [y/N] " -r
3132
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
3233
echo "exiting."
3334
exit 1
3435
fi
3536

3637
echo
38+
echo "downloading cli version ${CLI_VERSION}..."
39+
curl -#SLO "$url"
3740

3841
# check if google-cloud-sdk already exists
3942
if [ -d "google-cloud-sdk" ]; then
4043

44+
echo
45+
4146
# ask user if they want to overwrite
4247
read -p "google-cloud-sdk directory already exists. do you want to overwrite it? [y/N] " -r
4348
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
4449
echo "exiting."
4550
exit 1
4651
fi
4752
echo "removing old google-cloud-sdk directory..."
48-
rm -rvf "google-cloud-sdk"
53+
rm -rf "google-cloud-sdk"
4954
fi
5055

51-
echo "downloading..."
52-
curl -#SLO "$url"
53-
5456
echo
5557
echo "extracting..."
56-
tar -xzf "$filename"
58+
tar -xzf "$tarball"
5759

5860
echo
61+
install_script="install.sh"
62+
install_flags="--quiet --usage-reporting=false --command-completion=true --path-update=true"
63+
echo "running google-cloud-sdk/install.sh..."
64+
65+
echo "installing gcloud with the following flags: $install_flags"
66+
read -p "continue? [y/N] " -r
67+
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
68+
echo "exiting."
69+
exit 1
70+
fi
71+
72+
cd "$SDK_DIR"
73+
# shellcheck disable=SC2086
74+
bash "$install_script" $install_flags
75+
76+
echo "gcloud installation script completed."
5977
echo "cleaning up..."
60-
rm "$filename"
78+
rm "${base_dir}/$tarball"
6179

6280
echo "done."
81+
6382
echo
6483
echo "please ensure that the 'google-cloud-sdk/bin' directory is in your PATH:"
65-
echo "$(pwd)/google-cloud-sdk/bin"
84+
echo "$(pwd)/bin"

0 commit comments

Comments
 (0)