From 13a071d1cc382b14ca19e84346d6c2fc9829190c Mon Sep 17 00:00:00 2001 From: Harshvir Potpose Date: Sun, 8 Oct 2023 18:26:23 +0530 Subject: [PATCH] Fixes #4822: fixed all warnning produced by shellcheck Signed-off-by: Harshvir Potpose --- scripts/build-all-in-one-image.sh | 8 +++--- scripts/build-crossdock.sh | 2 +- scripts/build-upload-a-docker-image.sh | 10 +++---- scripts/cassandra-integration-test.sh | 16 ++++++----- scripts/check-go-version.sh | 30 +++++++++++--------- scripts/check-test-files.sh | 10 +++---- scripts/compute-tags.sh | 8 +++--- scripts/es-integration-test.sh | 38 ++++++++++++++------------ scripts/generate-help-output.sh | 2 +- scripts/hotrod-integration-test.sh | 7 +++-- scripts/import-order-cleanup.sh | 4 +-- scripts/package-deploy.sh | 31 +++++++++++---------- scripts/rebuild-ui.sh | 4 +-- scripts/update-semconv-version.sh | 2 +- scripts/updateLicenses.sh | 2 +- 15 files changed, 92 insertions(+), 82 deletions(-) diff --git a/scripts/build-all-in-one-image.sh b/scripts/build-all-in-one-image.sh index 3db543dad98..104a1b645fd 100755 --- a/scripts/build-all-in-one-image.sh +++ b/scripts/build-all-in-one-image.sh @@ -25,14 +25,14 @@ make build-ui run_integration_test() { local image_name="$1" - CID=$(docker run -d -p 16686:16686 -p 5778:5778 ${image_name}:${GITHUB_SHA}) + CID=$(docker run -d -p 16686:16686 -p 5778:5778 "${image_name}:${GITHUB_SHA}") if ! make all-in-one-integration-test ; then echo "---- integration test failed unexpectedly ----" echo "--- check the docker log below for details ---" - docker logs $CID + docker logs "$CID" exit 1 fi - docker kill $CID + docker kill "$CID" } if [ "$mode" = "pr-only" ]; then @@ -58,7 +58,7 @@ bash scripts/build-upload-a-docker-image.sh -b -c all-in-one -d cmd/all-in-one - # build debug image if not on a pull request if [ "$mode" != "pr-only" ]; then - make build-all-in-one-debug GOOS=linux GOARCH=$GOARCH + make build-all-in-one-debug GOOS=linux GOARCH="$GOARCH" repo=${repo}-debug # build all-in-one-debug image locally for integration test diff --git a/scripts/build-crossdock.sh b/scripts/build-crossdock.sh index bb8f630533f..7786815b53e 100755 --- a/scripts/build-crossdock.sh +++ b/scripts/build-crossdock.sh @@ -17,7 +17,7 @@ if [[ "$BRANCH" == "main" ]]; then docker buildx build --push \ --progress=plain \ --platform=linux/amd64 \ - ${IMAGE_TAGS} \ + "${IMAGE_TAGS}" \ crossdock/ else echo 'skip docker images upload for PR' diff --git a/scripts/build-upload-a-docker-image.sh b/scripts/build-upload-a-docker-image.sh index 6fda915e919..009c425c6f0 100644 --- a/scripts/build-upload-a-docker-image.sh +++ b/scripts/build-upload-a-docker-image.sh @@ -62,11 +62,11 @@ else fi docker buildx build --output "${PUSHTAG}" \ - --progress=plain ${target_arg} ${base_debug_img_arg}\ - --platform=${platforms} \ - --file ${docker_file_arg} \ - ${IMAGE_TAGS} \ - ${dir_arg} + --progress=plain "${target_arg}" "${base_debug_img_arg}"\ + --platform="${platforms}" \ + --file "${docker_file_arg}" \ + "${IMAGE_TAGS}" \ + "${dir_arg}" echo "Finished building${upload_flag} ${component_name} ==============" diff --git a/scripts/cassandra-integration-test.sh b/scripts/cassandra-integration-test.sh index c0e55032c06..b11020b1636 100755 --- a/scripts/cassandra-integration-test.sh +++ b/scripts/cassandra-integration-test.sh @@ -23,14 +23,15 @@ setup_cassandra() { --publish 9042:9042 --publish 9160:9160 ) - local cid=$(docker run ${params[@]} ${image}:${tag}) - echo ${cid} + local cid + cid=$(docker run "${params[@]}" "${image}:${tag}") + echo "${cid}" } teardown_cassandra() { local cid=$1 - docker kill ${cid} - exit ${exit_status} + docker kill "${cid}" + exit "${exit_status}" } apply_schema() { @@ -45,17 +46,18 @@ apply_schema() { --network host ) docker build -t ${image} ${schema_dir} - docker run ${params[@]} ${image} + docker run "${params[@]}" "${image}" } run_integration_test() { local version=$1 local schema_version=$2 - local cid=$(setup_cassandra ${version}) + local cid + cid=$(setup_cassandra "${version}") apply_schema "$2" STORAGE=cassandra make storage-integration-test exit_status=$? - trap "teardown_cassandra ${cid}" EXIT + trap 'teardown_cassandra ${cid}' EXIT } main() { diff --git a/scripts/check-go-version.sh b/scripts/check-go-version.sh index 625081a2da4..94af94cbce3 100755 --- a/scripts/check-go-version.sh +++ b/scripts/check-go-version.sh @@ -8,13 +8,17 @@ while getopts "uvd" opt; do case $opt in u) update=true ;; v) verbose=true ;; - x) set -x ;; *) echo "Usage: $0 [-u] [-v] [-d]" >&2 exit 1 ;; esac done +# Debugging option (-x) used separately +if [[ "$DEBUG" == "true" ]]; then + set -x +fi + # Fetch latest go release version go_latest_version=$(curl -s https://go.dev/dl/?mode=json | jq -r '.[0].version' | awk -F'.' '{gsub("go", ""); print $1"."$2}') go_previous_version="${go_latest_version%.*}.$((10#${go_latest_version#*.} - 1))" @@ -31,19 +35,19 @@ function update() { old_IFS=$IFS IFS='' while read -r line; do - match=$(echo $line | grep -e "$pattern") + match=$(echo "$line" | grep -e "$pattern") if [[ "$match" != "" ]]; then - line=$(echo "$line" | sed "s/${current}/${target}/g") + line=${line//${current}/${target}} fi - echo $line >> $newfile - done < $file + echo "$line" >> "$newfile" + done < "$file" IFS=$old_IFS if [ $verbose = true ]; then - diff $file $newfile + diff "$file" "$newfile" fi - mv $newfile $file + mv "$newfile" "$file" } function check() { @@ -51,7 +55,7 @@ function check() { local pattern=$2 local target=$3 - go_version=$(grep -e "$pattern" $file | head -1 | sed "s/^.*\($version_regex\).*$/\1/") + go_version=$(grep -e "$pattern" "$file" | head -1 | sed "s/^.*\($version_regex\).*$/\1/") if [ "$go_version" = "$target" ]; then mismatch='' @@ -68,16 +72,16 @@ function check() { printf "%-50s Go version: %s %s\n" "$file" "$go_version" "$mismatch" } -check go.mod "^go\s\+$version_regex" $go_previous_version +check go.mod "^go\s\+$version_regex" "$go_previous_version" -check docker/Makefile "^.*golang:$version_regex" $go_latest_version +check docker/Makefile "^.*golang:$version_regex" "$go_latest_version" gha_workflows=$(grep -rl go-version .github) -for gha_workflow in ${gha_workflows[@]}; do - check $gha_workflow "^\s*go-version:\s\+$version_regex" $go_latest_version +for gha_workflow in "${gha_workflows[@]}"; do + check "$gha_workflow" "^\s*go-version:\s\+$version_regex" "$go_latest_version" done -check .golangci.yml "go:\s\+\"$version_regex\"" $go_previous_version +check .golangci.yml "go:\s\+\"$version_regex\"" "$go_previous_version" if [ $files_to_update -eq 0 ]; then echo "All files are up to date." diff --git a/scripts/check-test-files.sh b/scripts/check-test-files.sh index c9d06fc6780..afe84e15574 100755 --- a/scripts/check-test-files.sh +++ b/scripts/check-test-files.sh @@ -7,14 +7,14 @@ COLOR_FIXME=$(printf "\033[31mFIXME\033[0m") NO_TEST_FILE_DIRS="" # shellcheck disable=SC2048 for dir in $*; do - mainFile=$(find ${dir} -maxdepth 1 -name 'main.go') - testFiles=$(find ${dir} -maxdepth 1 -name '*_test.go') + mainFile=$(find "${dir}" -maxdepth 1 -name 'main.go') + testFiles=$(find "${dir}" -maxdepth 1 -name '*_test.go') if [ -z "${testFiles}" ]; then if [ -n "${mainFile}" ]; then continue # single main does not require tests fi - if [ -e ${dir}/.nocover ]; then - reason=$(cat ${dir}/.nocover) + if [ -e "${dir}"/.nocover ]; then + reason=$(cat "${dir}"/.nocover) if [ "${reason}" == "" ]; then echo "error: ${dir}/.nocover must specify reason" >&2 exit 1 @@ -33,7 +33,7 @@ done if [ -n "${NO_TEST_FILE_DIRS}" ]; then echo "*** directories without *_test.go files:" >&2 - echo ${NO_TEST_FILE_DIRS} | tr ' ' '\n' >&2 + echo "${NO_TEST_FILE_DIRS}" | tr ' ' '\n' >&2 echo "error: at least one *_test.go file must be in all directories with go files so that they are counted for code coverage" >&2 echo " if no tests are possible for a package (e.g. it only defines types), create empty_test.go" >&2 exit 1 diff --git a/scripts/compute-tags.sh b/scripts/compute-tags.sh index 8198f493b9b..73fd63833d9 100644 --- a/scripts/compute-tags.sh +++ b/scripts/compute-tags.sh @@ -10,9 +10,9 @@ BRANCH=${BRANCH:?'expecting BRANCH env var'} ## if we are on a release tag, let's extract the version number ## the other possible value, currently, is 'main' (or another branch name) if [[ $BRANCH =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then - MAJOR_MINOR_PATCH=$(echo ${BRANCH} | grep -Po "([\d\.]+)") - MAJOR_MINOR=$(echo ${MAJOR_MINOR_PATCH} | awk -F. '{print $1"."$2}') - MAJOR=$(echo ${MAJOR_MINOR_PATCH} | awk -F. '{print $1}') + MAJOR_MINOR_PATCH=$(echo "${BRANCH}" | grep -Po "([\d\.]+)") + MAJOR_MINOR=$(echo "${MAJOR_MINOR_PATCH}" | awk -F. '{print $1"."$2}') + MAJOR=$(echo "${MAJOR_MINOR_PATCH}" | awk -F. '{print $1}') else MAJOR_MINOR_PATCH="latest" MAJOR_MINOR="" @@ -36,4 +36,4 @@ fi IMAGE_TAGS="${IMAGE_TAGS} --tag docker.io/${SNAPSHOT_TAG} --tag quay.io/${SNAPSHOT_TAG}" -echo ${IMAGE_TAGS} +echo "${IMAGE_TAGS}" diff --git a/scripts/es-integration-test.sh b/scripts/es-integration-test.sh index 680f1017173..a88cb396aab 100755 --- a/scripts/es-integration-test.sh +++ b/scripts/es-integration-test.sh @@ -29,8 +29,9 @@ setup_es() { --env "xpack.security.enabled=false" --env "xpack.monitoring.enabled=false" ) - local cid=$(docker run ${params[@]} ${image}:${tag}) - echo ${cid} + local cid + cid=$(docker run "${params[@]}" "${image}:${tag}") + echo "${cid}" } setup_opensearch() { @@ -43,8 +44,9 @@ setup_opensearch() { --env "transport.host=127.0.0.1" --env "plugins.security.disabled=true" ) - local cid=$(docker run ${params[@]} ${image}:${tag}) - echo ${cid} + local cid + cid=$(docker run "${params[@]}" "${image}:${tag}") + echo "${cid}" } wait_for_storage() { @@ -56,21 +58,21 @@ wait_for_storage() { --output /dev/null --write-out - ''%{http_code}'' + "%{http_code}" ) local counter=0 local max_counter=60 - while [[ "$(curl ${params[@]} ${url})" != "200" && ${counter} -le ${max_counter} ]]; do - docker inspect ${cid} | jq '.[].State' + while [[ "$(curl "${params[@]}" "${url}")" != "200" && ${counter} -le ${max_counter} ]]; do + docker inspect "${cid}" | jq '.[].State' echo "waiting for ${url} to be up..." sleep 10 counter=$((counter+1)) done # after the loop, do final verification and set status as global var - if [[ "$(curl ${params[@]} ${url})" != "200" ]]; then + if [[ "$(curl "${params[@]}" "${url}")" != "200" ]]; then echo "ERROR: ${distro} is not ready" - docker logs ${cid} - docker kill ${cid} + docker logs "${cid}" + docker kill "${cid}" db_is_up=0 else echo "SUCCESS: ${distro} is ready" @@ -87,21 +89,21 @@ bring_up_storage() { for retry in 1 2 3 do echo "attempt $retry" - if [ ${distro} = "elasticsearch" ]; then - cid=$(setup_es ${version}) - elif [ ${distro} == "opensearch" ]; then - cid=$(setup_opensearch ${version}) + if [ "${distro}" = "elasticsearch" ]; then + cid=$(setup_es "${version}") + elif [ "${distro}" == "opensearch" ]; then + cid=$(setup_opensearch "${version}") else echo "Unknown distribution $distro. Valid options are opensearch or elasticsearch" usage fi - wait_for_storage ${distro} "http://localhost:9200" ${cid} + wait_for_storage "${distro}" "http://localhost:9200" "${cid}" if [ ${db_is_up} = "1" ]; then break fi done if [ ${db_is_up} = "1" ]; then - trap "teardown_storage ${cid}" EXIT + trap 'teardown_storage ${cid}' EXIT else echo "ERROR: unable to start ${distro}" exit 1 @@ -110,7 +112,7 @@ bring_up_storage() { teardown_storage() { local cid=$1 - docker kill ${cid} + docker kill "${cid}" } main() { @@ -118,7 +120,7 @@ main() { local distro=$1 local version=$2 - bring_up_storage ${distro} ${version} + bring_up_storage "${distro}" "${version}" STORAGE=${distro} make storage-integration-test make index-cleaner-integration-test make index-rollover-integration-test diff --git a/scripts/generate-help-output.sh b/scripts/generate-help-output.sh index f138c77adad..072037e3945 100755 --- a/scripts/generate-help-output.sh +++ b/scripts/generate-help-output.sh @@ -14,7 +14,7 @@ function gen { shift for s in "$@" do - SPAN_STORAGE_TYPE=$s go run ./cmd/$bin help > $dir/$bin-$s.txt + SPAN_STORAGE_TYPE=$s go run ./cmd/"$bin" help > "$dir"/"$bin"-"$s".txt done } diff --git a/scripts/hotrod-integration-test.sh b/scripts/hotrod-integration-test.sh index d9a907d718c..fff1a0e19bb 100755 --- a/scripts/hotrod-integration-test.sh +++ b/scripts/hotrod-integration-test.sh @@ -13,9 +13,10 @@ make prepare-docker-buildx #build image locally for integration test bash scripts/build-upload-a-docker-image.sh -l -c example-hotrod -d examples/hotrod -p "${platforms}" -export CID=$(docker run -d -p 8080:8080 localhost:5000/$REPO:${GITHUB_SHA}) +export CID +CID=$(docker run -d -p 8080:8080 localhost:5000/$REPO:"${GITHUB_SHA}") i=0 -while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:8080)" != "200" && ${i} -lt 30 ]]; do +while [[ "$(curl -s -o /dev/null -w "%{http_code}" localhost:8080)" != "200" && ${i} -lt 30 ]]; do sleep 1 i=$((i+1)) done @@ -24,6 +25,6 @@ if [[ $body != *"Rides On Demand"* ]]; then echo "String \"Rides On Demand\" is not present on the index page" exit 1 fi -docker rm -f $CID +docker rm -f "$CID" bash scripts/build-upload-a-docker-image.sh -c example-hotrod -d examples/hotrod -p "${platforms}" diff --git a/scripts/import-order-cleanup.sh b/scripts/import-order-cleanup.sh index b912652f87f..758ce00ad42 100755 --- a/scripts/import-order-cleanup.sh +++ b/scripts/import-order-cleanup.sh @@ -2,8 +2,8 @@ set -e -# shellcheck disable=SC2046 -- we want multple arguments here -./scripts/import-order-cleanup.py -o $1 -t $(git ls-files "*\.go" | \ +# shellcheck disable=SC2046 # we want multple arguments here +./scripts/import-order-cleanup.py -o "$1" -t $(git ls-files "*\.go" | \ grep -v \ -e thrift-gen \ -e swagger-gen \ diff --git a/scripts/package-deploy.sh b/scripts/package-deploy.sh index 2719b15f006..6ca4143fce4 100755 --- a/scripts/package-deploy.sh +++ b/scripts/package-deploy.sh @@ -9,12 +9,12 @@ function stage-platform-files { local -r PACKAGE_STAGING_DIR=$2 local -r FILE_EXTENSION=${3:-} - cp ./cmd/all-in-one/all-in-one-$PLATFORM $PACKAGE_STAGING_DIR/jaeger-all-in-one$FILE_EXTENSION - cp ./cmd/agent/agent-$PLATFORM $PACKAGE_STAGING_DIR/jaeger-agent$FILE_EXTENSION - cp ./cmd/query/query-$PLATFORM $PACKAGE_STAGING_DIR/jaeger-query$FILE_EXTENSION - cp ./cmd/collector/collector-$PLATFORM $PACKAGE_STAGING_DIR/jaeger-collector$FILE_EXTENSION - cp ./cmd/ingester/ingester-$PLATFORM $PACKAGE_STAGING_DIR/jaeger-ingester$FILE_EXTENSION - cp ./examples/hotrod/hotrod-$PLATFORM $PACKAGE_STAGING_DIR/example-hotrod$FILE_EXTENSION + cp ./cmd/all-in-one/all-in-one-"$PLATFORM" "$PACKAGE_STAGING_DIR"/jaeger-all-in-one"$FILE_EXTENSION" + cp ./cmd/agent/agent-"$PLATFORM" "$PACKAGE_STAGING_DIR"/jaeger-agent"$FILE_EXTENSION" + cp ./cmd/query/query-"$PLATFORM" "$PACKAGE_STAGING_DIR"/jaeger-query"$FILE_EXTENSION" + cp ./cmd/collector/collector-"$PLATFORM" "$PACKAGE_STAGING_DIR"/jaeger-collector"$FILE_EXTENSION" + cp ./cmd/ingester/ingester-"$PLATFORM" "$PACKAGE_STAGING_DIR"/jaeger-ingester"$FILE_EXTENSION" + cp ./examples/hotrod/hotrod-"$PLATFORM" "$PACKAGE_STAGING_DIR"/example-hotrod"$FILE_EXTENSION" } # package pulls built files for the platform ($2) and compresses it using the compression ($1). @@ -26,32 +26,33 @@ function package { local -r PACKAGE_NAME=jaeger-$VERSION-$PLATFORM local -r PACKAGE_STAGING_DIR=$PACKAGE_NAME - if [ -d $PACKAGE_STAGING_DIR ] + if [ -d "$PACKAGE_STAGING_DIR" ] then rm -vrf "$PACKAGE_STAGING_DIR" fi - mkdir $PACKAGE_STAGING_DIR - stage-platform-files $PLATFORM $PACKAGE_STAGING_DIR $FILE_EXTENSION + mkdir "$PACKAGE_STAGING_DIR" + stage-platform-files "$PLATFORM" "$PACKAGE_STAGING_DIR" "$FILE_EXTENSION" # Create a checksum file for all the files being packaged in the archive. Sorted by filename. - find $PACKAGE_STAGING_DIR -type f -exec shasum -b -a 256 {} \; | sort -k2 | tee ./deploy/$PACKAGE_NAME.sha256sum.txt + find "$PACKAGE_STAGING_DIR" -type f -exec shasum -b -a 256 {} \; | sort -k2 | tee "./deploy/$PACKAGE_NAME.sha256sum.txt" if [ "$COMPRESSION" == "zip" ] then local -r ARCHIVE_NAME="$PACKAGE_NAME.zip" echo "Packaging into $ARCHIVE_NAME:" - zip -r ./deploy/$ARCHIVE_NAME $PACKAGE_STAGING_DIR + zip -r "./deploy/$ARCHIVE_NAME" "$PACKAGE_STAGING_DIR" else local -r ARCHIVE_NAME="$PACKAGE_NAME.tar.gz" echo "Packaging into $ARCHIVE_NAME:" - tar --sort=name -czvf ./deploy/$ARCHIVE_NAME $PACKAGE_STAGING_DIR + tar --sort=name -czvf "./deploy/$ARCHIVE_NAME" "$PACKAGE_STAGING_DIR" fi - rm -rf $PACKAGE_STAGING_DIR + rm -rf "$PACKAGE_STAGING_DIR" } set -e -readonly VERSION="$(make echo-version | perl -lne 'print $1 if /^v(\d+.\d+.\d+)$/' )" +readonly VERSION +VERSION="$(make echo-version | perl -lne 'print $1 if /^v(\d+.\d+.\d+)$/' )" echo "Working on version: $VERSION" if [ -z "$VERSION" ]; then # We want to halt if for some reason the version string is empty as this is an obvious error case @@ -73,7 +74,7 @@ package tar linux-arm64 package tar linux-ppc64le # Create a checksum file for all non-checksum files in the deploy directory. Strips the leading 'deploy/' directory from filepaths. Sort by filename. -find deploy \( ! -name '*sha256sum.txt' \) -type f -exec shasum -b -a 256 {} \; | sed -r 's#(\w+\s+\*?)deploy/(.*)#\1\2#' | sort -k2 | tee ./deploy/jaeger-$VERSION.sha256sum.txt +find deploy \( ! -name '*sha256sum.txt' \) -type f -exec shasum -b -a 256 {} \; | sed -r 's#(\w+\s+\*?)deploy/(.*)#\1\2#' | sort -k2 | tee ./deploy/jaeger-"$VERSION".sha256sum.txt # Use gpg to sign the (g)zip files (excluding checksum files) into .asc files. find deploy \( ! -name '*sha256sum.txt' \) -type f -exec gpg --armor --detach-sign {} \; diff --git a/scripts/rebuild-ui.sh b/scripts/rebuild-ui.sh index 04344d24a24..83c50ea0315 100644 --- a/scripts/rebuild-ui.sh +++ b/scripts/rebuild-ui.sh @@ -11,11 +11,11 @@ last_tag=$(git describe --tags --dirty 2>/dev/null) if [[ "$last_tag" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then branch_hash=$(git rev-parse HEAD) - last_tag_hash=$(git rev-parse $last_tag) + last_tag_hash=$(git rev-parse "$last_tag") if [[ "$branch_hash" == "$last_tag_hash" ]]; then temp_file=$(mktemp) - trap "rm -f ${temp_file}" EXIT + trap 'rm -f "${temp_file}"' EXIT release_url="https://github.com/jaegertracing/jaeger-ui/releases/download/${last_tag}/assets.tar.gz" if curl --silent --fail --location --output "$temp_file" "$release_url"; then diff --git a/scripts/update-semconv-version.sh b/scripts/update-semconv-version.sh index bc140caddae..73a5b83779f 100755 --- a/scripts/update-semconv-version.sh +++ b/scripts/update-semconv-version.sh @@ -6,7 +6,7 @@ version_regex="v[0-9]\.[0-9]\+\.[0-9]\+" latest_semconv_version=$( curl -s https://pkg.go.dev/$package_name \ | grep -oP 'data-id="v\d+\.\d+\.\d+"' \ - | sed -E 's/\"($version_regex)\"/v\1/' \ + | sed -E "s/\"($version_regex)\"/v\1/" \ | sort -Vr \ | head -n 1 \ | awk -F'"' '{print $2}' diff --git a/scripts/updateLicenses.sh b/scripts/updateLicenses.sh index b1d747cb749..ed305e1b521 100755 --- a/scripts/updateLicenses.sh +++ b/scripts/updateLicenses.sh @@ -2,7 +2,7 @@ set -e -# shellcheck disable=SC2046 -- we want multple arguments here +# shellcheck disable=SC2046 # we want multple arguments here ./scripts/updateLicense.py $(git ls-files "*\.go" | \ grep -v \ -e thrift-gen \