diff --git a/README.md b/README.md index 79089b4..3ec3e63 100644 --- a/README.md +++ b/README.md @@ -53,26 +53,26 @@ curl -Lo setup https://raw.githubusercontent.com/themobileprof/scripts/develop/a 1. [The GCP CLI setup script](../blob/develop/gcp_cli_setup): This script installs Google cloud CLI for managing Google Cloud resources. To use this script in Termux, copy and paste the below snippet of code into your terminal: ``` -curl -Lo setup https://raw.githubusercontent.com/themobileprof/scripts/develop/gcp_cli_setup && chmod +x ./setup && ./setup && exit +curl -Lo setup https://raw.githubusercontent.com/themobileprof/scripts/develop/gcp_cli_setup && chmod +x ./setup && ./setup ``` 1. [GCloud VM Setup](../blob/develop/gcloud_vm): This scripts helps you provision a free VM or customize a more robust machine for your use. It works well on Termux or on the Google cloud shell, just copy and paste the code below into your terminal: ``` -curl -Lo vm https://raw.githubusercontent.com/themobileprof/scripts/develop/gcloud_vm && chmod +x ./vm && ./vm && exit +curl -Lo vm https://raw.githubusercontent.com/themobileprof/scripts/develop/gcloud_vm && chmod +x ./vm && ./vm ``` ### AWS Cloud 1. [The AWS CLI setup script](../blob/develop/aws_cli_setup): This script installs AWS CLI for managing Amazon Web Services. To use this script in Termux, copy and paste the below snippet of code into your terminal: ``` -curl -Lo setup https://raw.githubusercontent.com/themobileprof/scripts/develop/aws_cli_setup && chmod +x ./setup && ./setup && exit +curl -Lo setup https://raw.githubusercontent.com/themobileprof/scripts/develop/aws_cli_setup && chmod +x ./setup && ./setup ``` ### Azure Cloud 1. [The Azure CLI setup script](../blob/develop/azure_cli_setup): This script installs Azure CLI for managing Microsoft Azure Cloud resources. To use this script in Termux, copy and paste the below snippet of code into your terminal: ``` -curl -Lo setup https://raw.githubusercontent.com/themobileprof/scripts/develop/azure_cli_setup && chmod +x ./setup && ./setup && exit +curl -Lo setup https://raw.githubusercontent.com/themobileprof/scripts/develop/azure_cli_setup && chmod +x ./setup && ./setup ``` diff --git a/gcloud_vm b/gcloud_vm index d4df5ad..f33198c 100755 --- a/gcloud_vm +++ b/gcloud_vm @@ -27,15 +27,21 @@ main(){ fi # Check if there is a default zone, if not, Google init - zone=$(gcloud config get-value compute/zone) - if [ -z "$zone" ] - then - # Initialize Google Cloud - echo "We cannot detect a Zone in your configuration, so let us help you with configuration. Please remember to configure your zone as us-west, us-central, or us-east especially if you need the Google free VM" - read -p "Press to proceed..." - gcloud init - fi - zone=$(gcloud config get-value compute/zone) + # zone=$(gcloud config get-value compute/zone) + # if [ -z "$zone" ] + # then + # # Initialize Google Cloud + # echo "We cannot detect a Zone in your configuration, so let us help you with configuration. Please remember to configure your zone as us-west, us-central, or us-east especially if you need the Google free VM" + # read -p "Press to proceed..." + # gcloud init + # fi + # zone=$(gcloud config get-value compute/zone) + + # Setup project + set_project + + # Setup zone + zone_setup # Name your machine with a unique name echo "" @@ -61,6 +67,83 @@ main(){ } +set_project(){ + echo "What project would we be working on?" + projectList=$(gcloud projects list --format="value(NAME)") + + projArray+=($projectList) + + i=0 + for project in $projectList + do + ((i++)) + echo "$i: $project" + done + + while [ -z "$PROJNUM" ] + do + read -p "Please select (1-$i): " PROJNUM + if [[ -n ${PROJNUM//[0-9]/} ]]; then + unset PROJNUM + fi + done + + PROJECT=${projArray[(($PROJNUM-1))]} + echo "You are to set $PROJECT as your default project, press to continue" + read + + gcloud config set project $PROJECT +} + +zone_setup(){ + ############################################################ + ## DO NOT ASSUME THE ZONES AND REGIONS - GET IT FROM GCLOUD + ############################################################ + local zone=$(gcloud config get-value compute/zone) + if [ -z "$zone" ] + then + echo "We cannot detect a Zone in your configuration" + echo "What Region do you want to set your resources to?" + echo "1. US-West" + echo "2. US-Central" + echo "3. US-East" + + while [ -z "$zoneNum" ] + do + read -p "Please select (1, 2, or 3): " zoneNum + if [[ -n ${zoneNum//[0-9]/} ]]; then + unset zoneNum + fi + done + + local letters=(a b c) + local a=$((RANDOM%3+1)) + local b=$((RANDOM%3)) + + + if [ "${zoneNum,,}" = "2" ]; then + zoneValue="us-central${a}-${letters[$b]}" + regionValue="us-central${a}" + elif [ "${zoneNum,,}" = "3" ]; then + zoneValue="us-east${a}-${letters[$b]}" + regionValue="us-east${a}" + else + zoneValue="us-west${a}-${letters[$b]}" + regionValue="us-west${a}" + fi + + echo "You are about to set your Zone to $zoneValue, press to continue" + read + + gcloud compute project-info add-metadata --metadata google-compute-default-region=$regionValue,google-compute-default-zone=$zoneValue + + # Initialize Gcloud + echo "We recommend that you setup a default zone as part of the setup below" + gcloud init + fi +} + + free_vm(){ # Get a US Zone except us-south @@ -179,16 +262,17 @@ vm(){ # Expecting VMNAME and zone gcloud compute machine-types describe ${machinesArray[$machineNum]} --zone=$2 # Select Disk Space - echo "" - echo "# How many GB hard drive do you need?" - - while [ -z "$HDD" ] - do - read -p "Input a number (GB): " HDD - if [[ -n ${HDD//[0-9]/} ]]; then - unset HDD - fi - done + # echo "" + # echo "# How many GB hard drive do you need?" + + # while [ -z "$HDD" ] + # do + # read -p "Input a number (GB): " HDD + # if [[ -n ${HDD//[0-9]/} ]]; then + # unset HDD + # fi + # done + HDD=200 # Use this default for now IMGFAM=$(gcloud compute images list --format="value(FAMILY)" --filter="$OpSys" --limit=1)