From 98cdf0418907757bde41dc3898d44807cb8d81e0 Mon Sep 17 00:00:00 2001 From: Brendan Burns Date: Mon, 30 Mar 2015 10:20:29 -0700 Subject: [PATCH] Auto-install gcloud if needed. --- cluster/gce/util.sh | 8 ++++++-- cluster/gke/util.sh | 30 ++++++++++++++++++++++++------ 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/cluster/gce/util.sh b/cluster/gce/util.sh index 5312681221441..1695165e0f27f 100755 --- a/cluster/gce/util.sh +++ b/cluster/gce/util.sh @@ -31,9 +31,13 @@ function verify-prereqs { local cmd for cmd in gcloud gsutil; do if ! which "${cmd}" >/dev/null; then - echo "Can't find ${cmd} in PATH. Do you wish to install the Google Cloud SDK? [Y/n]" local resp - read resp + if [[ "${KUBE_PROMPT_FOR_UPDATE" == "y" ]]; then + echo "Can't find ${cmd} in PATH. Do you wish to install the Google Cloud SDK? [Y/n]" + read resp + else + resp="y" + fi if [[ "${resp}" != "n" && "${resp}" != "N" ]]; then curl https://sdk.cloud.google.com | bash fi diff --git a/cluster/gke/util.sh b/cluster/gke/util.sh index 06f8c1864470d..dab49cfeed4ba 100755 --- a/cluster/gke/util.sh +++ b/cluster/gke/util.sh @@ -19,6 +19,7 @@ # Use the config file specified in $KUBE_CONFIG_FILE, or default to # config-default.sh. +KUBE_PROMPT_FOR_UPDATE=y KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../.. source "${KUBE_ROOT}/cluster/gke/${KUBE_CONFIG_FILE:-config-default.sh}" @@ -68,12 +69,29 @@ function test-build-release() { # Verify needed binaries exist. function verify-prereqs() { - echo "... in verify-prereqs()" >&2 - - ${GCLOUD} preview --help >/dev/null || { - echo "Either the GCLOUD environment variable is wrong, or the 'preview' component" - echo "is not installed. (Fix with 'gcloud components update preview')" - } + if ! which gcloud >/dev/null; then + local resp + if [[ "${KUBE_PROMPT_FOR_UPDATE" == "y" ]]; then + echo "Can't find gcloud in PATH. Do you wish to install the Google Cloud SDK? [Y/n]" + read resp + else + resp="y" + fi + if [[ "${resp}" != "n" && "${resp}" != "N" ]]; then + curl https://sdk.cloud.google.com | bash + fi + if ! which gcloud >/dev/null; then + echo "Can't find gcloud in PATH, please fix and retry. The Google Cloud " + echo "SDK can be downloaded from https://cloud.google.com/sdk/." + exit 1 + fi + fi + # update and install components as needed + if [[ "${KUBE_PROMPT_FOR_UPDATE}" != "y" ]]; then + gcloud_prompt="-q" + fi + gcloud ${gcloud_prompt:-} components update preview || true + gcloud ${gcloud_prompt:-} components update || true } # Instantiate a kubernetes cluster