11#! /bin/bash
2-
32# Copyright 2022 Google Inc. All Rights Reserved.
43#
54# Licensed under the Apache License, Version 2.0 (the "License");
1413# See the License for the specific language governing permissions and
1514# limitations under the License.
1615
16+ success () {
17+ echo " ========================================="
18+ echo " The Google Cloud setup is completed."
19+ echo " Please proceed with the Tutorial steps"
20+ echo " ========================================="
21+ exit 0
22+ }
23+
24+ failure () {
25+ echo " ========================================="
26+ echo " The Google Cloud setup was not completed."
27+ echo " Please fix the errors above!"
28+ echo " ========================================="
29+ exit 1
30+ }
31+
32+ # catch any error that happened during execution
33+ trap ' failure' ERR
34+
1735# set the Google Cloud Project ID
1836project_id=$1
1937echo " Project ID: $project_id "
2038gcloud config set project " $project_id "
2139
2240timestamp=$( date +%s)
23-
2441service_account_id=" service-acc-$timestamp "
2542echo " Service Account: $service_account_id "
26-
2743# create service account (your service-acc-$timestamp)
2844gcloud iam service-accounts create " $service_account_id "
2945
3046# assign necessary roles to your new service account
3147for role in {retail.admin,editor,bigquery.admin}
32- do
48+ do
3349 gcloud projects add-iam-policy-binding " $project_id " --member=" serviceAccount:$service_account_id @$project_id .iam.gserviceaccount.com" --role=roles/" ${role} "
3450done
3551
3652echo " Wait ~60 seconds to be sure the appropriate roles have been assigned to your service account"
3753sleep 60
38-
3954# upload your service account key file
4055service_acc_email=" $service_account_id @$project_id .iam.gserviceaccount.com"
4156gcloud iam service-accounts keys create ~ /key.json --iam-account " $service_acc_email "
@@ -44,10 +59,5 @@ gcloud iam service-accounts keys create ~/key.json --iam-account "$service_acc_e
4459gcloud auth activate-service-account --key-file ~ /key.json
4560
4661# install needed Google client libraries
47- cd ~ /cloudshell_open/nodejs-retail/samples || exit
62+ cd ~ /cloudshell_open/nodejs-retail/samples
4863npm install
49-
50- echo " ======================================="
51- echo " The Google Cloud setup is completed."
52- echo " Please proceed with the Tutorial steps"
53- echo " ======================================="
0 commit comments