check_php.sh 880 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/bin/bash
  2. # Original code: @jroman00 (https://gist.github.com/mathiasverraes/3096500#gistcomment-1575416)
  3. error=false
  4. current=$1
  5. if [ -z "$current" ]; then
  6. current="/usr/local/hestia/web/"
  7. fi
  8. if [ ! -d $current ] && [ ! -f $current ] ; then
  9. echo "Invalid directory or file: $current"
  10. error=true
  11. continue
  12. fi
  13. echo "Checking PHP files..."
  14. for file in `find $current -type f -name "*.php"` ; do
  15. RESULTS=`php -l -n $file`
  16. if [ "$RESULTS" != "No syntax errors detected in $file" ] ; then
  17. echo $RESULTS
  18. error=true
  19. fi
  20. done
  21. echo "Checking HTML/PHP combined files..."
  22. for file in `find $current -type f -name "*.html"` ; do
  23. RESULTS=`php -l -n $file`
  24. if [ "$RESULTS" != "No syntax errors detected in $file" ] ; then
  25. echo $RESULTS
  26. error=true
  27. fi
  28. done
  29. if [ "$error" = true ] ; then
  30. exit 1
  31. else
  32. exit 0
  33. fi