forked from telegramdesktop/tdesktop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·425 lines (359 loc) · 14.6 KB
/
build.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
set -e
FullExecPath=$PWD
pushd `dirname $0` > /dev/null
FullScriptPath=`pwd`
popd > /dev/null
if [ ! -d "$FullScriptPath/../../../TelegramPrivate" ]; then
echo ""
echo "This script is for building the production version of Telegram Desktop."
echo ""
echo "For building custom versions please visit the build instructions page at:"
echo "https://github.com/telegramdesktop/tdesktop/#build-instructions"
exit
fi
Error () {
cd $FullExecPath
echo "$1"
exit 1
}
if [ ! -f "$FullScriptPath/target" ]; then
Error "Build target not found!"
fi
while IFS='' read -r line || [[ -n "$line" ]]; do
BuildTarget="$line"
done < "$FullScriptPath/target"
while IFS='' read -r line || [[ -n "$line" ]]; do
set $line
eval $1="$2"
done < "$FullScriptPath/version"
VersionForPacker="$AppVersion"
if [ "$AlphaVersion" != "0" ]; then
AppVersion="$AlphaVersion"
AppVersionStrFull="${AppVersionStr}_${AlphaVersion}"
AlphaBetaParam="-alpha $AlphaVersion"
AlphaKeyFile="talpha_${AppVersion}_key"
elif [ "$BetaChannel" == "0" ]; then
AppVersionStrFull="$AppVersionStr"
AlphaBetaParam=''
else
AppVersionStrFull="$AppVersionStr.beta"
AlphaBetaParam='-beta'
fi
echo ""
HomePath="$FullScriptPath/.."
if [ "$BuildTarget" == "linux" ]; then
echo "Building version $AppVersionStrFull for Linux 64bit.."
UpdateFile="tlinuxupd$AppVersion"
SetupFile="tsetup.$AppVersionStrFull.tar.xz"
ReleasePath="$HomePath/../out/Release"
BinaryName="Telegram"
elif [ "$BuildTarget" == "linux32" ]; then
echo "Building version $AppVersionStrFull for Linux 32bit.."
UpdateFile="tlinux32upd$AppVersion"
SetupFile="tsetup32.$AppVersionStrFull.tar.xz"
ReleasePath="$HomePath/../out/Release"
BinaryName="Telegram"
elif [ "$BuildTarget" == "mac" ]; then
echo "Building version $AppVersionStrFull for OS X 10.8+.."
UpdateFile="tmacupd$AppVersion"
SetupFile="tsetup.$AppVersionStrFull.dmg"
ReleasePath="$HomePath/../out/Release"
BinaryName="Telegram"
elif [ "$BuildTarget" == "mac32" ]; then
echo "Building version $AppVersionStrFull for OS X 10.6 and 10.7.."
UpdateFile="tmac32upd$AppVersion"
SetupFile="tsetup32.$AppVersionStrFull.dmg"
ReleasePath="$HomePath/../out/Release"
BinaryName="Telegram"
elif [ "$BuildTarget" == "macstore" ]; then
if [ "$AlphaVersion" != "0" ]; then
Error "Can't build macstore alpha version!"
fi
echo "Building version $AppVersionStrFull for Mac App Store.."
ReleasePath="$HomePath/../out/Release"
BinaryName="Telegram Desktop"
else
Error "Invalid target!"
fi
#if [ "$BuildTarget" == "linux" ] || [ "$BuildTarget" == "linux32" ] || [ "$BuildTarget" == "mac" ] || [ "$BuildTarget" == "mac32" ] || [ "$BuildTarget" == "macstore" ]; then
if [ "$AlphaVersion" != "0" ]; then
if [ -f "$ReleasePath/$AlphaKeyFile" ]; then
Error "Alpha version key file for version $AppVersion already exists!"
fi
if [ -d "$ReleasePath/deploy/$AppVersionStrMajor/$AppVersionStrFull" ]; then
Error "Deploy folder for version $AppVersionStrFull already exists!"
fi
else
if [ -d "$ReleasePath/deploy/$AppVersionStrMajor/$AppVersionStr.alpha" ]; then
Error "Deploy folder for version $AppVersionStr.alpha already exists!"
fi
if [ -d "$ReleasePath/deploy/$AppVersionStrMajor/$AppVersionStr.beta" ]; then
Error "Deploy folder for version $AppVersionStr.beta already exists!"
fi
if [ -d "$ReleasePath/deploy/$AppVersionStrMajor/$AppVersionStr" ]; then
Error "Deploy folder for version $AppVersionStr already exists!"
fi
if [ -f "$ReleasePath/$UpdateFile" ]; then
Error "Update file for version $AppVersion already exists!"
fi
fi
DeployPath="$ReleasePath/deploy/$AppVersionStrMajor/$AppVersionStrFull"
#fi
if [ "$BuildTarget" == "linux" ] || [ "$BuildTarget" == "linux32" ]; then
DropboxSymbolsPath="/media/psf/Dropbox/Telegram/symbols"
if [ ! -d "$DropboxSymbolsPath" ]; then
Error "Dropbox path not found!"
fi
BackupPath="/media/psf/backup/$AppVersionStrMajor/$AppVersionStrFull/t$BuildTarget"
if [ ! -d "/media/psf/backup" ]; then
Error "Backup folder not found!"
fi
gyp/refresh.sh
cd $ReleasePath
make -j4
echo "$BinaryName build complete!"
if [ ! -f "$ReleasePath/$BinaryName" ]; then
Error "$BinaryName not found!"
fi
BadCount=`objdump -T $ReleasePath/$BinaryName | grep GLIBC_2\.1[6-9] | wc -l`
if [ "$BadCount" != "0" ]; then
Error "Bad GLIBC usages found: $BadCount"
fi
BadCount=`objdump -T $ReleasePath/$BinaryName | grep GLIBC_2\.2[0-9] | wc -l`
if [ "$BadCount" != "0" ]; then
Error "Bad GLIBC usages found: $BadCount"
fi
BadCount=`objdump -T $ReleasePath/$BinaryName | grep GCC_4\.[3-9] | wc -l`
if [ "$BadCount" != "0" ]; then
Error "Bad GCC usages found: $BadCount"
fi
BadCount=`objdump -T $ReleasePath/$BinaryName | grep GCC_[5-9]\. | wc -l`
if [ "$BadCount" != "0" ]; then
Error "Bad GCC usages found: $BadCount"
fi
if [ ! -f "$ReleasePath/Updater" ]; then
Error "Updater not found!"
fi
BadCount=`objdump -T $ReleasePath/Updater | grep GLIBC_2\.1[6-9] | wc -l`
if [ "$BadCount" != "0" ]; then
Error "Bad GLIBC usages found: $BadCount"
fi
BadCount=`objdump -T $ReleasePath/Updater | grep GLIBC_2\.2[0-9] | wc -l`
if [ "$BadCount" != "0" ]; then
Error "Bad GLIBC usages found: $BadCount"
fi
BadCount=`objdump -T $ReleasePath/Updater | grep GCC_4\.[3-9] | wc -l`
if [ "$BadCount" != "0" ]; then
Error "Bad GCC usages found: $BadCount"
fi
BadCount=`objdump -T $ReleasePath/Updater | grep GCC_[5-9]\. | wc -l`
if [ "$BadCount" != "0" ]; then
Error "Bad GCC usages found: $BadCount"
fi
echo "Dumping debug symbols.."
"$HomePath/../../Libraries/breakpad/out/Default/dump_syms" "$ReleasePath/$BinaryName" > "$ReleasePath/$BinaryName.sym"
echo "Done!"
echo "Stripping the executable.."
strip -s "$ReleasePath/$BinaryName"
echo "Done!"
echo "Removing RPATH.."
chrpath -d "$ReleasePath/$BinaryName"
echo "Done!"
echo "Preparing version $AppVersionStrFull, executing Packer.."
cd "$ReleasePath"
"./Packer" -path "$BinaryName" -path Updater -version $VersionForPacker $AlphaBetaParam
echo "Packer done!"
if [ "$AlphaVersion" != "0" ]; then
if [ ! -f "$ReleasePath/$AlphaKeyFile" ]; then
Error "Alpha version key file not found!"
fi
while IFS='' read -r line || [[ -n "$line" ]]; do
AlphaSignature="$line"
done < "$ReleasePath/$AlphaKeyFile"
UpdateFile="${UpdateFile}_${AlphaSignature}"
SetupFile="talpha${AlphaVersion}_${AlphaSignature}.tar.xz"
fi
SymbolsHash=`head -n 1 "$ReleasePath/$BinaryName.sym" | awk -F " " 'END {print $4}'`
echo "Copying $BinaryName.sym to $DropboxSymbolsPath/$BinaryName/$SymbolsHash"
mkdir -p "$DropboxSymbolsPath/$BinaryName/$SymbolsHash"
cp "$ReleasePath/$BinaryName.sym" "$DropboxSymbolsPath/$BinaryName/$SymbolsHash/"
echo "Done!"
if [ ! -d "$ReleasePath/deploy" ]; then
mkdir "$ReleasePath/deploy"
fi
if [ ! -d "$ReleasePath/deploy/$AppVersionStrMajor" ]; then
mkdir "$ReleasePath/deploy/$AppVersionStrMajor"
fi
echo "Copying $BinaryName, Updater and $UpdateFile to deploy/$AppVersionStrMajor/$AppVersionStrFull..";
mkdir "$DeployPath"
mkdir "$DeployPath/$BinaryName"
mv "$ReleasePath/$BinaryName" "$DeployPath/$BinaryName/"
mv "$ReleasePath/Updater" "$DeployPath/$BinaryName/"
mv "$ReleasePath/$UpdateFile" "$DeployPath/"
if [ "$AlphaVersion" != "0" ]; then
mv "$ReleasePath/$AlphaKeyFile" "$DeployPath/"
fi
cd "$DeployPath"
tar -cJvf "$SetupFile" "$BinaryName/"
mkdir -p $BackupPath
cp "$SetupFile" "$BackupPath/"
cp "$UpdateFile" "$BackupPath/"
if [ "$AlphaVersion" != "0" ]; then
cp -v "$AlphaKeyFile" "$BackupPath/"
fi
fi
if [ "$BuildTarget" == "mac" ] || [ "$BuildTarget" == "mac32" ] || [ "$BuildTarget" == "macstore" ]; then
DropboxSymbolsPath="$HOME/Dropbox/Telegram/symbols"
if [ ! -d "$DropboxSymbolsPath" ]; then
Error "Dropbox path not found!"
fi
BackupPath="$HOME/Telegram/backup/$AppVersionStrMajor/$AppVersionStrFull"
if [ ! -d "$HOME/Telegram/backup" ]; then
Error "Backup path not found!"
fi
gyp/refresh.sh
xcodebuild -project Telegram.xcodeproj -alltargets -configuration Release build
if [ ! -d "$ReleasePath/$BinaryName.app" ]; then
Error "$BinaryName.app not found!"
fi
if [ ! -d "$ReleasePath/$BinaryName.app.dSYM" ]; then
Error "$BinaryName.app.dSYM not found!"
fi
if [ "$BuildTarget" == "mac" ] || [ "$BuildTarget" == "mac32" ]; then
if [ ! -f "$ReleasePath/$BinaryName.app/Contents/Frameworks/Updater" ]; then
Error "Updater not found!"
fi
if [ ! -f "$ReleasePath/$BinaryName.app/Contents/Helpers/crashpad_handler" ]; then
Error "crashpad_handler not found!"
fi
fi
if [ "$BuildTarget" == "macstore" ]; then
if [ ! -d "$ReleasePath/$BinaryName.app/Contents/Frameworks/Breakpad.framework" ]; then
Error "Breakpad.framework not found!"
fi
fi
echo "Dumping debug symbols.."
"$HomePath/../../Libraries/breakpad/src/tools/mac/dump_syms/build/Release/dump_syms" "$ReleasePath/$BinaryName.app.dSYM" > "$ReleasePath/$BinaryName.sym" 2>/dev/null
echo "Done!"
echo "Stripping the executable.."
strip "$ReleasePath/$BinaryName.app/Contents/MacOS/$BinaryName"
echo "Done!"
echo "Signing the application.."
if [ "$BuildTarget" == "mac" ] || [ "$BuildTarget" == "mac32" ]; then
codesign --force --deep --sign "Developer ID Application: John Preston" "$ReleasePath/$BinaryName.app"
elif [ "$BuildTarget" == "macstore" ]; then
codesign --force --deep --sign "3rd Party Mac Developer Application: TELEGRAM MESSENGER LLP (6N38VWS5BX)" "$ReleasePath/$BinaryName.app" --entitlements "$HomePath/Telegram/Telegram Desktop.entitlements"
echo "Making an installer.."
productbuild --sign "3rd Party Mac Developer Installer: TELEGRAM MESSENGER LLP (6N38VWS5BX)" --component "$ReleasePath/$BinaryName.app" /Applications "$ReleasePath/$BinaryName.pkg"
fi
echo "Done!"
AppUUID=`dwarfdump -u "$ReleasePath/$BinaryName.app/Contents/MacOS/$BinaryName" | awk -F " " '{print $2}'`
DsymUUID=`dwarfdump -u "$ReleasePath/$BinaryName.app.dSYM" | awk -F " " '{print $2}'`
if [ "$AppUUID" != "$DsymUUID" ]; then
Error "UUID of binary '$AppUUID' and dSYM '$DsymUUID' differ!"
fi
if [ ! -f "$ReleasePath/$BinaryName.app/Contents/Resources/Icon.icns" ]; then
Error "Icon.icns not found in Resources!"
fi
if [ ! -f "$ReleasePath/$BinaryName.app/Contents/MacOS/$BinaryName" ]; then
Error "$BinaryName not found in MacOS!"
fi
if [ ! -d "$ReleasePath/$BinaryName.app/Contents/_CodeSignature" ]; then
Error "$BinaryName signature not found!"
fi
if [ "$BuildTarget" == "mac" ] || [ "$BuildTarget" == "mac32" ]; then
if [ ! -f "$ReleasePath/$BinaryName.app/Contents/Frameworks/Updater" ]; then
Error "Updater not found in Frameworks!"
fi
elif [ "$BuildTarget" == "macstore" ]; then
if [ ! -f "$ReleasePath/$BinaryName.pkg" ]; then
Error "$BinaryName.pkg not found!"
fi
fi
SymbolsHash=`head -n 1 "$ReleasePath/$BinaryName.sym" | awk -F " " 'END {print $4}'`
echo "Copying $BinaryName.sym to $DropboxSymbolsPath/$BinaryName/$SymbolsHash"
mkdir -p "$DropboxSymbolsPath/$BinaryName/$SymbolsHash"
cp "$ReleasePath/$BinaryName.sym" "$DropboxSymbolsPath/$BinaryName/$SymbolsHash/"
echo "Done!"
if [ "$BuildTarget" == "mac" ] || [ "$BuildTarget" == "mac32" ]; then
if [ "$AlphaVersion" == "0" ]; then
cd "$ReleasePath"
cp -f tsetup_template.dmg tsetup.temp.dmg
TempDiskPath=`hdiutil attach -nobrowse -noautoopenrw -readwrite tsetup.temp.dmg | awk -F "\t" 'END {print $3}'`
cp -R "./$BinaryName.app" "$TempDiskPath/"
bless --folder "$TempDiskPath/" --openfolder "$TempDiskPath/"
hdiutil detach "$TempDiskPath"
hdiutil convert tsetup.temp.dmg -format UDZO -imagekey zlib-level=9 -ov -o "$SetupFile"
rm tsetup.temp.dmg
fi
cd "$ReleasePath"
"./Packer" -path "$BinaryName.app" -target "$BuildTarget" -version $VersionForPacker $AlphaBetaParam
echo "Packer done!"
if [ "$AlphaVersion" != "0" ]; then
if [ ! -f "$ReleasePath/$AlphaKeyFile" ]; then
Error "Alpha version key file not found!"
fi
while IFS='' read -r line || [[ -n "$line" ]]; do
AlphaSignature="$line"
done < "$ReleasePath/$AlphaKeyFile"
UpdateFile="${UpdateFile}_${AlphaSignature}"
SetupFile="talpha${AlphaVersion}_${AlphaSignature}.zip"
fi
fi
if [ ! -d "$ReleasePath/deploy" ]; then
mkdir "$ReleasePath/deploy"
fi
if [ ! -d "$ReleasePath/deploy/$AppVersionStrMajor" ]; then
mkdir "$ReleasePath/deploy/$AppVersionStrMajor"
fi
if [ "$BuildTarget" == "mac" ] || [ "$BuildTarget" == "mac32" ]; then
echo "Copying $BinaryName.app and $UpdateFile to deploy/$AppVersionStrMajor/$AppVersionStr..";
mkdir "$DeployPath"
mkdir "$DeployPath/$BinaryName"
cp -r "$ReleasePath/$BinaryName.app" "$DeployPath/$BinaryName/"
if [ "$AlphaVersion" != "0" ]; then
cd "$DeployPath"
zip -r "$SetupFile" "$BinaryName"
mv "$SetupFile" "$ReleasePath/"
mv "$ReleasePath/$AlphaKeyFile" "$DeployPath/"
fi
mv "$ReleasePath/$BinaryName.app.dSYM" "$DeployPath/"
rm "$ReleasePath/$BinaryName.app/Contents/MacOS/$BinaryName"
rm "$ReleasePath/$BinaryName.app/Contents/Frameworks/Updater"
rm "$ReleasePath/$BinaryName.app/Contents/Info.plist"
rm -rf "$ReleasePath/$BinaryName.app/Contents/_CodeSignature"
mv "$ReleasePath/$UpdateFile" "$DeployPath/"
mv "$ReleasePath/$SetupFile" "$DeployPath/"
if [ "$BuildTarget" == "mac" ]; then
mkdir -p "$BackupPath/tmac"
cp "$DeployPath/$UpdateFile" "$BackupPath/tmac/"
cp "$DeployPath/$SetupFile" "$BackupPath/tmac/"
if [ "$AlphaVersion" != "0" ]; then
cp -v "$DeployPath/$AlphaKeyFile" "$BackupPath/tmac/"
fi
fi
if [ "$BuildTarget" == "mac32" ]; then
mkdir -p "$BackupPath/tmac32"
cp "$DeployPath/$UpdateFile" "$BackupPath/tmac32/"
cp "$DeployPath/$SetupFile" "$BackupPath/tmac32/"
if [ "$AlphaVersion" != "0" ]; then
cp -v "$DeployPath/$AlphaKeyFile" "$BackupPath/tmac32/"
fi
fi
elif [ "$BuildTarget" == "macstore" ]; then
echo "Copying $BinaryName.app to deploy/$AppVersionStrMajor/$AppVersionStr..";
mkdir "$DeployPath"
cp -r "$ReleasePath/$BinaryName.app" "$DeployPath/"
mv "$ReleasePath/$BinaryName.pkg" "$DeployPath/"
mv "$ReleasePath/$BinaryName.app.dSYM" "$DeployPath/"
rm "$ReleasePath/$BinaryName.app/Contents/MacOS/$BinaryName"
rm "$ReleasePath/$BinaryName.app/Contents/Info.plist"
rm -rf "$ReleasePath/$BinaryName.app/Contents/_CodeSignature"
fi
fi
echo "Version $AppVersionStrFull is ready!";
echo -en "\007";
sleep 1;
echo -en "\007";
sleep 1;
echo -en "\007";