Guest User

Untitled

a guest
Feb 14th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. FILES=$(find . -type f ! -path '*/vendor/*' ! -path '*.git*' )
  4.  
  5. for f in $FILES
  6. do
  7. F_CHARSET=$(file -bi $f | sed -e "s/.*[ ]charset=//")
  8.  
  9. if [ "$F_CHARSET" != "utf-8" ] || [ "$F_CHARSET" != "binary" ] || [ "$F_CHARSET" != "unknown-8bit" ]; then
  10. iconv -f "$F_CHARSET" -t utf-8 "$f" -o "$f.new"
  11.  
  12. CURRENT_FILE_SIZE=$(stat -c%s "$f")
  13. CURRENT_TMP_SIZE=$(stat -c%s "$f.new")
  14.  
  15. if [ "$CURRENT_TMP_SIZE" -ge "$CURRENT_FILE_SIZE" ]; then
  16. mv -f "$f.new" "$f"
  17. echo "success \t" "$f"
  18. fi
  19.  
  20. if [ "$CURRENT_TMP_SIZE" -lt "$CURRENT_FILE_SIZE" ]; then
  21. rm -f "$f.new"
  22. echo "error \t" "$f"
  23. fi
  24.  
  25. fi
  26. done
Add Comment
Please, Sign In to add comment