diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bcfcac3..adb3693 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,12 +8,14 @@ repos: - id: check-yaml - id: double-quote-string-fixer - id: check-shebang-scripts-are-executable + exclude: tools/docker/docker.sh - id: check-executables-have-shebangs - id: detect-private-key - repo: 'https://github.com/jumanjihouse/pre-commit-hooks' rev: 3.0.0 hooks: - id: shellcheck + exclude: tools/docker/docker.sh - id: script-must-have-extension - id: git-dirty - id: git-check diff --git a/tools/docker/docker-entrypoint.sh b/tools/docker/docker-entrypoint.sh index a73eb5e..befded7 100755 --- a/tools/docker/docker-entrypoint.sh +++ b/tools/docker/docker-entrypoint.sh @@ -2,5 +2,6 @@ set -eo pipefail shopt -s nullglob +# shellcheck disable=SC2145 echo "./bin/FullNode $@" > command.txt exec "./bin/FullNode" "$@" diff --git a/tools/docker/test.sh b/tools/docker/test.sh index d961920..fb58cc9 100755 --- a/tools/docker/test.sh +++ b/tools/docker/test.sh @@ -20,6 +20,7 @@ export GOSS_PATH=$TEST_PATH/goss-linux-amd64 export GOSS_OPTS="$GOSS_OPTS --format junit" export GOSS_FILES_STRATEGY=cp DOCKER_IMAGE=$1 +# shellcheck disable=SC2034 DOCKER_FILE="${2:-$PWD/Dockerfile}" i=0 @@ -28,8 +29,11 @@ i=0 # we test that things listen on the right interface/port, not what interface the advertise # hence we dont set p2p-host=0.0.0.0 because this sets what its advertising to devp2p; the important piece is that it defaults to listening on all interfaces GOSS_FILES_PATH=$TEST_PATH/01 \ -bash $TEST_PATH/dgoss run --sysctl net.ipv6.conf.all.disable_ipv6=1 $DOCKER_IMAGE \ -#-p 8090:8090 -p 8091:8091 -p 18888:18888 -p 18888:18888/udp -p 50051:50051 \ +bash $TEST_PATH/dgoss run --sysctl net.ipv6.conf.all.disable_ipv6=1 "$DOCKER_IMAGE" \ +#-p 8090:8090 -p 8091:8091 -p 18888:18888 -p 18888:18888/udp -p 50051:50051 +# shellcheck disable=SC2006 +# shellcheck disable=SC2003 +# shellcheck disable=SC2188 > ./reports/01.xml || i=`expr $i + 1` -exit $i +exit "$i" diff --git a/tools/docker/tests/01/testSync.sh b/tools/docker/tests/01/testSync.sh index 17f9bc8..c789768 100755 --- a/tools/docker/tests/01/testSync.sh +++ b/tools/docker/tests/01/testSync.sh @@ -8,6 +8,7 @@ response=$(curl -X GET http://127.0.0.1:8090/wallet/getnodeinfo) result=$(echo "$response" | jq -r '.beginSyncNum') echo "result 1: $result, response 1: $response" +# shellcheck disable=SC2236 if [ ! -z "$result" ]; then last_sync=$(printf "%d" "$result") last_syncNum=$last_sync @@ -15,7 +16,7 @@ if [ ! -z "$result" ]; then else alert="TRON node first sync error: : $response" - echo $alert + echo "$alert" exit 1 fi @@ -32,22 +33,24 @@ check_sync_process() { result=$(echo "$response" | jq -r '.beginSyncNum') echo "result 2: $result, response 2: $response" + # shellcheck disable=SC2236 if [ ! -z "$result" ]; then last_sync=$(printf "%d" "$result") second_syncNum=$last_sync echo "TRON node second sync: $last_sync" else alert="TRON node second sync error: : $response" - echo $alert + echo "$alert" exit 1 fi } +# shellcheck disable=SC2004 for((i=1;i<=$count;i++)); do echo "try i: $i" sleep $monitor_interval check_sync_process - if [ $second_syncNum -gt $last_syncNum ]; then + if [ "$second_syncNum" -gt "$last_syncNum" ]; then echo "sync increased" exit 0 fi diff --git a/tools/docker/tests/dgoss b/tools/docker/tests/dgoss index ae8e0d4..f29a9f7 100755 --- a/tools/docker/tests/dgoss +++ b/tools/docker/tests/dgoss @@ -32,8 +32,10 @@ setup_container(){ [[ -e "${GOSS_FILES_PATH}/goss.yaml" ]] && cp "${GOSS_FILES_PATH}/goss.yaml" "$tmp_dir" [[ -e "${GOSS_FILES_PATH}/goss_wait.yaml" ]] && cp "${GOSS_FILES_PATH}/goss_wait.yaml" "$tmp_dir" [[ -e "${GOSS_FILES_PATH}/testSync.sh" ]] && cp "${GOSS_FILES_PATH}/testSync.sh" "$tmp_dir" + # shellcheck disable=SC2236 [[ ! -z "${GOSS_VARS}" ]] && [[ -e "${GOSS_FILES_PATH}/${GOSS_VARS}" ]] && cp "${GOSS_FILES_PATH}/${GOSS_VARS}" "$tmp_dir" # copy the Dockerfile if path has been provided + # shellcheck disable=SC2236 [[ ! -z "${3}" ]] && [[ "${3}" == *"Dockerfile"* ]] && cp "${3}" "$tmp_dir" info "Setup complete" @@ -47,11 +49,12 @@ setup_container(){ ;; cp) info "Creating docker container" + # shellcheck disable=SC2068 id=$(docker create ${@:2}) info "Copy goss files into container" - docker cp $tmp_dir/. $id:/goss + docker cp "$tmp_dir"/. "$id":/goss info "Starting docker container" - docker start $id > /dev/null + docker start "$id" > /dev/null ;; *) error "Wrong goss files strategy used! Correct options are \"mount\" or \"cp\"." esac @@ -71,6 +74,7 @@ get_file_from_docker() { # Main tmp_dir=$(mktemp -d /tmp/tmp.XXXXXXXXXX) chmod 777 "$tmp_dir" +# shellcheck disable=SC2154 trap 'ret=$?;cleanup;exit $ret' EXIT GOSS_PATH="${GOSS_PATH:-$(which goss 2> /dev/null || true)}" @@ -119,6 +123,7 @@ case "$1" in docker exec -it "$id" sh -c 'cd /goss; PATH="/goss:$PATH" exec sh' get_file_from_docker "/goss/goss.yaml" get_file_from_docker "/goss/goss_wait.yaml" + # shellcheck disable=SC2236 [[ ! -z "${GOSS_VARS}" ]] && get_file_from_docker "/goss/${GOSS_VARS}" ;; *)