Serenity Operating System
at master 51 lines 1.5 kB view raw
1#!/usr/bin/env bash 2 3set -eo pipefail 4 5script_path=$(cd -P -- "$(dirname -- "$0")" && pwd -P) 6cd "$script_path/.." 7 8if [ "$#" -eq "0" ]; then 9 mapfile -t files < <( 10 git ls-files -- \ 11 '*.sh' \ 12 ':!:Ports' \ 13 ':!:Userland/Shell/Tests' \ 14 ':!:Base/home/anon/Tests' \ 15 ':!:Base/root/generate_manpages.sh' \ 16 ':!:Base/usr/share/shell' \ 17 ':!:Base/etc/shellrc' \ 18 ) 19else 20 files=() 21 for file in "$@"; do 22 # Skip ports, like we in the CI case above. 23 if [[ "${file}" =~ "Ports" ]]; then 24 continue 25 fi 26 27 if [[ "${file}" == *".sh" && "${file}" != "Base/root/generate_manpages.sh" ]]; then 28 files+=("${file}") 29 fi 30 done 31fi 32 33if (( ${#files[@]} )); then 34 if ! command -v shellcheck &>/dev/null ; then 35 echo "shellcheck is not available, but shell files need linting! Either skip this script, or install shellcheck." 36 exit 1 37 fi 38 39 shellcheck --source-path=SCRIPTDIR "${files[@]}" 40 41 for file in "${files[@]}"; do 42 if (< "$file" grep -qE "grep [^|);]*-[^- ]*P"); then 43 # '\x2D' is the unicode escape sequence for '-'. This is used so 44 # that this script does not flag itself for containing grep dash P. 45 echo -e "The script '$file' contains 'grep \x2DP', which is not supported on macOS. Please use grep -E instead." 46 exit 1 47 fi 48 done 49else 50 echo "No .sh files to check." 51fi