script: Add script to run shellcheck on shell scripts
authorAndreas Schneider <asn@samba.org>
Mon, 21 Feb 2022 10:25:37 +0000 (11:25 +0100)
committerPavel Filipensky <pfilipensky@samba.org>
Wed, 17 Aug 2022 10:08:35 +0000 (10:08 +0000)
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Pavel Filipenský <pfilipensky@samba.org>
script/check-shell-scripts.sh [new file with mode: 0755]

diff --git a/script/check-shell-scripts.sh b/script/check-shell-scripts.sh
new file mode 100755 (executable)
index 0000000..f4f48a3
--- /dev/null
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+if [ $# -lt 1 ]; then
+       echo "Usage: $(basename "${0}") DIR [SEVERITY]"
+       exit 1
+fi
+
+DIR="${1}"
+SEVERITY="${2:-error}"
+
+shfmt -f "${DIR}" |
+       grep -v -E "(bootstrap|third_party)" |
+       xargs shellcheck \
+               --shell=sh \
+               --external-sources \
+               --check-sourced \
+               --format=gcc \
+               --severity="${SEVERITY}"
+
+exit $?