I want to write a shell script which basically goes through all the installation steps for gcloud, as outlined at: https://cloud.google.com/sdk/?hl=en
However, when you are run install.sh, you will be asked to enter an authorization code, your project-id, whether you want to help improve Google Cloud or not and so on. Basically user-inputs are required.
But if I want to automate the installation process on a machine where there will not be any user, how can I do this?
The gcloud CLI starts you off with a single configuration named default . You can set properties in your configuration by running the gcloud init command or by running gcloud config set directly.
The first thing to do after successful installation is open your command line and type “gcloud” to check whether Cloud SDK has installed perfectly. Run “gcloud init”, it opens up a new browser window and asks to login into your google cloud account.
There are two separate problems here.
First, how do you install without prompts:
CLOUDSDK_CORE_DISABLE_PROMPTS=1 ./install.sh
(or install.bat)This disables all prompts. If you don't like the way it answers the prompts, you can pre-answer them with flags. If you preanswer all the questions, you don't need the CLOUDSDK_CORE_DISABLE_PROMPTS environment variable set. Run ./install.sh --help for a list of flags.
Now that you have it installed, how do you auth it?
If you are on GCE, you can use the credentials on the machine itself automatically. If not, some setup is required.
Since these are automated installs, you want to give them a server key. If there was a human involved, he can just proceed through the normal flow.
Keys can be downloaded from the developer console under "APIs & auth -> Credentials". Click "New credentials -> Service account key". Google recommends you use a JSON key.
When you have that key, you need to move it to the new server and run:
gcloud auth activate-service-account --key-file servicekey.json
gcloud config set project MYPROJECT
This sequence of commands should help:
file="google-cloud-sdk-101.0.0-linux-x86_64.tar.gz"
link="https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/"
curl -L "$link""$file" | tar xz
CLOUDSDK_CORE_DISABLE_PROMPTS=1 ./google-cloud-sdk/install.sh
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With