diff --git a/psu b/psu index 724929b..c3ad6bb 100755 --- a/psu +++ b/psu @@ -128,25 +128,25 @@ main() { echo_debug_safe_json "Stack ${PORTAINER_STACK_NAME} -> $(echo $STACK | jq -C .)" "$STACK" fi - if [ $ACTION == "deploy" ]; then + if [ "$ACTION" == "deploy" ]; then deploy exit 0 fi - if [ $ACTION == "rm" ]; then + if [ "$ACTION" == "rm" ]; then undeploy exit 0 fi - if [ $ACTION == "login" ]; then - if [ $QUIET_MODE == "false" ] && [ $MASKED_VARIABLES == "false" ]; then + if [ "$ACTION" == "login" ]; then + if [ "$QUIET_MODE" == "false" ] && [ $MASKED_VARIABLES == "false" ]; then echo "$PORTAINER_AUTH_TOKEN" fi exit 0 fi # Returns Docker system info - if [ $ACTION == "system:info" ]; then + if [ "$ACTION" == "system:info" ]; then local docker_info echo_verbose "Getting Docker info..." docker_info="$(docker_info)" @@ -159,13 +159,13 @@ main() { exit 1 fi - if [ $ACTION == "services" ]; then + if [ "$ACTION" == "services" ]; then echo_verbose "List service(s) of stack '$PORTAINER_STACK_NAME'..." local services services=$(services) echo_debug "Services action response -> $(echo $services | jq -C .)" if [ -n "$services" ] && [ ! "$services" == "[]" ]; then - if [ $QUIET_MODE == "false" ]; then + if [ "$QUIET_MODE" == "false" ]; then # Returns response in JSON format echo "$services" else @@ -177,7 +177,7 @@ main() { exit 1 fi - if [ $ACTION == "status" ]; then + if [ "$ACTION" == "status" ]; then echo_verbose "Status of tasks for the stack '$PORTAINER_STACK_NAME'..." local status # WIP: Each services should have at least one task @@ -198,13 +198,13 @@ main() { fi fi - if [ $ACTION == "tasks" ] || [ $ACTION == "tasks:healthy" ]; then + if [ "$ACTION" == "tasks" ] || [ "$ACTION" == "tasks:healthy" ]; then 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 if [ -n "$PORTAINER_SERVICE_NAME" ]; then 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 .)" else echo_verbose "List $scope tasks of stack '$PORTAINER_STACK_NAME'..." @@ -228,7 +228,7 @@ main() { fi if [ -n "$tasks" ] && [ ! "$tasks" == "[]" ]; then - if [ $QUIET_MODE == "false" ]; then + if [ "$QUIET_MODE" == "false" ]; then # Returns response in JSON format echo "$tasks" else @@ -241,13 +241,13 @@ main() { exit 1 fi - if [ $ACTION == "containers" ]; then + if [ "$ACTION" == "containers" ]; then echo_verbose "List container(s) of stack '$PORTAINER_STACK_NAME'..." local containers containers=$(containers) echo_debug "Containers action response -> $(echo $containers | jq -C .)" if [ -n "$containers" ] && [ ! "$containers" == "[]" ]; then - if [ $QUIET_MODE == "false" ]; then + if [ "$QUIET_MODE" == "false" ]; then # Returns response in JSON format echo "$containers" else @@ -261,9 +261,9 @@ main() { # Returns stack info # If it already exists - if [ $ACTION == "inspect" ]; then + if [ "$ACTION" == "inspect" ]; then if [ -n "$STACK" ]; then - if [ $QUIET_MODE == "false" ]; then + if [ "$QUIET_MODE" == "false" ]; then echo "$STACK" else # Only display the stack name in quiet mode @@ -275,8 +275,8 @@ main() { fi # Get list of all stacks - if [ $ACTION == "ls" ]; then - if [ $QUIET_MODE == "false" ]; then + if [ "$ACTION" == "ls" ]; then + if [ "$QUIET_MODE" == "false" ]; then # Returns response in JSON format echo "$STACKS" else @@ -287,13 +287,13 @@ main() { fi # Lint the Docker compose/stack file - if [ $ACTION == "lint" ]; then + if [ "$ACTION" == "lint" ]; then lint exit 0 fi # 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 "" display_actions_message @@ -571,7 +571,7 @@ inputs() { HTTPIE_VERIFY_SSL="${HTTPIE_VERIFY_SSL:-"yes"}" fi 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" fi if [ -n "$2" ] && [[ ! $2 =~ ^-.+$ ]] ; then @@ -583,7 +583,7 @@ inputs() { echo_verbose "DEPRECATED: Use '--insecure' option, instead of this '$1' option" HTTPIE_VERIFY_SSL=$(input_flag "$1" "$2" "yes no" "no") 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" fi if [ -n "$2" ] && [[ ! $2 =~ ^-.+$ ]] ; then @@ -851,7 +851,7 @@ echo_verbose() { local yellow='\033[1;33m' local nc='\033[0m' - if [ $VERBOSE_MODE == "true" ]; then + if [ "$VERBOSE_MODE" == "true" ]; then local verbose_message verbose_message=$(mask_variables "$message") echo -e "${yellow}${verbose_message}${nc}" @@ -869,7 +869,7 @@ echo_verbose() { ######################################### echo_debug() { local message=$1 - if [ $DEBUG_MODE == "true" ]; then + if [ "$DEBUG_MODE" == "true" ]; then local debug_message debug_message=$(mask_variables "$message") @@ -1027,7 +1027,7 @@ deploy() { echo_debug "Swarm ID -> $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 "Preparing stack JSON..." @@ -1082,7 +1082,7 @@ deploy() { rm -f "$json_temp_path" else - if [ $STRICT_MODE == "true" ]; then + if [ "$STRICT_MODE" == "true" ]; then echo_error "Error: Stack $PORTAINER_STACK_NAME already exists." exit 1 fi @@ -1134,7 +1134,7 @@ deploy() { ########################## undeploy() { if [ -z "$STACK" ]; then - if [ $STRICT_MODE == "true" ]; then + if [ "$STRICT_MODE" == "true" ]; then echo_error "Error: Stack $PORTAINER_STACK_NAME does not exist." exit 1 else @@ -1332,7 +1332,7 @@ lint() { # JSON string # ################################################### 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 @@ -1487,7 +1487,7 @@ display_actions_message() { fi done - if [ $VERBOSE_MODE == "true" ]; then + if [ "$VERBOSE_MODE" == "true" ]; then display_actions_aliased_message fi }