Skip to content

Instantly share code, notes, and snippets.

@rpappalax
Created August 3, 2020 20:48
Show Gist options
  • Save rpappalax/14213f918bcd8f674fe188beb0c0ca1f to your computer and use it in GitHub Desktop.
Save rpappalax/14213f918bcd8f674fe188beb0c0ca1f to your computer and use it in GitHub Desktop.
#!/bin/bash
## ----------------------------------
# Step #1: Define variables
# ----------------------------------
STD='\033[0;0;39m'
NONE='\033[00m'
RED='\033[01;31m'
BLUE='\033[01;34m'
# ----------------------------------
# Step #2: User defined function
# ----------------------------------
pause(){
read -p "Press [Enter] key to continue..." fackEnterKey
}
auth_list(){
CMD="gcloud auth list"
echo
echo "listing accounts whose credentials are stored locally..."
echo -e "\n${BLUE}$ ${CMD}${NONE}\n"
exec $CMD
pause
}
config_list(){
echo
echo "listing properties in your active SDK config..."
CMD="gcloud config list"
echo -e "\n${BLUE}$ ${CMD}${NONE}\n"
exec $CMD
pause
}
instance_create(){
echo
echo "create new instance"
read -p 'enter instance name: ' INSTANCE_NAME
CMD="gcloud compute instances create $INSTANCE_NAME"
echo -e "\n${BLUE}$ ${CMD}${NONE}\n"
exec $CMD
pause
}
instance_activity(){
echo
echo "stop | start | delete instance"
read -p 'enter instance name: ' INSTANCE_NAME
read -p 'enter action (stop|start|delete): ' ACTIVITY
CMD="gcloud compute instances $ACTIVITY $INSTANCE_NAME"
echo -e "\n${BLUE}$ ${CMD}${NONE}\n"
exec $CMD
pause
}
instance_create_with_container(){
echo
echo "create new instance with container"
read -p 'enter container name: ' CONTAINER_NAME
read -p 'enter image name: ' IMAGE_NAME
CMD="gcloud compute instances create-with-container $INSTANCE_NAME --container-image=$IMAGE_NAME"
echo -e "\n${BLUE}$ ${CMD}${NONE}\n"
exec $CMD
pause
}
# function to display menus
show_menus() {
clear
echo "~~~~~~~~~~~~~~~~~~~~~"
echo " M A I N - M E N U"
echo "~~~~~~~~~~~~~~~~~~~~~"
echo "0. Exit"
echo "1. gcloud auth list"
echo "2. gcloud config list"
echo "3. gcloud create instance"
echo "4. gcloud compute instances [start|stop|delete]"
echo "5. gcloud create instance with container"
}
read_options(){
local choice
read -p "Enter choice [ 0 - 5] " choice
case $choice in
1) auth_list ;;
2) config_list ;;
3) instance_create;;
4) instance_activity;;
5) instance_create_with_container;;
0) tput sgr0; exit 0;;
*) echo -e "${RED}Error...${STD}" && sleep 2
esac
}
# ----------------------------------------------
# Step #3: Trap CTRL+C, CTRL+Z and quit singles
# ----------------------------------------------
trap '' SIGINT SIGQUIT SIGTSTP
# -----------------------------------
# Step #4: Main logic - infinite loop
# ------------------------------------
while true
do
show_menus
read_options
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment