Skip to content

Commit 834e489

Browse files
authored
[chore] activate shellcheck in lint target (#136)
* resolve shellcheck issues, add .shellcheckrc, add shellcheck-lint dependency to lint target
1 parent 03f4928 commit 834e489

File tree

15 files changed

+52
-37
lines changed

15 files changed

+52
-37
lines changed

.shellcheckrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
enable=useless-use-of-cat
2+
3+
disable=SC2164 # cd/popd/push failure check

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ injector-integration-tests-for-all-architectures:
101101
test/scripts/test-all.sh
102102

103103
.PHONY: lint
104-
lint: zig-fmt-check # TODO add the `shellcheck-lint` target here as well, in a follow-up PR.
104+
lint: zig-fmt-check shellcheck-lint
105105

106106
.PHONY: zig-fmt-check
107107
zig-fmt-check: check-zig-installed

packaging/fpm/common.sh

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#!/bin/bash
2+
# shellcheck disable=SC2034 # Some of the variables are used in other scripts
23

34
# Copyright The OpenTelemetry Authors
45
# SPDX-License-Identifier: Apache-2.0
56

6-
FPM_DIR="$( cd "$( dirname ${BASH_SOURCE[0]} )" && pwd )"
7+
FPM_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
78
REPO_DIR="$( cd "$FPM_DIR/../../" && pwd )"
89

910
PKG_NAME="opentelemetry-injector"
@@ -60,7 +61,7 @@ download_java_agent() {
6061
fi
6162

6263
echo "Downloading $dl_url ..."
63-
mkdir -p "$( dirname $dest )"
64+
mkdir -p "$( dirname "$dest" )"
6465
curl -sfL "$dl_url" -o "$dest"
6566
}
6667

@@ -70,8 +71,8 @@ download_nodejs_agent() {
7071
pushd "$(dirname "$dest")"
7172
mkdir -p "js"
7273
pushd "js"
73-
npm pack @opentelemetry/auto-instrumentations-node@${tag#v}
74-
mv *.tgz otel-js.tgz
74+
npm pack "@opentelemetry/auto-instrumentations-node@${tag#v}"
75+
mv ./*.tgz otel-js.tgz
7576
npm install --global=false otel-js.tgz
7677
rm otel-js.tgz
7778
popd
@@ -82,7 +83,7 @@ download_dotnet_agent() {
8283
local tag="$1"
8384
local dest="$2"
8485

85-
case "$ARCH" in
86+
case "${ARCH:-}" in
8687
amd64) local dotnet_arch="x64" ;;
8788
arm64) local dotnet_arch="arm64" ;;
8889
*)
@@ -109,21 +110,24 @@ download_and_unzip_dotnet_agent_for_libc_flavor() {
109110
local dl_url="$DOTNET_AGENT_RELEASE_URL/$tag/$pkg"
110111

111112
echo "Downloading $dl_url ..."
112-
curl -sSfL "$dl_url" -o /tmp/$pkg
113+
curl -sSfL "$dl_url" -o "/tmp/$pkg"
113114

114115
echo "Extracting $pkg to $destination_folder_for_libc_flavor ..."
115116
mkdir -p "$destination_folder_for_libc_flavor"
116-
unzip -d "$destination_folder_for_libc_flavor" /tmp/$pkg
117-
rm -f /tmp/$pkg
117+
unzip -d "$destination_folder_for_libc_flavor" "/tmp/$pkg"
118+
rm -f "/tmp/$pkg"
118119
}
119120

120121
setup_files_and_permissions() {
121122
local arch="$1"
122123
local buildroot="$2"
123124
local libotelinject="$REPO_DIR/dist/libotelinject_${arch}.so"
124-
local java_agent_release="$(cat "$JAVA_AGENT_RELEASE_PATH" | tail -n 1)"
125-
local nodejs_agent_release="$(cat "$NODEJS_AGENT_RELEASE_PATH" | tail -n 1)"
126-
local dotnet_agent_release="$(cat "$DOTNET_AGENT_RELEASE_PATH" | tail -n 1)"
125+
local java_agent_release
126+
local nodejs_agent_release
127+
local dotnet_agent_release
128+
java_agent_release="$(tail -n 1 <"$JAVA_AGENT_RELEASE_PATH")"
129+
nodejs_agent_release="$(tail -n 1 <"$NODEJS_AGENT_RELEASE_PATH")"
130+
dotnet_agent_release="$(tail -n 1 <"$DOTNET_AGENT_RELEASE_PATH")"
127131

128132
mkdir -p "$buildroot/$(dirname $libotelinject_INSTALL_PATH)"
129133
cp -f "$libotelinject" "$buildroot/$libotelinject_INSTALL_PATH"

packaging/fpm/deb/build.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55

66
set -euxo pipefail
77

8-
SCRIPT_DIR="$( cd "$( dirname ${BASH_SOURCE[0]} )" && pwd )"
9-
. $SCRIPT_DIR/../common.sh
8+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
9+
10+
# shellcheck disable=SC1091 # Including common.sh
11+
. "$SCRIPT_DIR/../common.sh"
1012

1113
VERSION="${1:-}"
1214
ARCH="${2:-amd64}"

packaging/fpm/install-deps.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
set -euxo pipefail
77

8-
SCRIPT_DIR="$( cd "$( dirname ${BASH_SOURCE[0]} )" && pwd )"
8+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
99

1010
apt-get update
1111

1212
apt-get install -y ruby ruby-dev rubygems build-essential git rpm sudo curl jq ruby-bundler unzip
1313

14-
bundle install --gemfile ${SCRIPT_DIR}/Gemfile
14+
bundle install --gemfile "${SCRIPT_DIR}/Gemfile"

packaging/fpm/rpm/build.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55

66
set -euxo pipefail
77

8-
SCRIPT_DIR="$( cd "$( dirname ${BASH_SOURCE[0]} )" && pwd )"
9-
. $SCRIPT_DIR/../common.sh
8+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
9+
10+
# shellcheck disable=SC1091 # Including common.sh
11+
. "$SCRIPT_DIR/../common.sh"
1012

1113
VERSION="${1:-}"
1214
ARCH="${2:-amd64}"

packaging/fpm/test.sh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
set -euo pipefail
44

5-
SCRIPT_DIR="$( cd "$( dirname ${BASH_SOURCE[0]} )" && pwd )"
6-
. $SCRIPT_DIR/common.sh
5+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
6+
7+
# shellcheck disable=SC1091 # Including common.sh
8+
. "$SCRIPT_DIR/common.sh"
79

810
PKG_TYPE="${1:-rpm}"
911
ARCH="${2:-amd64}"
@@ -27,7 +29,7 @@ PKG_PATH="${REPO_DIR}/instrumentation/dist/${PKG_NAME}*${ARCH}.${PKG_TYPE}"
2729

2830
# install
2931
echo "Installing $PKG_PATH"
30-
$INSTALL_CMD $PKG_PATH
32+
$INSTALL_CMD "$PKG_PATH"
3133
if [ ! -f /etc/ld.so.preload ]; then
3234
echo "/etc/ld.so.preload not found" >&2
3335
exit 1
@@ -41,7 +43,7 @@ ldd "$LIBOTELINJECT_INSTALL_PATH"
4143

4244
# upgrade
4345
echo "Upgrading $PKG_PATH"
44-
$UPGRADE_CMD $PKG_PATH
46+
$UPGRADE_CMD "$PKG_PATH"
4547
if [ ! -f /etc/ld.so.preload ]; then
4648
echo "/etc/ld.so.preload not found" >&2
4749
exit 1
@@ -64,7 +66,7 @@ fi
6466
# install with pre-existing /etc/ld.so.preload
6567
touch /etc/ld.so.preload
6668
echo "Installing $PKG_PATH"
67-
$INSTALL_CMD $PKG_PATH
69+
$INSTALL_CMD "$PKG_PATH"
6870
if [ ! -f /etc/ld.so.preload ]; then
6971
echo "/etc/ld.so.preload not found" >&2
7072
exit 1

packaging/tests/deb/dotnet/run.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ else
1212
exit 1
1313
fi
1414

15-
SCRIPT_DIR="$( cd "$( dirname ${BASH_SOURCE[0]} )" && pwd )"
16-
cd $SCRIPT_DIR/../../../..
15+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
16+
cd "$SCRIPT_DIR/../../../.."
1717

1818
docker build \
1919
--platform "$docker_platform" \

packaging/tests/deb/java/run.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ else
1212
exit 1
1313
fi
1414

15-
SCRIPT_DIR="$( cd "$( dirname ${BASH_SOURCE[0]} )" && pwd )"
16-
cd $SCRIPT_DIR/../../../..
15+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
16+
cd "$SCRIPT_DIR/../../../.."
1717

1818
tomcat_download_url=$(packaging/tests/shared/determine-tomcat-download-url.sh)
1919
if [[ ! "$tomcat_download_url" =~ dlcdn.apache.org ]]; then

packaging/tests/deb/nodejs/run.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ else
1212
exit 1
1313
fi
1414

15-
SCRIPT_DIR="$( cd "$( dirname ${BASH_SOURCE[0]} )" && pwd )"
16-
cd $SCRIPT_DIR/../../../..
15+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
16+
cd "$SCRIPT_DIR/../../../.."
1717

1818
docker build \
1919
--platform "$docker_platform" \

0 commit comments

Comments
 (0)