-
Notifications
You must be signed in to change notification settings - Fork 11
/
initNewVersion.sh
executable file
·168 lines (137 loc) · 5.81 KB
/
initNewVersion.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/bin/bash
export masterLProj="English.lproj"
export IBTOOL=/Applications/Xcode.app/Contents/Developer/usr/bin/ibtool
if [ $# != 2 ] ; then
echo "Usage: ./initNewVersion.sh old_versino_number new_version_number"
else
export oldVer=$1
export newVer=$2
if [ -d $oldVer ] ; then
# oldVe必须存在
if [ -d ../MPlayerX/$masterLProj ] ; then
# ../MPlayerX/$masterLProj 也必须存在
if [ -d $newVer ] ; then
echo "$newVer already exists"
export oldVer=$2
export newVer="../MPlayerX/$masterLProj"
echo "Updating from $oldVer -> $newVer"
find $newVer -not -name *.lproj | while read filePath
do
# 遍历MPlayerX里面所有的文件
fileName=`basename $filePath`
ext=${fileName##*.}
fileNameNoExt=${fileName%.*}
if [ -f $oldVer/$masterLProj/$fileName ] ; then
# 如果对应的旧文件夹里面有同样的文件的话
# 两个文件比较
diffRes=`diff $filePath ./$oldVer/$masterLProj/$fileName | wc -l`
if [ $diffRes == 0 ] ; then
# 两个文件相同的话,什么也不做
echo "Same File: $filePath and $oldVer/$masterLProj/$fileName"
else
# 两个文件不同的话,根据文件的不同更新
echo "DIFF File: $filePath and $oldVer/$masterLProj/$fileName"
if [ $ext == "xib" ] ; then
# 如果是xib文件,那么需要特殊的命令
find $oldVer -name *.lproj -and -not -name $masterLProj | while read folderPath
do
# 寻找旧文件夹里面所有的【翻译版本】
echo "update: $folderPath/$fileNameNoExt.$ext"
${IBTOOL} --previous-file ./$oldVer/$masterLProj/$fileName --incremental-file ./$folderPath/$fileName --localize-incremental --write ./$folderPath/$fileNameNoExt.$ext $filePath
done
elif [ $ext == "strings" ]; then
find $oldVer -name *.lproj -and -not -name $masterLProj | while read folderPath
do
./mergeStrings -o ./$folderPath/$fileNameNoExt.$ext -n $filePath -O ./$folderPath/$fileNameNoExt.$ext
done
else
# 如果是普通文件的话,直接拷贝
find $oldVer -name *.lproj -and -not -name $masterLProj | while read folderPath
do
# 寻找旧文件夹里面所有的【翻译版本】
echo "copy : $folderPath/$fileNameNoExt.updated.$ext"
cp -R $filePath ./$folderPath/$fileNameNoExt.updated.$ext
done
fi
# 然后将【Master版本】拷贝
echo "copy : $oldVer/$masterLProj/$fileName"
cp -R $filePath $oldVer/$masterLProj/$fileName
fi
else
# 如果旧文件夹里面没有该文件的话,说明是新文件,那么就更新
find $oldVer -name *.lproj -and -not -name $masterLProj | while read folderPath
do
echo "copy : $folderPath/$fileNameNoExt.newfish.$ext"
cp -R $filePath ./$folderPath/$fileNameNoExt.newfish.$ext
done
fi
done
else
# 如果目标新文件夹不存在的话,说明是全新的更新
echo "$oldVer -> $newVer, Start initialization..."
# 创建新文件夹
mkdir -p $newVer
# 将现在MPlayerX里面的文件夹全部拷贝
cp -R ../MPlayerX/$masterLProj $newVer/
# 拷贝 Makefile
cp template.Makefile $newVer/Makefile
find $oldVer -name *.lproj -and -not -name $masterLProj | while read folderPath
do
# 旧文件夹里面所有的【翻译版本】
echo $folderPath
# 【翻译版本】文件夹的名字
folderName=`basename $folderPath`
# 创建相应新版本的【翻译版本】文件夹
mkdir -p $newVer/$folderName
find $folderPath -not -name *.lproj | while read filePath
do
# 对于所有的文件
fileName=`basename $filePath`
ext=${fileName##*.}
fileNameNoExt=${fileName%.*}
if [ $ext == "xib" ] ; then
if [ -f ./$oldVer/$masterLProj/$fileName ] && [ -f ./$filePath ] && [ -f ./$newVer/$masterLProj/$fileName ] ; then
# 对于xib文件,命令不一样
echo "update ./$newVer/$folderName/$fileName"
${IBTOOL} --previous-file ./$oldVer/$masterLProj/$fileName --incremental-file ./$filePath --localize-incremental --write ./$newVer/$folderName/$fileName ./$newVer/$masterLProj/$fileName
else
echo "necessary files are missing for xib transformation"
fi
else
# 如果是其他文件,既拷贝旧【翻译版本】,也拷贝新【Master版本】
echo "copy : ./$filePath -> $newVer/$folderName/$fileNameNoExt.prev.$ext"
cp ./$filePath ./$newVer/$folderName/$fileNameNoExt.prev.$ext
echo "copy : ./$newVer/$masterLProj/$fileName -> $newVer/$folderName/$fileNameNoExt.now.$ext"
cp ./$newVer/$masterLProj/$fileName ./$newVer/$folderName/$fileNameNoExt.now.$ext
if [[ $ext == "strings" ]]; then
./mergeStrings -o ./$filePath -n ./$newVer/$masterLProj/$fileName -O ./$newVer/$folderName/$fileNameNoExt.$ext
fi
fi
done
done
# check if there are new things
find $newVer/$masterLProj -not -name *.lproj | while read newFilePath
do
# 遍历新【Master版本】
newFileName=`basename $newFilePath`
ext=${newFileName##*.}
fileNameNoExt=${newFileName%.*}
if [ -e $oldVer/$masterLProj/$newFileName ] ; then
echo "$oldVer/$masterLProj/$newFileName already exist"
else
find $newVer -name *.lproj -and -not -name $masterLProj | while read folderPath
do
# 新出现的文件就拷贝
echo "copy : $folderPath/$fileNameNoExt.newfish.$ext"
cp -R ./$newFilePath ./$folderPath/$fileNameNoExt.newfish.$ext
done
fi
done
fi
else
echo "folder structure misses ../MPlayerX/"
fi
else
echo "$oldVer doesn’t exists"
fi
fi