.linter_shell.sh 736 Bytes
Newer Older
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
#!/bin/bash
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color

sh_files=$(find . -name "*.sh")
exe_files=$(grep -Erl "#\\!/bin/(bash|sh)" --exclude=*.* package)
files="$sh_files\\n$exe_files"
#find no files
if [[ "$files" == "\\n" ]];then
  echo -e "${YELLOW}No shell files found!${NC}"
  exit 0
fi

# Download the lastest stable version of shellcheck 
apt install wget
wget https://storage.googleapis.com/shellcheck/shellcheck-stable.linux.x86_64.tar.xz
tar xf shellcheck-stable.linux.x86_64.tar.xz

if echo -e "$files"| xargs ./shellcheck-stable/shellcheck -s bash
then
  echo "AWESOME!No problems found."
  exit 0
else
  echo -e "Understand errors in: ${BLUE}https://github.com/koalaman/shellcheck/wiki${NC}"
  exit 1
fi