2
2
set -euo pipefail
3
3
4
4
CLI_VERSION=" 481.0.0"
5
+ SDK_DIR=" google-cloud-sdk"
5
6
arch=$( uname -sm)
7
+ base_dir=$( pwd)
6
8
7
9
function err_exit() {
8
10
echo " Error: $1 " >&2
@@ -16,8 +18,8 @@ Darwin\ arm64) filename_ident="darwin-arm.tar.gz" ;;
16
18
* ) err_exit " unsupported architecture: $arch " ;;
17
19
esac
18
20
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 } "
21
23
22
24
echo
23
25
echo " cli_version: $CLI_VERSION "
@@ -26,40 +28,57 @@ echo "pwd: $(pwd)"
26
28
echo " url: $url "
27
29
echo
28
30
29
- echo " continue?"
30
- read -p " [y/N] " -r
31
+ read -p " continue? [y/N] " -r
31
32
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
32
33
echo " exiting."
33
34
exit 1
34
35
fi
35
36
36
37
echo
38
+ echo " downloading cli version ${CLI_VERSION} ..."
39
+ curl -#SLO " $url "
37
40
38
41
# check if google-cloud-sdk already exists
39
42
if [ -d " google-cloud-sdk" ]; then
40
43
44
+ echo
45
+
41
46
# ask user if they want to overwrite
42
47
read -p " google-cloud-sdk directory already exists. do you want to overwrite it? [y/N] " -r
43
48
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
44
49
echo " exiting."
45
50
exit 1
46
51
fi
47
52
echo " removing old google-cloud-sdk directory..."
48
- rm -rvf " google-cloud-sdk"
53
+ rm -rf " google-cloud-sdk"
49
54
fi
50
55
51
- echo " downloading..."
52
- curl -#SLO " $url "
53
-
54
56
echo
55
57
echo " extracting..."
56
- tar -xzf " $filename "
58
+ tar -xzf " $tarball "
57
59
58
60
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."
59
77
echo " cleaning up..."
60
- rm " $filename "
78
+ rm " ${base_dir} / $tarball "
61
79
62
80
echo " done."
81
+
63
82
echo
64
83
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