Format Bash code

This commit is contained in:
Tortue Torche 2021-09-14 13:46:09 +02:00
parent 457aba0687
commit c00c8fe67b

58
psu
View File

@ -128,25 +128,25 @@ main() {
echo_debug_safe_json "Stack ${PORTAINER_STACK_NAME} -> $(echo $STACK | jq -C .)" "$STACK" echo_debug_safe_json "Stack ${PORTAINER_STACK_NAME} -> $(echo $STACK | jq -C .)" "$STACK"
fi fi
if [ $ACTION == "deploy" ]; then if [ "$ACTION" == "deploy" ]; then
deploy deploy
exit 0 exit 0
fi fi
if [ $ACTION == "rm" ]; then if [ "$ACTION" == "rm" ]; then
undeploy undeploy
exit 0 exit 0
fi fi
if [ $ACTION == "login" ]; then if [ "$ACTION" == "login" ]; then
if [ $QUIET_MODE == "false" ] && [ $MASKED_VARIABLES == "false" ]; then if [ "$QUIET_MODE" == "false" ] && [ $MASKED_VARIABLES == "false" ]; then
echo "$PORTAINER_AUTH_TOKEN" echo "$PORTAINER_AUTH_TOKEN"
fi fi
exit 0 exit 0
fi fi
# Returns Docker system info # Returns Docker system info
if [ $ACTION == "system:info" ]; then if [ "$ACTION" == "system:info" ]; then
local docker_info local docker_info
echo_verbose "Getting Docker info..." echo_verbose "Getting Docker info..."
docker_info="$(docker_info)" docker_info="$(docker_info)"
@ -159,13 +159,13 @@ main() {
exit 1 exit 1
fi fi
if [ $ACTION == "services" ]; then if [ "$ACTION" == "services" ]; then
echo_verbose "List service(s) of stack '$PORTAINER_STACK_NAME'..." echo_verbose "List service(s) of stack '$PORTAINER_STACK_NAME'..."
local services local services
services=$(services) services=$(services)
echo_debug "Services action response -> $(echo $services | jq -C .)" echo_debug "Services action response -> $(echo $services | jq -C .)"
if [ -n "$services" ] && [ ! "$services" == "[]" ]; then if [ -n "$services" ] && [ ! "$services" == "[]" ]; then
if [ $QUIET_MODE == "false" ]; then if [ "$QUIET_MODE" == "false" ]; then
# Returns response in JSON format # Returns response in JSON format
echo "$services" echo "$services"
else else
@ -177,7 +177,7 @@ main() {
exit 1 exit 1
fi fi
if [ $ACTION == "status" ]; then if [ "$ACTION" == "status" ]; then
echo_verbose "Status of tasks for the stack '$PORTAINER_STACK_NAME'..." echo_verbose "Status of tasks for the stack '$PORTAINER_STACK_NAME'..."
local status local status
# WIP: Each services should have at least one task # WIP: Each services should have at least one task
@ -198,13 +198,13 @@ main() {
fi fi
fi fi
if [ $ACTION == "tasks" ] || [ $ACTION == "tasks:healthy" ]; then if [ "$ACTION" == "tasks" ] || [ "$ACTION" == "tasks:healthy" ]; then
local scope local scope
scope="$(if [ $ACTION == "tasks:healthy" ]; then echo healthy; else echo all; fi)" scope="$(if [ "$ACTION" == "tasks:healthy" ]; then echo healthy; else echo all; fi)"
local tasks local tasks
if [ -n "$PORTAINER_SERVICE_NAME" ]; then if [ -n "$PORTAINER_SERVICE_NAME" ]; then
echo_verbose "List $scope tasks from service '$PORTAINER_SERVICE_NAME' of stack '$PORTAINER_STACK_NAME'..." echo_verbose "List $scope tasks from service '$PORTAINER_SERVICE_NAME' of stack '$PORTAINER_STACK_NAME'..."
tasks=$(if [ $scope == "healthy" ]; then tasks_healthy; else tasks; fi) tasks=$(if [ "$scope" == "healthy" ]; then tasks_healthy; else tasks; fi)
echo_debug "Tasks action response -> $(echo $tasks | jq -C .)" echo_debug "Tasks action response -> $(echo $tasks | jq -C .)"
else else
echo_verbose "List $scope tasks of stack '$PORTAINER_STACK_NAME'..." echo_verbose "List $scope tasks of stack '$PORTAINER_STACK_NAME'..."
@ -228,7 +228,7 @@ main() {
fi fi
if [ -n "$tasks" ] && [ ! "$tasks" == "[]" ]; then if [ -n "$tasks" ] && [ ! "$tasks" == "[]" ]; then
if [ $QUIET_MODE == "false" ]; then if [ "$QUIET_MODE" == "false" ]; then
# Returns response in JSON format # Returns response in JSON format
echo "$tasks" echo "$tasks"
else else
@ -241,13 +241,13 @@ main() {
exit 1 exit 1
fi fi
if [ $ACTION == "containers" ]; then if [ "$ACTION" == "containers" ]; then
echo_verbose "List container(s) of stack '$PORTAINER_STACK_NAME'..." echo_verbose "List container(s) of stack '$PORTAINER_STACK_NAME'..."
local containers local containers
containers=$(containers) containers=$(containers)
echo_debug "Containers action response -> $(echo $containers | jq -C .)" echo_debug "Containers action response -> $(echo $containers | jq -C .)"
if [ -n "$containers" ] && [ ! "$containers" == "[]" ]; then if [ -n "$containers" ] && [ ! "$containers" == "[]" ]; then
if [ $QUIET_MODE == "false" ]; then if [ "$QUIET_MODE" == "false" ]; then
# Returns response in JSON format # Returns response in JSON format
echo "$containers" echo "$containers"
else else
@ -261,9 +261,9 @@ main() {
# Returns stack info # Returns stack info
# If it already exists # If it already exists
if [ $ACTION == "inspect" ]; then if [ "$ACTION" == "inspect" ]; then
if [ -n "$STACK" ]; then if [ -n "$STACK" ]; then
if [ $QUIET_MODE == "false" ]; then if [ "$QUIET_MODE" == "false" ]; then
echo "$STACK" echo "$STACK"
else else
# Only display the stack name in quiet mode # Only display the stack name in quiet mode
@ -275,8 +275,8 @@ main() {
fi fi
# Get list of all stacks # Get list of all stacks
if [ $ACTION == "ls" ]; then if [ "$ACTION" == "ls" ]; then
if [ $QUIET_MODE == "false" ]; then if [ "$QUIET_MODE" == "false" ]; then
# Returns response in JSON format # Returns response in JSON format
echo "$STACKS" echo "$STACKS"
else else
@ -287,13 +287,13 @@ main() {
fi fi
# Lint the Docker compose/stack file # Lint the Docker compose/stack file
if [ $ACTION == "lint" ]; then if [ "$ACTION" == "lint" ]; then
lint lint
exit 0 exit 0
fi fi
# Get list of all actions who can be used for this program # Get list of all actions who can be used for this program
if [ $ACTION == "actions" ]; then if [ "$ACTION" == "actions" ]; then
echo "Portainer Stack Utils, version $VERSION" echo "Portainer Stack Utils, version $VERSION"
echo "" echo ""
display_actions_message display_actions_message
@ -571,7 +571,7 @@ inputs() {
HTTPIE_VERIFY_SSL="${HTTPIE_VERIFY_SSL:-"yes"}" HTTPIE_VERIFY_SSL="${HTTPIE_VERIFY_SSL:-"yes"}"
fi fi
if [ "$HTTPIE_VERIFY_SSL" == "no" ] && [ -z "$PYTHONWARNINGS" ]; then if [ "$HTTPIE_VERIFY_SSL" == "no" ] && [ -z "$PYTHONWARNINGS" ]; then
# Fix httpie with Debian and Ubuntu # Fix HTTPie with Debian and Ubuntu
export PYTHONWARNINGS="ignore:Unverified HTTPS request" export PYTHONWARNINGS="ignore:Unverified HTTPS request"
fi fi
if [ -n "$2" ] && [[ ! $2 =~ ^-.+$ ]] ; then if [ -n "$2" ] && [[ ! $2 =~ ^-.+$ ]] ; then
@ -583,7 +583,7 @@ inputs() {
echo_verbose "DEPRECATED: Use '--insecure' option, instead of this '$1' option" echo_verbose "DEPRECATED: Use '--insecure' option, instead of this '$1' option"
HTTPIE_VERIFY_SSL=$(input_flag "$1" "$2" "yes no" "no") HTTPIE_VERIFY_SSL=$(input_flag "$1" "$2" "yes no" "no")
if [ "$HTTPIE_VERIFY_SSL" == "no" ] && [ -z "$PYTHONWARNINGS" ]; then if [ "$HTTPIE_VERIFY_SSL" == "no" ] && [ -z "$PYTHONWARNINGS" ]; then
# Fix httpie with Debian and Ubuntu # Fix HTTPie with Debian and Ubuntu
export PYTHONWARNINGS="ignore:Unverified HTTPS request" export PYTHONWARNINGS="ignore:Unverified HTTPS request"
fi fi
if [ -n "$2" ] && [[ ! $2 =~ ^-.+$ ]] ; then if [ -n "$2" ] && [[ ! $2 =~ ^-.+$ ]] ; then
@ -851,7 +851,7 @@ echo_verbose() {
local yellow='\033[1;33m' local yellow='\033[1;33m'
local nc='\033[0m' local nc='\033[0m'
if [ $VERBOSE_MODE == "true" ]; then if [ "$VERBOSE_MODE" == "true" ]; then
local verbose_message local verbose_message
verbose_message=$(mask_variables "$message") verbose_message=$(mask_variables "$message")
echo -e "${yellow}${verbose_message}${nc}" echo -e "${yellow}${verbose_message}${nc}"
@ -869,7 +869,7 @@ echo_verbose() {
######################################### #########################################
echo_debug() { echo_debug() {
local message=$1 local message=$1
if [ $DEBUG_MODE == "true" ]; then if [ "$DEBUG_MODE" == "true" ]; then
local debug_message local debug_message
debug_message=$(mask_variables "$message") debug_message=$(mask_variables "$message")
@ -1027,7 +1027,7 @@ deploy() {
echo_debug "Swarm ID -> $swarm_id" echo_debug "Swarm ID -> $swarm_id"
# If there is no swarm ID # If there is no swarm ID
if [ -z "$swarm_id" ];then if [ -z "$swarm_id" ]; then
echo_verbose "Swarm cluster not found." echo_verbose "Swarm cluster not found."
echo_verbose "Preparing stack JSON..." echo_verbose "Preparing stack JSON..."
@ -1082,7 +1082,7 @@ deploy() {
rm -f "$json_temp_path" rm -f "$json_temp_path"
else else
if [ $STRICT_MODE == "true" ]; then if [ "$STRICT_MODE" == "true" ]; then
echo_error "Error: Stack $PORTAINER_STACK_NAME already exists." echo_error "Error: Stack $PORTAINER_STACK_NAME already exists."
exit 1 exit 1
fi fi
@ -1134,7 +1134,7 @@ deploy() {
########################## ##########################
undeploy() { undeploy() {
if [ -z "$STACK" ]; then if [ -z "$STACK" ]; then
if [ $STRICT_MODE == "true" ]; then if [ "$STRICT_MODE" == "true" ]; then
echo_error "Error: Stack $PORTAINER_STACK_NAME does not exist." echo_error "Error: Stack $PORTAINER_STACK_NAME does not exist."
exit 1 exit 1
else else
@ -1332,7 +1332,7 @@ lint() {
# JSON string # # JSON string #
################################################### ###################################################
env_file_to_json() { env_file_to_json() {
echo "$(env -i sh -c "(unset \$(env | sed 's/=.*//'); set -a; . $(readlink -f $ENVIRONMENT_VARIABLES_FILE); set +a; jq -njc 'env | to_entries | map({name: .key, value: .value})')")" env -i sh -c "(unset \$(env | sed 's/=.*//'); set -a; . $(readlink -f $ENVIRONMENT_VARIABLES_FILE); set +a; jq -njc 'env | to_entries | map({name: .key, value: .value})')"
} }
# Set the ACTIONS variable who's a list of all psu actions # Set the ACTIONS variable who's a list of all psu actions
@ -1487,7 +1487,7 @@ display_actions_message() {
fi fi
done done
if [ $VERBOSE_MODE == "true" ]; then if [ "$VERBOSE_MODE" == "true" ]; then
display_actions_aliased_message display_actions_aliased_message
fi fi
} }