You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
165 lines
3.6 KiB
165 lines
3.6 KiB
#!/bin/bash
|
|
|
|
### DO NOT EDIT THIS FILE
|
|
|
|
if [ true != ${includes_main_functions:-false} ]
|
|
then
|
|
includes_main_functions=true
|
|
|
|
function echoMainTitle {
|
|
echo -e "\033[38;5;214m$1\033[0m"
|
|
}
|
|
|
|
function echoSubTitle {
|
|
echo -e "\033[38;5;142m$1\033[0m"
|
|
}
|
|
|
|
function echoSmall {
|
|
echo -e "\033[38;5;240m$1\033[0m"
|
|
}
|
|
|
|
function echoSelect {
|
|
local select="$1"
|
|
local message="$2"
|
|
echo -e "\033[0;33m$select\033[0m $message"
|
|
}
|
|
|
|
function echoError {
|
|
echo -e "\033[0;91m$1\033[0m"
|
|
}
|
|
|
|
function echoWarning {
|
|
echo -e "\033[0;33m$1\033[0m"
|
|
}
|
|
|
|
function echoSuccess {
|
|
echo -e "\033[0;32m$1\033[0m"
|
|
}
|
|
|
|
function getParameter {
|
|
local name=$1
|
|
local has=$2
|
|
local parameters=($3)
|
|
|
|
for i in "${!parameters[@]}"
|
|
do
|
|
if [ "${parameters[$i]}" == "$name" ] && [ "$has" == true ]
|
|
then
|
|
((j=i+1))
|
|
echo "${parameters[$j]}"
|
|
elif [ "${parameters[$i]}" == "$name" ]
|
|
then
|
|
echo true
|
|
fi
|
|
done
|
|
}
|
|
|
|
function getArgument {
|
|
local var=$1
|
|
local errmsg=${2:-"Invalid Argument"}
|
|
local allow=${3:-true}
|
|
|
|
if [ "$allow" != false ] && [ "$(isAllowed "$var" "$allow")" == false ]
|
|
then
|
|
echo "$errmsg" >&2
|
|
exit 1
|
|
fi
|
|
|
|
echo "$var"
|
|
}
|
|
|
|
function isAllowed {
|
|
local var="$1"
|
|
local allow="$2"
|
|
local valid=true
|
|
|
|
if [ "$allow" == true ] && [ "$var" == "" ]
|
|
then
|
|
valid=false
|
|
elif [ "$allow" != false ] && [ "$allow" != true ]
|
|
then
|
|
allow=($allow)
|
|
local found=false
|
|
for i in "${!allow[@]}"
|
|
do
|
|
if [ "${allow[$i]}" == "$var" ]
|
|
then
|
|
found=true
|
|
fi
|
|
done
|
|
if [ "$found" != true ]
|
|
then
|
|
valid=false
|
|
fi
|
|
fi
|
|
|
|
echo $valid
|
|
}
|
|
|
|
function readConsole {
|
|
local message="$1"
|
|
local errmsg="$2"
|
|
local allow=${3:-false}
|
|
local default="$4"
|
|
|
|
if [ "$default" != "" ]
|
|
then
|
|
read -p "$message [default:$default]: " var
|
|
else
|
|
read -p "$message: " var
|
|
fi
|
|
|
|
if [ "$var" == "" ] && [ "$default" != "" ]
|
|
then
|
|
var="$default"
|
|
fi
|
|
|
|
if [ "$(isAllowed "$var" "$allow")" == false ]
|
|
then
|
|
echo "$errmsg" >&2
|
|
var=$(readConsole "$message" "$errmsg" "$allow" "$default")
|
|
fi
|
|
|
|
echo "$var"
|
|
}
|
|
|
|
function postScript {
|
|
local script=$(getArgument "$1" "Usage: postScript \"post_script.sh\"" true)
|
|
if [ -f "$script" ]
|
|
then
|
|
source "$script"
|
|
fi
|
|
}
|
|
|
|
function getConfig {
|
|
local env=$(getArgument "$1" "Usage getEnvVar [live|stage|local_live|local_stage] var" "live stage local_live local_stage")
|
|
local suffix=$(getArgument "$2" "Usage getEnvVar [live|stage|local_live|local_stage] var" true)
|
|
echo "$(eval "echo \"\$${env}_$suffix\"")"
|
|
}
|
|
|
|
function sedEscape {
|
|
echo "$1" | sed -r 's/([\$\.\*\/\[\\^])/\\\1/g' | sed 's/[]]/\[]]/g'
|
|
}
|
|
|
|
function confirm {
|
|
confirm="$(readConsole "Should i execute? [y,n]" "Invalid selection" "y n")"
|
|
|
|
if [ "$confirm" == "n" ]
|
|
then
|
|
echo
|
|
echoError "Aborting"
|
|
echo
|
|
exit
|
|
fi
|
|
}
|
|
|
|
function getSudoPassword {
|
|
if [ "${project_manager_sudo_password}" == "" ]
|
|
then
|
|
echo -n "Sudo Password:"
|
|
read -s project_manager_sudo_password
|
|
fi
|
|
echo project_manager_sudo_password
|
|
}
|
|
|
|
fi
|