Skip to content

Instantly share code, notes, and snippets.

@cmoulliard
Created June 13, 2022 10:41
Show Gist options
  • Save cmoulliard/a72397d5bdd58e28b08a1909bed04e7e to your computer and use it in GitHub Desktop.
Save cmoulliard/a72397d5bdd58e28b08a1909bed04e7e to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Defining some colors for output
NC='\033[0m' # No Color
RED='\033[0;31m'
YELLOW='\033[0;33m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
MAGENTA='\033[0;35m'
CYAN='\033[0;36m'
WHITE='\033[0;37m'
repeat_char(){
COLOR=${1}
for i in {1..50}; do echo -ne "${!COLOR}$2${NC}"; done
}
log_msg() {
COLOR=${1}
MSG="${@:2}"
echo -e "\n${!COLOR}## ${MSG}${NC}"
}
log() {
MSG="${@:2}"
echo; repeat_char ${1} '#'; log_msg ${1} ${MSG}; repeat_char ${1} '#'; echo
}
repeat(){
local start=1
local end=${1:-80}
local str="${2:-=}"
local range=$(seq $start $end)
for i in $range ; do echo -n "${str}"; done
}
check_os_linux_distro() {
platform='unknown'
unamestr=$(uname)
if [[ "$unamestr" == 'Linux' ]]; then
platform='linux'
elif [[ "$unamestr" == 'Darwin' ]]; then
platform='darwin'
fi
if [[ $platform == 'linux' ]]; then
echo "Linux OS ...."
elif [[ $platform == 'darwin' ]]; then
echo "Macos OS ...."
fi
}
HELP_CONTENT="
Usage: local-tap.sh [OPTIONS]
Options:
[Global Mandatory Flags]
--action : What action to take - create,stop,start,status,delete,prepare
[Global Optional Flags]
--help : show this help menu
[Mandatory Flags - Used by the Create/Delete Action]
--xxxxx-yyyyy : User for xxxxxxxx
[Optional Flags - For Create Action]
--tap-profile : TAP Installation Profile. (Default full)
--supply-chain : The supply chain to install (Default basic) Options: basic, testing, testing_scanning
--tap-version : Version of TAP. - (Default 1.1.1)"
if [[ $# == 0 ]]; then
echo "No Flags were passed. Run with --help flag to get usage information"
exit 1
fi
while test $# -gt 0; do
case "$1" in
--action)
shift
action=$1
shift
;;
--version)
shift
platform_version=$1
shift
;;
--help)
echo "$HELP_CONTENT"
exit 1
;;
*)
echo "$1 is not a recognized flag!"
exit 1
;;
esac
done
unameOut="$(uname -s)"
case "${unameOut}" in
Linux*) machine_os=Linux;;
Darwin*) machine_os=Mac;;
*) machine_os="UNKNOWN:${unameOut}"
esac
:
if [[ $machine_os != "Mac" && $machine_os != "Linux" ]]; then
echo "Only Mac and Linux are currently supported. your machine returned the type of $machine_os"
exit 1
fi
# Validate an action was selected
if ! [[ $action ]]; then
echo "You must specify the action the script should perform via the --action flag"
exit 1
fi
if ! [[ $platform_version ]]; then
platform_version="1.2.0"
fi
case $action in
start)
echo "I'm starting"
echo "Tanzu TAP using ${tanzunet_user}"
echo "....";;
stop)
echo "I'm stopping"
echo "Tanzu TAP"
echo "....";;
status)
echo "Here is the"
echo "Tanzu"
echo "status....";;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment