chore(shellcheck): fix shellcheck linting warnings

This commit is contained in:
Thales Macedo Garitezi 2021-12-22 15:07:23 -03:00
parent e137555052
commit 014b6d3cfd
No known key found for this signature in database
GPG Key ID: DD279F8152A9B6DD
8 changed files with 44 additions and 18 deletions

View File

@ -5,8 +5,8 @@ if [ "$DEBUG" -eq 1 ]; then
set -x set -x
fi fi
ROOT_DIR="$(cd "$(dirname "$(readlink "$0" || echo "$0")")"/..; pwd -P)" ROOT_DIR="$(cd "$(dirname "$(readlink "$0" || echo "$0")")"/.. || exit 1; pwd -P)"
# shellcheck disable=SC1090 # shellcheck disable=SC1090,SC1091
. "$ROOT_DIR"/releases/emqx_vars . "$ROOT_DIR"/releases/emqx_vars
# defined in emqx_vars # defined in emqx_vars
@ -14,15 +14,16 @@ export RUNNER_ROOT_DIR
export RUNNER_ETC_DIR export RUNNER_ETC_DIR
export REL_VSN export REL_VSN
RUNNER_SCRIPT="$RUNNER_BIN_DIR/$REL_NAME" export RUNNER_SCRIPT="$RUNNER_BIN_DIR/$REL_NAME"
CODE_LOADING_MODE="${CODE_LOADING_MODE:-embedded}" export CODE_LOADING_MODE="${CODE_LOADING_MODE:-embedded}"
REL_DIR="$RUNNER_ROOT_DIR/releases/$REL_VSN" export REL_DIR="$RUNNER_ROOT_DIR/releases/$REL_VSN"
SCHEMA_MOD=emqx_conf_schema export SCHEMA_MOD=emqx_conf_schema
WHOAMI=$(whoami) WHOAMI=$(whoami)
export WHOAMI
# Make sure data/configs exists # Make sure data/configs exists
CONFIGS_DIR="$RUNNER_DATA_DIR/configs" export CONFIGS_DIR="$RUNNER_DATA_DIR/configs"
# hocon try to read environment variables starting with "EMQX_" # hocon try to read environment variables starting with "EMQX_"
export HOCON_ENV_OVERRIDE_PREFIX='EMQX_' export HOCON_ENV_OVERRIDE_PREFIX='EMQX_'
@ -33,7 +34,7 @@ export BINDIR="$ERTS_DIR/bin"
export EMU="beam" export EMU="beam"
export PROGNAME="erl" export PROGNAME="erl"
export ERTS_LIB_DIR="$ERTS_DIR/../lib" export ERTS_LIB_DIR="$ERTS_DIR/../lib"
DYNLIBS_DIR="$RUNNER_ROOT_DIR/dynlibs" export DYNLIBS_DIR="$RUNNER_ROOT_DIR/dynlibs"
## backward compatible ## backward compatible
if [ -d "$ERTS_DIR/lib" ]; then if [ -d "$ERTS_DIR/lib" ]; then
@ -56,5 +57,6 @@ SED_REPLACE="sed -i "
case $(sed --help 2>&1) in case $(sed --help 2>&1) in
*GNU*) SED_REPLACE="sed -i ";; *GNU*) SED_REPLACE="sed -i ";;
*BusyBox*) SED_REPLACE="sed -i ";; *BusyBox*) SED_REPLACE="sed -i ";;
*) SED_REPLACE="sed -i '' ";; *) SED_REPLACE=(sed -i '' );;
esac esac
export SED_REPLACE

View File

@ -7,6 +7,9 @@
## they require the variable `IS_BOOT_COMMAND` to be set to either ## they require the variable `IS_BOOT_COMMAND` to be set to either
## `yes` or `no` for the name definition to be done properly. ## `yes` or `no` for the name definition to be done properly.
## This should be sourced after the calling script has define the
## `$COMMAND` variable.
## make EMQX_NODE_COOKIE right ## make EMQX_NODE_COOKIE right
if [ -n "${EMQX_NODE_NAME:-}" ]; then if [ -n "${EMQX_NODE_NAME:-}" ]; then
export EMQX_NODE__NAME="${EMQX_NODE_NAME}" export EMQX_NODE__NAME="${EMQX_NODE_NAME}"
@ -22,7 +25,7 @@ NAME="${EMQX_NODE__NAME:-}"
if [ -z "$NAME" ]; then if [ -z "$NAME" ]; then
if [ "$IS_BOOT_COMMAND" = 'yes' ]; then if [ "$IS_BOOT_COMMAND" = 'yes' ]; then
# for boot commands, inspect emqx.conf for node name # for boot commands, inspect emqx.conf for node name
NAME="$(call_hocon -s $SCHEMA_MOD -I "$CONFIGS_DIR/" -c "$RUNNER_ETC_DIR"/emqx.conf get node.name | tr -d \")" NAME="$(call_hocon -s "$SCHEMA_MOD" -I "$CONFIGS_DIR/" -c "$RUNNER_ETC_DIR"/emqx.conf get node.name | tr -d \")"
else else
vm_args_file="$(latest_vm_args 'EMQX_NODE__NAME')" vm_args_file="$(latest_vm_args 'EMQX_NODE__NAME')"
NAME="$(grep -E '^-s?name' "${vm_args_file}" | awk '{print $2}')" NAME="$(grep -E '^-s?name' "${vm_args_file}" | awk '{print $2}')"
@ -31,7 +34,7 @@ fi
# force to use 'emqx' short name # force to use 'emqx' short name
[ -z "$NAME" ] && NAME='emqx' [ -z "$NAME" ] && NAME='emqx'
MNESIA_DATA_DIR="$RUNNER_DATA_DIR/mnesia/$NAME" export MNESIA_DATA_DIR="$RUNNER_DATA_DIR/mnesia/$NAME"
case "$NAME" in case "$NAME" in
*@*) *@*)
@ -40,6 +43,7 @@ case "$NAME" in
*) *)
NAME_TYPE='-sname' NAME_TYPE='-sname'
esac esac
export NAME_TYPE
SHORT_NAME="$(echo "$NAME" | awk -F'@' '{print $1}')" SHORT_NAME="$(echo "$NAME" | awk -F'@' '{print $1}')"
export ESCRIPT_NAME="$SHORT_NAME" export ESCRIPT_NAME="$SHORT_NAME"
@ -53,7 +57,7 @@ fi
COOKIE="${EMQX_NODE__COOKIE:-}" COOKIE="${EMQX_NODE__COOKIE:-}"
if [ -z "$COOKIE" ]; then if [ -z "$COOKIE" ]; then
if [ "$IS_BOOT_COMMAND" = 'yes' ]; then if [ "$IS_BOOT_COMMAND" = 'yes' ]; then
COOKIE="$(call_hocon -s $SCHEMA_MOD -I "$CONFIGS_DIR/" -c "$RUNNER_ETC_DIR"/emqx.conf get node.cookie | tr -d \")" COOKIE="$(call_hocon -s "$SCHEMA_MOD" -I "$CONFIGS_DIR/" -c "$RUNNER_ETC_DIR"/emqx.conf get node.cookie | tr -d \")"
else else
vm_args_file="$(latest_vm_args 'EMQX_NODE__COOKIE')" vm_args_file="$(latest_vm_args 'EMQX_NODE__COOKIE')"
COOKIE="$(grep -E '^-setcookie' "${vm_args_file}" | awk '{print $2}')" COOKIE="$(grep -E '^-setcookie' "${vm_args_file}" | awk '{print $2}')"

View File

@ -60,6 +60,7 @@ relx_rem_sh() {
TICKTIME="$(relx_nodetool rpcterms net_kernel get_net_ticktime)" TICKTIME="$(relx_nodetool rpcterms net_kernel get_net_ticktime)"
# shellcheck disable=SC2086 # $EPMD_ARG is supposed to be split by whitespace # shellcheck disable=SC2086 # $EPMD_ARG is supposed to be split by whitespace
# shellcheck disable=SC2153 # $NAME_TYPE is defined by `common_defs2.sh`, which runs before this is called
# Setup remote shell command to control node # Setup remote shell command to control node
exec "$BINDIR/erl" "$NAME_TYPE" "$id" -remsh "$NAME" -boot "$REL_DIR/start_clean" \ exec "$BINDIR/erl" "$NAME_TYPE" "$id" -remsh "$NAME" -boot "$REL_DIR/start_clean" \
-boot_var ERTS_LIB_DIR "$ERTS_LIB_DIR" \ -boot_var ERTS_LIB_DIR "$ERTS_LIB_DIR" \
@ -90,7 +91,9 @@ relx_escript() {
"$ERTS_DIR/bin/escript" "$ROOTDIR/$scriptpath" "$@" "$ERTS_DIR/bin/escript" "$ROOTDIR/$scriptpath" "$@"
} }
# Output a start command for the last argument of run_erl # Output a start command for the last argument of run_erl.
# The calling script defines `$START_OPTION`, when the command is to
# start EMQX in the background.
relx_start_command() { relx_start_command() {
printf "exec \"%s\" \"%s\"" "$RUNNER_SCRIPT" \ printf "exec \"%s\" \"%s\"" "$RUNNER_SCRIPT" \
"$START_OPTION" "$START_OPTION"
@ -128,6 +131,7 @@ generate_config() {
# This is needed by the Elixir scripts. # This is needed by the Elixir scripts.
# Do NOT append `.config`. # Do NOT append `.config`.
RELEASE_SYS_CONFIG="$CONFIGS_DIR/app.$NOW_TIME" RELEASE_SYS_CONFIG="$CONFIGS_DIR/app.$NOW_TIME"
export RELEASE_SYS_CONFIG
CONFIG_ARGS="-config $CONF_FILE -args_file $HOCON_GEN_ARG_FILE" CONFIG_ARGS="-config $CONF_FILE -args_file $HOCON_GEN_ARG_FILE"
@ -212,6 +216,7 @@ latest_vm_args() {
echo "$vm_args_file" echo "$vm_args_file"
else else
echoerr "node not initialized?" echoerr "node not initialized?"
# shellcheck disable=SC2153 # $COMMAND is defined by the calling script
echoerr "Generated config file vm.*.args is not found for command '$COMMAND'" echoerr "Generated config file vm.*.args is not found for command '$COMMAND'"
echoerr "in config dir: $CONFIGS_DIR" echoerr "in config dir: $CONFIGS_DIR"
echoerr "In case the file has been deleted while the node is running," echoerr "In case the file has been deleted while the node is running,"

View File

@ -5,7 +5,9 @@
set -euo pipefail set -euo pipefail
BASE="$(cd "$(dirname "$(readlink "$0" || echo "$0")")"/..; pwd -P)" BASE="$(cd "$(dirname "$(readlink "$0" || echo "$0")")"/..; pwd -P)"
# shellcheck disable=SC1090,SC1091
source "$BASE/bin/common_defs.sh" source "$BASE/bin/common_defs.sh"
# shellcheck disable=SC1090,SC1091
source "$BASE/bin/common_functions.sh" source "$BASE/bin/common_functions.sh"
# Make sure log directory exists # Make sure log directory exists
@ -182,7 +184,9 @@ case "${COMMAND}" in
IS_BOOT_COMMAND='no' IS_BOOT_COMMAND='no'
;; ;;
esac esac
export IS_BOOT_COMMAND
# shellcheck disable=SC1090,SC1091
source "$BASE/bin/common_defs2.sh" source "$BASE/bin/common_defs2.sh"
cd "$ROOTDIR" cd "$ROOTDIR"
@ -205,6 +209,7 @@ case "${COMMAND}" in
HEART_OPTION="start" HEART_OPTION="start"
;; ;;
esac esac
export START_OPTION
RUN_PARAM="$*" RUN_PARAM="$*"
# Set arguments for the heart command # Set arguments for the heart command

View File

@ -1,10 +1,11 @@
#!/bin/sh #!/bin/sh
set -eu set -eu
# shellcheck disable=SC1090,SC1091
ROOT_DIR="$(cd "$(dirname "$(readlink "$0" || echo "$0")")"/..; pwd -P)" ROOT_DIR="$(cd "$(dirname "$(readlink "$0" || echo "$0")")"/..; pwd -P)"
echo "Running node dump in ${ROOT_DIR}" echo "Running node dump in ${ROOT_DIR}"
# shellcheck disable=SC1090 # shellcheck disable=SC1090,SC1091
. "$ROOT_DIR"/releases/emqx_vars . "$ROOT_DIR"/releases/emqx_vars
cd "${ROOT_DIR}" cd "${ROOT_DIR}"

View File

@ -1,6 +1,4 @@
#!/bin/bash #!/bin/bash
# shellcheck disable=SC1000-SC9999
set -ex set -ex
mix release --overwrite mix release --overwrite

View File

@ -5,7 +5,9 @@
set -euo pipefail set -euo pipefail
BASE="$(cd "$(dirname "$(readlink "$0" || echo "$0")")"/..; pwd -P)" BASE="$(cd "$(dirname "$(readlink "$0" || echo "$0")")"/..; pwd -P)"
# shellcheck disable=SC1090,SC1091
source "$BASE/bin/common_defs.sh" source "$BASE/bin/common_defs.sh"
# shellcheck disable=SC1090,SC1091
source "$BASE/bin/common_functions.sh" source "$BASE/bin/common_functions.sh"
# Make sure log directory exists # Make sure log directory exists
@ -30,12 +32,14 @@ case "${COMMAND}" in
IS_BOOT_COMMAND='no' IS_BOOT_COMMAND='no'
;; ;;
esac esac
export IS_BOOT_COMMAND
# shellcheck disable=SC1090,SC1091
source "$BASE/bin/common_defs2.sh" source "$BASE/bin/common_defs2.sh"
cd "$ROOTDIR" cd "$ROOTDIR"
# FIXME!!! # FIXME!!! Create case for commands.
generate_config "$NAME_TYPE" "$NAME" generate_config "$NAME_TYPE" "$NAME"
# Must be explicitly exported here in order to be picked up correctly # Must be explicitly exported here in order to be picked up correctly
export RELEASE_SYS_CONFIG export RELEASE_SYS_CONFIG

View File

@ -3,7 +3,14 @@
set -euo pipefail set -euo pipefail
target_files=() target_files=()
while IFS='' read -r line; do target_files+=("$line"); done < <(grep -r -l --exclude-dir=.git --exclude-dir=_build "#!/bin/" .) while IFS='' read -r line;
do
target_files+=("$line");
done < <(grep -r -l \
--exclude-dir=.git \
--exclude-dir=_build \
--exclude-dir=deps \
"^#!/bin/" .)
return_code=0 return_code=0
for i in "${target_files[@]}"; do for i in "${target_files[@]}"; do
echo checking "$i" ... echo checking "$i" ...