From a7b388602c96314c69c56d1914f495a2f6f3c97a Mon Sep 17 00:00:00 2001 From: Nick Schonning Date: Thu, 8 Jun 2017 01:24:48 -0400 Subject: [PATCH 1/7] Add Shellcheck to Travis build --- .travis.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.travis.yml b/.travis.yml index 304fea2c..c414d9a3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,15 @@ sudo: required services: - docker +addons: + apt: + sources: + - debian-sid + packages: + - shellcheck + script: + - shellcheck *.sh - ./test-build.sh $NODE_VERSION env: From 5380d0fffa069914120155e8323e49c4fac0c252 Mon Sep 17 00:00:00 2001 From: Nick Schonning Date: Wed, 14 Jun 2017 02:24:18 -0400 Subject: [PATCH 2/7] Shellcheck: Ignore SC2034 for version alias arrays MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These are used dynamically which shellcheck can’t tell --- generate-stackbrew-library.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/generate-stackbrew-library.sh b/generate-stackbrew-library.sh index 84688ffa..6b8fb972 100755 --- a/generate-stackbrew-library.sh +++ b/generate-stackbrew-library.sh @@ -3,8 +3,12 @@ set -e hash git 2>/dev/null || { echo >&2 "git not found, exiting."; } +# Used dynamically: print "$array_" $1 +# shellcheck disable=SC2034 array_4_8='4 argon'; +# shellcheck disable=SC2034 array_6_11='6 boron'; +# shellcheck disable=SC2034 array_8_1='8 latest'; cd $(cd ${0%/*} && pwd -P); From 359ba16fe0ae70c3ce57e5f4dba96243e03a420f Mon Sep 17 00:00:00 2001 From: Nick Schonning Date: Wed, 14 Jun 2017 02:45:21 -0400 Subject: [PATCH 3/7] Shellcheck: SC2181 Check exit code directly --- test-build.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test-build.sh b/test-build.sh index 0158f632..13455fe9 100755 --- a/test-build.sh +++ b/test-build.sh @@ -31,9 +31,8 @@ for version in "${versions[@]}"; do tag=$(cat $version/Dockerfile | grep "ENV NODE_VERSION" | cut -d' ' -f3) info "Building $tag..." - docker build -t node:$tag $version - if [[ $? -gt 0 ]]; then + if ! docker build -t node:$tag $version; then fatal "Build of $tag failed!" else info "Build of $tag succeeded." @@ -53,9 +52,8 @@ for version in "${versions[@]}"; do [ -f "$version/$variant/Dockerfile" ] || continue info "Building $tag-$variant variant..." - docker build -t node:$tag-$variant $version/$variant - if [[ $? -gt 0 ]]; then + if ! docker build -t node:$tag-$variant $version/$variant; then fatal "Build of $tag-$variant failed!" else info "Build of $tag-$variant succeeded." From d2d0efe69cce764eb5def83929f69188d2da9cfb Mon Sep 17 00:00:00 2001 From: Nick Schonning Date: Wed, 14 Jun 2017 02:38:15 -0400 Subject: [PATCH 4/7] Shellcheck: SC2046 and SC2086 quoting --- generate-stackbrew-library.sh | 6 +++--- test-build.sh | 16 ++++++++-------- update.sh | 4 ++-- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/generate-stackbrew-library.sh b/generate-stackbrew-library.sh index 6b8fb972..f515b5fb 100755 --- a/generate-stackbrew-library.sh +++ b/generate-stackbrew-library.sh @@ -11,7 +11,7 @@ array_6_11='6 boron'; # shellcheck disable=SC2034 array_8_1='8 latest'; -cd $(cd ${0%/*} && pwd -P); +cd "$(cd "${0%/*}" && pwd -P)"; self="$(basename "$BASH_SOURCE")" @@ -44,7 +44,7 @@ for version in "${versions[@]}"; do # Skip "docs" and other non-docker directories [ -f "$version/Dockerfile" ] || continue - eval stub=$(echo "$version" | awk -F. '{ print "$array_" $1 "_" $2 }'); + eval stub="$(echo "$version" | awk -F. '{ print "$array_" $1 "_" $2 }')"; commit="$(fileCommit "$version")" fullVersion="$(grep -m1 'ENV NODE_VERSION ' "$version/Dockerfile" | cut -d' ' -f3)" @@ -55,7 +55,7 @@ for version in "${versions[@]}"; do echo "Directory: ${version}" echo - variants=$(echo $version/*/ | xargs -n1 basename) + variants=$(echo "$version"/*/ | xargs -n1 basename) for variant in $variants; do # Skip non-docker directories [ -f "$version/$variant/Dockerfile" ] || continue diff --git a/test-build.sh b/test-build.sh index 13455fe9..55b64427 100755 --- a/test-build.sh +++ b/test-build.sh @@ -16,7 +16,7 @@ fatal() { exit 1 } -cd $(cd ${0%/*} && pwd -P); +cd "$(cd "${0%/*}" && pwd -P)"; versions=( "$@" ) if [ ${#versions[@]} -eq 0 ]; then @@ -28,38 +28,38 @@ for version in "${versions[@]}"; do # Skip "docs" and other non-docker directories [ -f "$version/Dockerfile" ] || continue - tag=$(cat $version/Dockerfile | grep "ENV NODE_VERSION" | cut -d' ' -f3) + tag=$(cat "$version/Dockerfile" | grep "ENV NODE_VERSION" | cut -d' ' -f3) info "Building $tag..." - if ! docker build -t node:$tag $version; then + if ! docker build -t node:"$tag" "$version"; then fatal "Build of $tag failed!" else info "Build of $tag succeeded." fi - OUTPUT=$(docker run --rm -it node:$tag node -e "process.stdout.write(process.versions.node)") + OUTPUT=$(docker run --rm -it node:"$tag" node -e "process.stdout.write(process.versions.node)") if [ "$OUTPUT" != "$tag" ]; then fatal "Test of $tag failed!" else info "Test of $tag succeeded." fi - variants=$(echo $version/*/ | xargs -n1 basename) + variants=$(echo "$version"/*/ | xargs -n1 basename) for variant in $variants; do # Skip non-docker directories [ -f "$version/$variant/Dockerfile" ] || continue - + info "Building $tag-$variant variant..." - if ! docker build -t node:$tag-$variant $version/$variant; then + if ! docker build -t node:"$tag-$variant" "$version/$variant"; then fatal "Build of $tag-$variant failed!" else info "Build of $tag-$variant succeeded." fi - OUTPUT=$(docker run --rm -it node:$tag-$variant node -e "process.stdout.write(process.versions.node)") + OUTPUT=$(docker run --rm -it node:"$tag-$variant" node -e "process.stdout.write(process.versions.node)") if [ "$OUTPUT" != "$tag" ]; then fatal "Test of $tag-$variant failed!" else diff --git a/update.sh b/update.sh index 21a0b459..008ac5f6 100755 --- a/update.sh +++ b/update.sh @@ -1,7 +1,7 @@ #!/bin/bash set -e -cd $(cd ${0%/*} && pwd -P); +cd "$(cd "${0%/*}" && pwd -P)"; versions=( "$@" ) if [ ${#versions[@]} -eq 0 ]; then @@ -39,7 +39,7 @@ for version in "${versions[@]}"; do update_node_version - variants=$(echo $version/*/ | xargs -n1 basename) + variants=$(echo "$version"/*/ | xargs -n1 basename) for variant in $variants; do # Skip non-docker directories From 19d6c122192afb59d02192d9d3f6384d325ee639 Mon Sep 17 00:00:00 2001 From: Nick Schonning Date: Wed, 14 Jun 2017 02:59:02 -0400 Subject: [PATCH 5/7] Spellcheck: SC2002 useless cat --- test-build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-build.sh b/test-build.sh index 55b64427..8eb34d6a 100755 --- a/test-build.sh +++ b/test-build.sh @@ -28,7 +28,7 @@ for version in "${versions[@]}"; do # Skip "docs" and other non-docker directories [ -f "$version/Dockerfile" ] || continue - tag=$(cat "$version/Dockerfile" | grep "ENV NODE_VERSION" | cut -d' ' -f3) + tag=$(grep "ENV NODE_VERSION" "$version/Dockerfile" | cut -d' ' -f3) info "Building $tag..." From cce56a99b96d14f1f42fb1208e1542ec88358bb5 Mon Sep 17 00:00:00 2001 From: Nick Schonning Date: Wed, 14 Jun 2017 03:51:35 -0400 Subject: [PATCH 6/7] Shellcheck: SC2128 Expanding an array without an index only gives the first element --- generate-stackbrew-library.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generate-stackbrew-library.sh b/generate-stackbrew-library.sh index f515b5fb..39eff745 100755 --- a/generate-stackbrew-library.sh +++ b/generate-stackbrew-library.sh @@ -13,7 +13,7 @@ array_8_1='8 latest'; cd "$(cd "${0%/*}" && pwd -P)"; -self="$(basename "$BASH_SOURCE")" +self="$(basename "${BASH_SOURCE[0]}")" versions=( */ ) versions=( "${versions[@]%/}" ) From c11be06fa41965f32c0cc2372aa599cafb8277bf Mon Sep 17 00:00:00 2001 From: Nick Schonning Date: Wed, 14 Jun 2017 03:54:55 -0400 Subject: [PATCH 7/7] Shellcheck: SC2164 Use 'cd ... || exit' or 'cd ... || return' in case cd fails --- test-build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-build.sh b/test-build.sh index 8eb34d6a..89c40ea5 100755 --- a/test-build.sh +++ b/test-build.sh @@ -16,7 +16,7 @@ fatal() { exit 1 } -cd "$(cd "${0%/*}" && pwd -P)"; +cd "$(cd "${0%/*}" && pwd -P)" || exit; versions=( "$@" ) if [ ${#versions[@]} -eq 0 ]; then