#!/bin/bash
cd /home/user/proj
FILES=()
function testF
{
FILE=$1
LEN=`wc -l $FILE | awk '{print $1}'`
count=1;
CHOMP=false
if [ -s "$FILE" ] && [ "$(tail -c1 "$FILE"; echo x)" != $'\nx' ]; then
LEN=($LEN+1)
CHOMP=true
fi
while [[ $count -le $LEN ]]
do
LINE=`head -$count $FILE | tail -1`
echo "$LINE" > /tmp/converter.txt
isUTF=`file /tmp/converter.txt | grep UTF | wc -l`;
if [ $isUTF != "1" ]; then
iconv -f cp1251 -t utf8 /tmp/converter.txt -o /tmp/converter_1251.txt;
mv /tmp/converter_1251.txt /tmp/converter.txt
fi;
cat /tmp/converter.txt >> "${file}.utf8"
((count++))
done
if [ $CHOMP == true ]; then
perl -pe 'chomp if eof' "${file}.utf8" > "${file}.utf8.chomped"
mv "${file}.utf8.chomped" "${file}.utf8"
fi
}
git reset .
git co .
git clean -df
git co .
git merge --abort
echo "NOW PULL"
git stash
git pull -Xtheirs origin master
for i in `git status | grep "new file" | awk '{print $3}' | egrep "\.(php|js|htm|html|yml|xml|tpl)"`
do
FILES=("${FILES[@]}" "$i");
done
for i in `git status | grep "modified" | awk '{print $2}' | egrep "\.(php|js|htm|html|yml|xml|tpl)"`
do
FILES=("${FILES[@]}" "$i");
done
git stash pop
echo "NOW CONVERT"
for file in "${FILES[@]}"
do
DONE=false
if [ -f "${file}" ]; then
echo "FILE $file"
testF "$file"
echo "RENAME ${file}.utf8"
mv "${file}.utf8" "$file"
fi
done