fixutf8bomfiles.sh 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/bin/sh
  2. #
  3. # Checks of fix files contains UTF-8 BOM in dolibarr source tree,
  4. # excluding git repository, custom modules and included libraries.
  5. #
  6. # Raphaël Doursenaud - rdoursenaud@gpcsolutions.fr
  7. # Laurent Destailleur eldy@users.sourceforge.net
  8. #------------------------------------------------------
  9. # Usage: fixutf8bomfiles.sh [list|fix]
  10. #------------------------------------------------------
  11. # Syntax
  12. if [ "x$1" != "xlist" -a "x$1" != "xfix" ]
  13. then
  14. echo "Detect and fix bad UTF8 encoded files (UTF8 must not use BOM char)"
  15. echo "Usage: fixutf8bomfiles.sh (list|fix) [addincludes]"
  16. fi
  17. if [ "x$2" != "xaddincludes" ]
  18. then
  19. export moreoptions="--exclude-dir='includes'"
  20. fi
  21. # To detec
  22. if [ "x$1" = "xlist" ]
  23. then
  24. #find . \( -iname '*.php' -print0 -o -iname '*.sh' -print0 -o -iname '*.pl' -print0 -o -iname '*.lang' -print0 -o -iname '*.txt' \) -print0 | xargs -0 awk '/^\xEF\xBB\xBF/ {print FILENAME} {nextfile}'
  25. echo "grep -rlIZ --include='*.php' --include='*.sh' --include='*.pl' --include='*.lang' --include='*.txt' --exclude-dir='.git' --exclude-dir='.tx' $moreoptions --exclude-dir='custom' . . | xargs -0 awk '/^\xEF\xBB\xBF/ {print FILENAME} {nextfile}'"
  26. grep -rlIZ --include='*.php' --include='*.sh' --include='*.pl' --include='*.lang' --include='*.txt' --exclude-dir='.git' --exclude-dir='.tx' $moreoptions --exclude-dir='custom' . . | xargs -0 awk '/^\xEF\xBB\xBF/ {print FILENAME} {nextfile}'
  27. fi
  28. # To convert
  29. if [ "x$1" = "xfix" ]
  30. then
  31. for fic in `grep -rlIZ --include='*.php' --include='*.sh' --include='*.pl' --include='*.lang' --include='*.txt' --exclude-dir='.git' --exclude-dir='.tx' $moreoptions --exclude-dir='custom' . . | xargs -0 awk '/^\xEF\xBB\xBF/ {print FILENAME} {nextfile}'`
  32. do
  33. echo "Fixing $fic"
  34. sed -i '1s/^\xEF\xBB\xBF//' $fic
  35. done;
  36. fi