2019-05-10 15:24:06 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -eu -o pipefail
|
|
|
|
|
|
|
|
script_dir="$( cd "$( dirname "${0}" )" && pwd -P)"
|
|
|
|
|
|
|
|
if command -v shellcheck
|
|
|
|
then
|
2024-10-08 09:58:05 +00:00
|
|
|
exit_code=0
|
2019-05-10 15:24:06 +00:00
|
|
|
# The list of shell script come from the (grep ...) command, feeding the loop
|
|
|
|
while IFS= read -r script_to_check
|
|
|
|
do
|
|
|
|
# The shellcheck command are run in background, to have an overview of the linter (instead of a fail at first issue)
|
|
|
|
shellcheck "${script_to_check}" &
|
|
|
|
done < <( # Search all the repository for sh and bash shebangs, excluding .js and .md files
|
2021-10-27 08:34:05 +00:00
|
|
|
# the folders ".git", "vendor" and "node_modules" are also ignored
|
2019-05-10 15:24:06 +00:00
|
|
|
grep -rI '#!/' "${script_dir}"/.. \
|
|
|
|
| grep 'sh' | grep -v '.js' | grep -v '.md' \
|
2021-10-27 08:34:05 +00:00
|
|
|
| grep -v '.git/' | grep -v 'vendor/' | grep -v 'node_modules/' \
|
2019-05-10 15:24:06 +00:00
|
|
|
| cut -d':' -f1
|
|
|
|
)
|
2024-10-08 09:58:05 +00:00
|
|
|
# Wait for all background command to be completed
|
|
|
|
for p in $(jobs -p)
|
|
|
|
do
|
|
|
|
wait "$p" || exit_code=$?
|
|
|
|
done
|
|
|
|
exit $exit_code
|
2019-05-10 15:24:06 +00:00
|
|
|
else
|
|
|
|
echo "== Command shellcheck not found in your PATH. No shell script checked."
|
2024-10-08 09:58:05 +00:00
|
|
|
exit 1
|
2019-05-10 15:24:06 +00:00
|
|
|
fi
|