betazold
Vi Veri Veniversum Vivus Vici
  1. #!/bin/bash
  2. cd /home/user/proj
  3. FILES=()
  4. function testF
  5. {
  6. FILE=$1
  7. LEN=`wc -l $FILE | awk '{print $1}'`
  8. count=1;
  9. CHOMP=false
  10. if [ -s "$FILE" ] && [ "$(tail -c1 "$FILE"; echo x)" != $'\nx' ]; then
  11. LEN=($LEN+1)
  12. CHOMP=true
  13. fi
  14. while [[ $count -le $LEN ]]
  15. do
  16. LINE=`head -$count $FILE | tail -1`
  17. echo "$LINE" > /tmp/converter.txt
  18. isUTF=`file /tmp/converter.txt | grep UTF | wc -l`;
  19. if [ $isUTF != "1" ]; then
  20. iconv -f cp1251 -t utf8 /tmp/converter.txt -o /tmp/converter_1251.txt;
  21. mv /tmp/converter_1251.txt /tmp/converter.txt
  22. fi;
  23. cat /tmp/converter.txt >> "${file}.utf8"
  24. ((count++))
  25. done
  26. if [ $CHOMP == true ]; then
  27. perl -pe 'chomp if eof' "${file}.utf8" > "${file}.utf8.chomped"
  28. mv "${file}.utf8.chomped" "${file}.utf8"
  29. fi
  30. }
  31. git reset .
  32. git co .
  33. git clean -df
  34. git co .
  35. git merge --abort
  36. echo "NOW PULL"
  37. git stash
  38. git pull -Xtheirs origin master
  39. for i in `git status | grep "new file" | awk '{print $3}' | egrep "\.(php|js|htm|html|yml|xml|tpl)"`
  40. do
  41. FILES=("${FILES[@]}" "$i");
  42. done
  43. for i in `git status | grep "modified" | awk '{print $2}' | egrep "\.(php|js|htm|html|yml|xml|tpl)"`
  44. do
  45. FILES=("${FILES[@]}" "$i");
  46. done
  47. git stash pop
  48. echo "NOW CONVERT"
  49. for file in "${FILES[@]}"
  50. do
  51. DONE=false
  52. if [ -f "${file}" ]; then
  53. echo "FILE $file"
  54. testF "$file"
  55. echo "RENAME ${file}.utf8"
  56. mv "${file}.utf8" "$file"
  57. fi
  58. done

@темы: Bash