2021-01-22 19:44:05 +03:00
|
|
|
#!/usr/bin/env bash
|
2020-12-27 17:26:43 +03:00
|
|
|
|
|
|
|
set -eo pipefail
|
2020-02-10 09:39:30 +03:00
|
|
|
|
|
|
|
script_path=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
|
|
|
|
cd "$script_path/.."
|
|
|
|
|
2020-12-27 17:34:06 +03:00
|
|
|
if [ "$#" -eq "0" ]; then
|
|
|
|
mapfile -t files < <(
|
|
|
|
git ls-files -- \
|
|
|
|
'*.sh' \
|
|
|
|
':!:Ports' \
|
2021-02-04 05:04:22 +03:00
|
|
|
':!:Userland/Shell/Tests' \
|
2022-03-20 21:55:50 +03:00
|
|
|
':!:Base/home/anon/Tests' \
|
2022-04-12 02:00:02 +03:00
|
|
|
':!:Base/root/generate_manpages.sh' \
|
|
|
|
':!:Base/usr/share/shell' \
|
|
|
|
':!:Base/etc/shellrc' \
|
2020-12-27 17:34:06 +03:00
|
|
|
)
|
|
|
|
else
|
|
|
|
files=()
|
|
|
|
for file in "$@"; do
|
2022-01-17 11:06:56 +03:00
|
|
|
# Skip ports, like we in the CI case above.
|
|
|
|
if [[ "${file}" =~ "Ports" ]]; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2021-10-24 00:47:08 +03:00
|
|
|
if [[ "${file}" == *".sh" && "${file}" != "Base/root/generate_manpages.sh" ]]; then
|
2020-12-27 17:34:06 +03:00
|
|
|
files+=("${file}")
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
2020-02-10 09:39:30 +03:00
|
|
|
|
2020-12-27 17:34:06 +03:00
|
|
|
if (( ${#files[@]} )); then
|
2021-01-10 10:20:21 +03:00
|
|
|
if ! command -v shellcheck &>/dev/null ; then
|
|
|
|
echo "shellcheck is not available, but shell files need linting! Either skip this script, or install shellcheck."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2022-10-16 23:23:44 +03:00
|
|
|
shellcheck --source-path=SCRIPTDIR "${files[@]}"
|
2021-10-29 11:27:29 +03:00
|
|
|
|
|
|
|
for file in "${files[@]}"; do
|
|
|
|
if (< "$file" grep -qE "grep [^|);]*-[^- ]*P"); then
|
|
|
|
# '\x2D' is the unicode escape sequence for '-'. This is used so
|
|
|
|
# that this script does not flag itself for containing grep dash P.
|
|
|
|
echo -e "The script '$file' contains 'grep \x2DP', which is not supported on macOS. Please use grep -E instead."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
done
|
2020-12-27 17:34:06 +03:00
|
|
|
else
|
|
|
|
echo "No .sh files to check."
|
2020-02-10 09:39:30 +03:00
|
|
|
fi
|