fixdosfiles.sh 2.0 KB

1234567891011121314151617181920212223242526272829303132
  1. #!/bin/sh
  2. #------------------------------------------------------
  3. # Script to find files that are not Unix encoded
  4. #
  5. # Laurent Destailleur - eldy@users.sourceforge.net
  6. #------------------------------------------------------
  7. # Usage: fixdosfiles.sh [list|fix]
  8. #------------------------------------------------------
  9. # Syntax
  10. if [ "x$1" != "xlist" -a "x$1" != "xfix" ]
  11. then
  12. echo "This script detect or clean files with CR+LF into files with LF only. All source files are included, including files into includes."
  13. echo "Usage: fixdosfiles.sh [list|fix]"
  14. fi
  15. # To detec
  16. if [ "x$1" = "xlist" ]
  17. then
  18. find . \( -iname "functions" -o -iname "*.md" -o -iname "*.html" -o -iname "*.htm" -o -iname "*.php" -o -iname "*.sh" -o -iname "*.cml" -o -iname "*.css" -o -iname "*.js" -o -iname "*.lang" -o -iname "*.pl" -o -iname "*.sql" -o -iname "*.txt" -o -iname "*.xml" -o -iname "*.pml" \) -exec file "{}" + | grep -v 'custom\/' | grep -v 'documents\/website' | grep -v 'documents\/medias' | grep -v 'documents\/sellyoursaas' | grep CRLF
  19. # find . \( -iname "*.md" -o -iname "*.html" -o -iname "*.htm" -o -iname "*.php" -o -iname "*.sh" -o -iname "*.cml" -o -iname "*.css" -o -iname "*.js" -o -iname "*.lang" -o -iname "*.pl" -o -iname "*.sql" -o -iname "*.txt" -o -iname "*.xml" \) -exec file "{}" + | grep -v "CRLF" | grep -v 'custom\/' | grep -v 'documents\/website' | grep -v 'documents\/medias' | grep -v 'documents\/sellyoursaas' | grep -v 'htdocs\/includes' | grep CRLF
  20. fi
  21. # To convert
  22. if [ "x$1" = "xfix" ]
  23. then
  24. for fic in `find . \( -iname "functions" -o -iname "*.md" -o -iname "*.html" -o -iname "*.htm" -o -iname "*.php" -o -iname "*.sh" -o -iname "*.cml" -o -iname "*.css" -o -iname "*.js" -o -iname "*.lang" -o -iname "*.pl" -o -iname "*.sql" -o -iname "*.txt" -o -iname "*.xml" -o -iname "*.pml" \) -exec file "{}" + | grep -v 'custom\/' | grep -v 'documents\/website' | grep -v 'documents\/medias' | grep -v 'documents\/sellyoursaas' | grep CRLF | awk -F':' '{ print $1 }' `
  25. do
  26. echo "Fix file $fic"
  27. dos2unix "$fic"
  28. done;
  29. fi