1414set -e
1515
1616command=$1
17- [ " $ENV_DIR " == " " ] && env_unset=1
17+ [ " $ENV_DIR " = " " ] && env_unset=1
1818ENV_DIR=${ENV_DIR:- $PWD }
19- [ " $ENV_DIR " == " /home/app/stack" ] && ENV_DIR=$ENV_DIR /env
19+ [ " $ENV_DIR " = " /home/app/stack" ] && ENV_DIR=$ENV_DIR /env
2020
2121. bin/common.sh
2222
@@ -33,9 +33,9 @@ function verbose_env() {
3333}
3434
3535# VERBOSE - export this varibale to run this script in verbose mode
36- VERBOSE=${VERBOSE:- " 0 " }
36+ VERBOSE=${VERBOSE:- ' true ' }
3737# EXIT_FAST - export this varaibale to exit the script on error
38- EXIT_FAST=${EXIT_FAST:- " 1 " }
38+ EXIT_FAST=${EXIT_FAST:- ' true ' }
3939
4040# check_kube_context - a flag to indicate to use kube context and to refresh kube access token before running command in docker
4141check_kube_context=1
@@ -55,10 +55,10 @@ readme_url='https://github.com/redkubes/otomi-core'
5555
5656function set_env_and_stack_dir() {
5757 local cwd=$( basename " $PWD " )
58- [ " $VERBOSE " == " 1" ] && echo " CWD: $cwd "
59- if [[ " $cwd " == " otomi-core" ] ]; then
60- [ " $env_unset " == " 1" ] && echo " Error: The ENV_DIR environment variable is not set" && exit 1
61- [ " $VERBOSE " == " 1" ] && echo " Mounting otomi-core dir"
58+ [ " $VERBOSE " = " 1" ] && echo " CWD: $cwd "
59+ if [ " $cwd " = " otomi-core" ]; then
60+ [ " $env_unset " = " 1" ] && echo " Error: The ENV_DIR environment variable is not set" >&2 && exit 1
61+ [ " $VERBOSE " = " 1" ] && echo " Mounting otomi-core dir"
6262 stack_dir=$PWD
6363 mount_stack_dir=1
6464 fi
@@ -106,16 +106,15 @@ function check_docker_running() {
106106 if [ " $? " = " 0" ]; then
107107 has_docker=1
108108 else
109- echo " Otomi CLI expects a running docker daemon!"
110- exit 1
109+ echo " Otomi CLI expects a running docker daemon!" >&2 && exit 1
111110 fi
112111}
113112
114113function evaluate_k8s_context() {
115114 local env_path=" ${ENV_DIR} /env/clouds/${CLOUD} /${CLUSTER} /.env"
116- [ ! -f $env_path ] && echo " Error: The file '${env_path} ' does not exist" && exit 1
115+ [ ! -f $env_path ] && echo " Error: The file '${env_path} ' does not exist" >&2 && exit 1
117116 source $env_path
118- [[ -z " $K8S_CONTEXT " ]] && echo " Error: The K8S_CONTEXT env is not defined in $env_path " && exit 1
117+ [[ -z " $K8S_CONTEXT " ]] && echo " Error: The K8S_CONTEXT env is not defined in $env_path " >&2 && exit 1
119118 return 0
120119}
121120
@@ -144,9 +143,9 @@ evaluate_secrets() {
144143 echo " Info: The 'secrets.*.yaml files' are not decrypted, because $ENV_DIR /.sops.yaml file is not present"
145144 return 0
146145 }
147- if [ " $CI " == " " ]; then
146+ if [ " $CI " = " " ]; then
148147 local secrets_path=" $ENV_DIR /.secrets"
149- [[ ! -r " $secrets_path " ]] && echo " Error: Unable to find the '$secrets_path ' file.\nPlease follow to documentation: $readme_url " && exit 2
148+ [[ ! -r " $secrets_path " ]] && echo " Error: Unable to find the '$secrets_path ' file.\nPlease follow to documentation: $readme_url " >&2 && exit 2
150149 source $secrets_path
151150 fi
152151 prepare_crypt
@@ -155,13 +154,15 @@ evaluate_secrets() {
155154
156155validate_cluster_env () {
157156 evaluate_secrets
158- [[ -z " $CLOUD " ]] && echo " Error: The CLOUD environment variable is not set" && exit 2
159- [[ -z " $CLUSTER " ]] && echo " Error: The CLUSTER environment variable is not set" && exit 2
157+ local err
158+ [[ -z " $CLOUD " ]] && echo " Error: The CLOUD environment variable is not set" >&2 && err=1
159+ [[ -z " $CLUSTER " ]] && echo " Error: The CLUSTER environment variable is not set" >&2 && err=1
160+ [[ ! -z " $err " ]] && exit 2
160161 return 0
161162}
162163
163164is_repo () {
164- [[ " $( basename " $PWD " ) " == " otomi-core" ]] && echo " Error: Should not be ran from otomi-core" && exit 2
165+ [[ " $( basename " $PWD " ) " = " otomi-core" ]] && echo " Error: Should not be ran from otomi-core" >&2 && exit 2
165166 return 0
166167}
167168
@@ -188,7 +189,7 @@ function drun() {
188189 local socket_volume=' '
189190
190191 if [ " $CI " != " " ]; then
191- echo " Running in CI: $CI "
192+ [ " $VERBOSE " = " 1 " ] && echo " Running in CI: $CI "
192193 check_kube_context=0
193194 else
194195 socket_volume=" -v /var/run/docker.sock:/var/run/docker.sock"
@@ -205,15 +206,15 @@ function drun() {
205206 stack_volume=" -v ${stack_dir} :${stack_dir} "
206207 fi
207208
208- if [ " $VERBOSE " == " 1" ]; then
209+ if [ " $VERBOSE " = " 1" ]; then
209210 verbose_env
210211 fi
211212
212213 # use docker run if has_docker AND either:
213214 # - not in docker
214215 # - in docker AND force docker
215- if [[ (" $CI " == " " ) && $has_docker -eq 1 && (" $IN_DOCKER " ! = " 1" || $dind -eq 1) ]]; then
216- [ " $VERBOSE " == " 1" ] && echo " Running dockerized version of command: $command "
216+ if [[ (" $CI " = " " ) && $has_docker -eq 1 && (" $IN_DOCKER " ! = " 1" || $dind -eq 1) ]]; then
217+ [ " $VERBOSE " = " 1" ] && echo " Running dockerized version of command: $command "
217218 docker run $docker_terminal_params --rm \
218219 $stack_volume $socket_volume -v /tmp:/tmp \
219220 -v $GOOGLE_APPLICATION_CREDENTIALS :$GOOGLE_APPLICATION_CREDENTIALS \
@@ -237,7 +238,7 @@ function drun() {
237238 $cmd_image \
238239 $command
239240 else
240- [ " $VERBOSE " == " 1" ] && echo " Running native version of command: $command "
241+ [ " $VERBOSE " = " 1" ] && echo " Running native version of command: $command "
241242 $command
242243 fi
243244}
@@ -383,13 +384,12 @@ function execute() {
383384 ;;
384385 * )
385386 show_usage
386- [ " $1 " != " " ] && echo " Error: Unknown command: $@ "
387- exit 1
387+ [ " $1 " != " " ] && echo " Error: Unknown command: $@ " >&2 && exit 1
388388 ;;
389389 esac
390390}
391391
392- [[ -z " $command " ]] && echo " Error: Missing command argument" && show_usage && exit 2
392+ [[ -z " $command " ]] && echo " Error: Missing command argument" >&2 && show_usage && exit 2
393393
394394set_env_and_stack_dir
395395set_otomi_image
0 commit comments