forked from sclorg/ci-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-shellcheck.sh
More file actions
executable file
·44 lines (35 loc) · 867 Bytes
/
run-shellcheck.sh
File metadata and controls
executable file
·44 lines (35 loc) · 867 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/bash
VERBOSE_OUTPUT=0
usage() {
echo "Usage: $(basename "$0") [ -v|--verbose ] <dir|file> [ <dir|file> ... ]"
}
verbose() {
if [ "${VERBOSE_OUTPUT}" -eq 1 ] ; then
echo "$@" >&2
fi
}
if [ $# -eq 0 ] ; then
echo "ERROR: No arguments given."
usage
exit 1
fi
case $1 in
-v|--verbose) VERBOSE_OUTPUT=1; shift ;;
esac
filter_files() {
while read -r file ; do
if [ -L "$file" ] ; then
verbose "Ignoring symlink $file."
continue
fi
verbose "Will scan $file"
echo "$file"
done
}
detect_shell_files() {
find -H "$@" -type f -not -path '*/\.git/*' -exec grep -l '^#!/bin/\(bash\|sh\)' {} +
find -H "$@" -name '*.sh' -not -path '*/\.git/*'
}
# Run shellcheck on all files (we should also ignore symlinks)
detect_shell_files "$@" | filter_files | sort -u | xargs shellcheck
# vim: set tabstop=2:shiftwidth=2:expandtab: