Skip to content

Commit aa86704

Browse files
authored
Merge pull request #1879 from larsewi/linting
ENT-12601: Added workflow to lint shell scripts
2 parents 2d1d5cf + 7383aa8 commit aa86704

25 files changed

+362
-236
lines changed

.github/workflows/shellcheck.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: shellcheck
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
branches: [master]
8+
9+
jobs:
10+
check:
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: read
14+
15+
steps:
16+
- uses: actions/checkout@v4
17+
- name: Install dependencies
18+
run: sudo apt install shellcheck
19+
- name: Lint sources with shellcheck
20+
run: |
21+
# Recursively find all shell scripts in the build-scripts directory with a shebang
22+
grep -Erl '^(#!/(bin|usr/bin)/(env )?(sh|bash))' build-scripts/ | while read -r file; do
23+
shellcheck --external-sources --source-path=build-scripts "$file"
24+
done

build-scripts/bootstrap-tarballs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,7 @@ run_and_print_on_failure ./configure
112112
echo "$(basename "$0"): Debug: Running make dist on masterfiles repository..."
113113
run_and_print_on_failure make dist # source tarball
114114
echo "$(basename "$0"): Debug: Running make tar-package on masterfiles repository..."
115-
run_and_print_on_failure make tar-package # package tarball (containing all
116-
# files as if they were installed
117-
# under "prefix".)
115+
run_and_print_on_failure make tar-package # package tarball (containing all files as if they were installed under "prefix".)
118116
mv cfengine-masterfiles*.tar.gz "$BASEDIR"/output/tarballs/
119117
echo "$(basename "$0"): Debug: Running make distclean on masterfiles repository..."
120118
run_and_print_on_failure make distclean

build-scripts/build-environment-check

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh
22

3-
. $(dirname "$0")/functions
3+
. "$(dirname "$0")"/functions
44
. detect-environment
55
. compile-options
66

@@ -45,17 +45,17 @@ DEP_LIST="$DEP_LIST rsync gcc make sudo wget"
4545

4646
RET=0
4747
for unwanted in $UNWANTED_DEPS; do
48-
if query_pkg $unwanted; then
49-
echo "ERROR Found unwanted package:" $unwanted
48+
if query_pkg "$unwanted"; then
49+
echo "ERROR Found unwanted package: $unwanted"
5050
RET=1
5151
fi
5252
done
5353

5454
for dep in $DEP_LIST; do
55-
if query_pkg $dep; then
55+
if query_pkg "$dep"; then
5656
true
5757
else
58-
echo "ERROR Missing system package:" $dep
58+
echo "ERROR Missing system package: $dep"
5959
RET=1
6060
fi
6161
done

build-scripts/clean-results

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh -ex
22

3-
. $(dirname "$0")/functions
3+
. "$(dirname "$0")"/functions
44
. version
55

66
# This script is designed to clean up old directories, specifically keeping the

build-scripts/compile

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,24 @@ nova)
3434
esac
3535

3636
echo "$(basename "$0"): Debug: Running make in core repo..."
37-
run_and_print_on_failure $MAKE -C "$BASEDIR"/core -k
37+
run_and_print_on_failure "$MAKE" -C "$BASEDIR"/core -k
3838
echo "$(basename "$0"): Debug: Running make install in core repo..."
39-
run_and_print_on_failure $MAKE -C "$BASEDIR"/core install DESTDIR="$BASEDIR"/cfengine/dist
39+
run_and_print_on_failure "$MAKE" -C "$BASEDIR"/core install DESTDIR="$BASEDIR"/cfengine/dist
4040

4141
if [ "$NOVA" = yes ]; then
4242
echo "$(basename "$0"): Debug: Running make in enterprise repo..."
43-
run_and_print_on_failure $MAKE -C "$BASEDIR"/enterprise -k
43+
run_and_print_on_failure "$MAKE" -C "$BASEDIR"/enterprise -k
4444
echo "$(basename "$0"): Debug: Running make install in enterprise repo..."
45-
run_and_print_on_failure $MAKE -C "$BASEDIR"/enterprise install DESTDIR="$BASEDIR"/cfengine/dist
45+
run_and_print_on_failure "$MAKE" -C "$BASEDIR"/enterprise install DESTDIR="$BASEDIR"/cfengine/dist
4646
if [ "$ROLE" = hub ]; then
4747
echo "$(basename "$0"): Debug: Running make in nova repo..."
48-
run_and_print_on_failure $MAKE -C "$BASEDIR"/nova -k
48+
run_and_print_on_failure "$MAKE" -C "$BASEDIR"/nova -k
4949
echo "$(basename "$0"): Debug: Running make install in nova repo..."
50-
run_and_print_on_failure $MAKE -C "$BASEDIR"/nova install DESTDIR="$BASEDIR"/cfengine/dist
50+
run_and_print_on_failure "$MAKE" -C "$BASEDIR"/nova install DESTDIR="$BASEDIR"/cfengine/dist
5151
echo "$(basename "$0"): Debug: Running make install in masterfiles repo..."
52-
run_and_print_on_failure $MAKE -C "$BASEDIR"/masterfiles install DESTDIR="$BASEDIR"/cfengine/dist
52+
run_and_print_on_failure "$MAKE" -C "$BASEDIR"/masterfiles install DESTDIR="$BASEDIR"/cfengine/dist
5353
fi
5454
else
5555
echo "$(basename "$0"): Debug: Running make install in masterfiles repo..."
56-
run_and_print_on_failure $MAKE -C "$BASEDIR"/masterfiles install DESTDIR="$BASEDIR"/cfengine/dist
56+
run_and_print_on_failure "$MAKE" -C "$BASEDIR"/masterfiles install DESTDIR="$BASEDIR"/cfengine/dist
5757
fi

build-scripts/compile-options

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

66
# Autodect PROJECT if not set
77

8-
if [ x"$PROJECT" = x ]; then
9-
case x"$JOB_NAME" in
8+
if [ -z "$PROJECT" ]; then
9+
case "$JOB_NAME" in
1010
*-community-*) PROJECT=community ;;
1111
*-enterprise-*) PROJECT=nova ;;
1212
*-hub-*) PROJECT=nova ;;
@@ -17,8 +17,8 @@ fi
1717
# If still not set, then either we are running outside Jenkins, or this
1818
# is not a main "build" type job (it could be the bootstrap job).
1919
# Do directory-based auto-detection.
20-
if [ x"$PROJECT" = x ]; then
21-
if [ -d $BASEDIR/nova ]; then
20+
if [ -z "$PROJECT" ]; then
21+
if [ -d "$BASEDIR"/nova ]; then
2222
PROJECT=nova
2323
else
2424
PROJECT=community
@@ -31,7 +31,7 @@ export PROJECT
3131
# When running manually, you can just export this variable.
3232
# It's a flag: if it's set to 1 - then we use system OpenSSL.
3333
# Otherwise, we build it.
34-
if [ x"$SYSTEM_SSL" = x ]; then
34+
if [ -z "$SYSTEM_SSL" ]; then
3535
# We don't bundle OpenSSL on some redhat-derived systems due to incompatability with libpam and our openssl.
3636
_OS_MAJOR_VERSION="$(echo "$OS_VERSION" | cut -d. -f1)"
3737
if [ "$OS" = "rhel" ] && expr "$_OS_MAJOR_VERSION" ">=" "8" >/dev/null; then
@@ -43,6 +43,9 @@ if [ x"$SYSTEM_SSL" = x ]; then
4343
fi
4444
fi
4545
# Detect using system ssl when running a Jenkins job
46+
# shellcheck disable=SC2154
47+
# > label is referenced but not assigned.
48+
# This file is sourced by other scripts. label is assigned elsewhere.
4649
if expr x"$label" ":" ".*systemssl" >/dev/null; then
4750
SYSTEM_SSL=1
4851
fi
@@ -82,7 +85,7 @@ solaris)
8285
esac
8386

8487
# When we don't bundle OpenSSL, then we need to pull it from /usr/lib64.
85-
if [ x"$SYSTEM_SSL" = x1 ]; then
88+
if [ "$SYSTEM_SSL" = 1 ]; then
8689
LDFLAGS="$LDFLAGS -L/usr/lib64"
8790
fi
8891
export LDFLAGS
@@ -96,8 +99,11 @@ EMBEDDED_DB="lmdb"
9699

97100
############### Fill in build dependencies in DEPS variable ################
98101

102+
# shellcheck disable=SC2034
103+
# > DEPS appears unused. Verify use (or export if used externally).
104+
# This file is sourced by other scripts that uses it
99105
DEPS=
100-
[ $OS_FAMILY = mingw ] && var_append DEPS "pthreads-w32 libgnurx"
106+
[ "$OS_FAMILY" = mingw ] && var_append DEPS "pthreads-w32 libgnurx"
101107

102108
# libgcc_s.so is needed before we compile any other dependency
103109
# on some platforms!
@@ -107,7 +113,7 @@ esac
107113

108114
var_append DEPS "$EMBEDDED_DB pcre2"
109115

110-
if ! [ x"$SYSTEM_SSL" = x1 ]; then
116+
if [ "$SYSTEM_SSL" != 1 ]; then
111117
# FIXME: Why do we need zlib?
112118
# ANSWER: Openssl uses it optionally, TODO DISABLE
113119
var_append DEPS "zlib openssl"
@@ -156,7 +162,7 @@ agent) ROLE=agent ;;
156162
hub) ROLE=hub ;;
157163
*)
158164
# Not running under Jenkins?
159-
if [ x"$JENKINS_SERVER_COOKIE" = x ]; then
165+
if [ -z "$JENKINS_SERVER_COOKIE" ]; then
160166
case "$PROJECT-$ARCH-$OS-${OS_VERSION}" in
161167
community-*) ROLE=agent ;;
162168
# We do not support 32 bits hubs anymore
@@ -220,7 +226,12 @@ esac
220226
# unit files for it?
221227
case "$OS_FAMILY" in
222228
linux) WITH_SYSTEMD=yes ;;
223-
*) WITH_SYSTEMD=no ;;
229+
*)
230+
# shellcheck disable=SC2034
231+
# > DEPS appears unused. Verify use (or export if used externally).
232+
# This file is sourced by other scripts that uses it.
233+
WITH_SYSTEMD=no
234+
;;
224235
esac
225236

226237
case "$OS_FAMILY" in

build-scripts/detect-environment

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ fi
1717
# compilation targets. However, if CROSS_TARGET is already set in the
1818
# environment it will take precedence.
1919
detect_cross_target() {
20+
# shellcheck disable=SC2154
21+
# > label is referenced but not assigned.
22+
# This file is sourced by other scripts. label is assigned elsewhere.
2023
case "$label" in
2124
*_x86_64_mingw*)
2225
CROSS_TARGET=${CROSS_TARGET:-x64-mingw}

0 commit comments

Comments
 (0)