check_php.sh 864 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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. fi
  12. echo "Checking PHP files..."
  13. for file in $(find $current -type f -name "*.php" -not -path "${current}fm/*"); do
  14. RESULTS=$(php -l -n $file)
  15. if [ "$RESULTS" != "No syntax errors detected in $file" ]; then
  16. echo $RESULTS
  17. error=true
  18. fi
  19. done
  20. echo "Checking HTML/PHP combined files..."
  21. for file in $(find $current -type f -name "*.html" -not -path "${current}fm/*"); do
  22. RESULTS=$(php -l -n $file)
  23. if [ "$RESULTS" != "No syntax errors detected in $file" ]; then
  24. echo $RESULTS
  25. error=true
  26. fi
  27. done
  28. if [ "$error" = true ]; then
  29. exit 1
  30. else
  31. exit 0
  32. fi