forked from meganz/MEGAsync
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstaller_mac.sh
executable file
·219 lines (181 loc) · 8.99 KB
/
installer_mac.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
#!/bin/bash -e
Usage () {
echo "Usage: installer_mac.sh [[--sign] | [--create-dmg] | [--notarize]]"
}
APP_NAME=MEGAsync
ID_BUNDLE=mega.mac
MOUNTDIR=tmp
RESOURCES=installer/resourcesDMG
QTBASE=/QT/qt5/qtbase
#Get canonical path to be used when removing any @rpath or an absolute path from Qt executables
QTBASE="$(cd "$QTBASE"; pwd -P)"
AVCODEC_VERSION=libavcodec.57.dylib
AVFORMAT_VERSION=libavformat.57.dylib
AVUTIL_VERSION=libavutil.55.dylib
SWSCALE_VERSION=libswscale.4.dylib
AVCODEC_PATH=src/MEGASync/mega/bindings/qt/3rdparty/libs/$AVCODEC_VERSION
AVFORMAT_PATH=src/MEGASync/mega/bindings/qt/3rdparty/libs/$AVFORMAT_VERSION
AVUTIL_PATH=src/MEGASync/mega/bindings/qt/3rdparty/libs/$AVUTIL_VERSION
SWSCALE_PATH=src/MEGASync/mega/bindings/qt/3rdparty/libs/$SWSCALE_VERSION
sign=0
createdmg=0
notarize=0
while [ "$1" != "" ]; do
case $1 in
--sign ) sign=1
;;
--create-dmg ) createdmg=1
;;
--notarize ) notarize=1
;;
-h | --help ) Usage
exit
;;
* ) Usage
exit 1
esac
shift
done
rm -rf Release_x64
mkdir Release_x64
cd Release_x64
$QTBASE/bin/lrelease ../src/MEGASync/MEGASync.pro
$QTBASE/bin/qmake "CONFIG += FULLREQUIREMENTS" -r ../src -spec macx-g++ CONFIG+=release CONFIG+=x86_64 -nocache
make -j4
cp -R MEGASync/MEGAsync.app MEGASync/MEGAsync_orig.app
$QTBASE/bin/macdeployqt MEGASync/MEGAsync.app -no-strip
dsymutil MEGASync/MEGAsync.app/Contents/MacOS/MEGAsync -o MEGAsync.app.dSYM
strip MEGASync/MEGAsync.app/Contents/MacOS/MEGAsync
dsymutil MEGALoader/MEGAloader.app/Contents/MacOS/MEGAloader -o MEGAloader.dSYM
strip MEGALoader/MEGAloader.app/Contents/MacOS/MEGAloader
dsymutil MEGAUpdater/MEGAupdater.app/Contents/MacOS/MEGAupdater -o MEGAupdater.dSYM
strip MEGAUpdater/MEGAupdater.app/Contents/MacOS/MEGAupdater
dsymutil MEGADeprecatedVersion/MEGADeprecatedVersion.app/Contents/MacOS/MEGADeprecatedVersion -o MEGADeprecatedVersion.dSYM
strip MEGADeprecatedVersion/MEGADeprecatedVersion.app/Contents/MacOS/MEGADeprecatedVersion
mv MEGASync/MEGAsync.app/Contents/MacOS/MEGAsync MEGASync/MEGAsync.app/Contents/MacOS/MEGAclient
mv MEGALoader/MEGAloader.app/Contents/MacOS/MEGAloader MEGASync/MEGAsync.app/Contents/MacOS/MEGAsync
mv MEGAUpdater/MEGAupdater.app/Contents/MacOS/MEGAupdater MEGASync/MEGAsync.app/Contents/MacOS/MEGAupdater
mv MEGADeprecatedVersion/MEGADeprecatedVersion.app/Contents/MacOS/MEGADeprecatedVersion MEGASync/MEGAsync.app/Contents/MacOS/MEGADeprecatedVersion
cp -L ../$AVCODEC_PATH MEGASync/MEGAsync.app/Contents/Frameworks/
cp -L ../$AVFORMAT_PATH MEGASync/MEGAsync.app/Contents/Frameworks/
cp -L ../$AVUTIL_PATH MEGASync/MEGAsync.app/Contents/Frameworks/
cp -L ../$SWSCALE_PATH MEGASync/MEGAsync.app/Contents/Frameworks/
if [ ! -f MEGASync/MEGAsync.app/Contents/Frameworks/$AVCODEC_VERSION ] \
|| [ ! -f MEGASync/MEGAsync.app/Contents/Frameworks/$AVFORMAT_VERSION ] \
|| [ ! -f MEGASync/MEGAsync.app/Contents/Frameworks/$AVUTIL_VERSION ] \
|| [ ! -f MEGASync/MEGAsync.app/Contents/Frameworks/$SWSCALE_VERSION ];
then
echo "Error copying FFmpeg libs to app bundle."
exit 1
fi
MEGASYNC_VERSION=`grep "const QString Preferences::VERSION_STRING" ../src/MEGASync/control/Preferences.cpp | awk -F '"' '{print $2}'`
/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $MEGASYNC_VERSION" "$APP_NAME/$APP_NAME.app/Contents/Info.plist"
install_name_tool -change @loader_path/$AVCODEC_VERSION @executable_path/../Frameworks/$AVCODEC_VERSION MEGASync/MEGAsync.app/Contents/MacOS/MEGAclient
install_name_tool -change @loader_path/$AVFORMAT_VERSION @executable_path/../Frameworks/$AVFORMAT_VERSION MEGASync/MEGAsync.app/Contents/MacOS/MEGAclient
install_name_tool -change @loader_path/$AVUTIL_VERSION @executable_path/../Frameworks/$AVUTIL_VERSION MEGASync/MEGAsync.app/Contents/MacOS/MEGAclient
install_name_tool -change @loader_path/$SWSCALE_VERSION @executable_path/../Frameworks/$SWSCALE_VERSION MEGASync/MEGAsync.app/Contents/MacOS/MEGAclient
#If any @rpath or an absolute path to link to a dynamic library outside of the app, the app will be rejected by Gatekeeper, so remove them. QTBUG-61413
install_name_tool -delete_rpath "$QTBASE/lib" MEGASync/MEGAsync.app/Contents/Frameworks/QtGui.framework/Versions/5/QtGui
install_name_tool -delete_rpath "$QTBASE/lib" MEGASync/MEGAsync.app/Contents/Frameworks/QtMacExtras.framework/Versions/5/QtMacExtras
install_name_tool -delete_rpath "$QTBASE/lib" MEGASync/MEGAsync.app/Contents/Frameworks/QtNetwork.framework/Versions/5/QtNetwork
install_name_tool -delete_rpath "$QTBASE/lib" MEGASync/MEGAsync.app/Contents/Frameworks/QtPrintSupport.framework/Versions/5/QtPrintSupport
install_name_tool -delete_rpath "$QTBASE/lib" MEGASync/MEGAsync.app/Contents/Frameworks/QtWidgets.framework/Versions/5/QtWidgets
otool -L MEGASync/MEGAsync.app/Contents/MacOS/MEGAclient
mv MEGASync/MEGAsync.app ./
#Attach shell extension
xcodebuild clean build CODE_SIGN_IDENTITY="-" CODE_SIGNING_REQUIRED=NO -jobs "$(sysctl -n hw.ncpu)" -configuration Release -target MEGAShellExtFinder -project ../src/MEGAShellExtFinder/MEGAFinderSync.xcodeproj/
cp -a ../src/MEGAShellExtFinder/build/Release/MEGAShellExtFinder.appex $APP_NAME.app/Contents/Plugins/
if [ "$sign" = "1" ]; then
cp -R $APP_NAME.app ${APP_NAME}_unsigned.app
echo "Signing 'APPBUNDLE'"
codesign --force --verify --verbose --preserve-metadata=entitlements --options runtime --sign "Developer ID Application: Mega Limited" --deep $APP_NAME.app
echo "Checking signature"
spctl -vv -a $APP_NAME.app
fi
if [ "$createdmg" = "1" ]; then
echo "DMG CREATION PROCESS..."
echo "Creating temporary Disk Image (1/7)"
#Create a temporary Disk Image
/usr/bin/hdiutil create -srcfolder $APP_NAME.app/ -volname $APP_NAME -ov $APP_NAME-tmp.dmg -fs HFS+ -format UDRW >/dev/null
echo "Attaching the temporary image (2/7)"
#Attach the temporary image
mkdir $MOUNTDIR
/usr/bin/hdiutil attach $APP_NAME-tmp.dmg -mountroot $MOUNTDIR >/dev/null
echo "Copying resources (3/7)"
#Copy the background, the volume icon and DS_Store files
unzip -d $MOUNTDIR/$APP_NAME ../$RESOURCES.zip
/usr/bin/SetFile -a C $MOUNTDIR/$APP_NAME
echo "Adding symlinks (4/7)"
#Add a symbolic link to the Applications directory
ln -s /Applications/ $MOUNTDIR/$APP_NAME/Applications
echo "Detaching temporary Disk Image (5/7)"
#Detach the temporary image
/usr/bin/hdiutil detach $MOUNTDIR/$APP_NAME >/dev/null
echo "Compressing Image (6/7)"
#Compress it to a new image
/usr/bin/hdiutil convert $APP_NAME-tmp.dmg -format UDZO -o $APP_NAME.dmg >/dev/null
echo "Deleting temporary image (7/7)"
#Delete the temporary image
rm $APP_NAME-tmp.dmg
rmdir $MOUNTDIR
fi
if [ "$notarize" = "1" ]; then
rm querystatus.txt staple.txt || :
echo "NOTARIZATION PROCESS..."
echo "Getting USERNAME for notarization commands (1/7)"
AC_USERNAME=$(security find-generic-password -s AC_PASSWORD | grep acct | cut -d '"' -f 4)
if [[ -z "$AC_USERNAME" ]]; then
echo "Error USERNAME not found for notarization process. You should add item named AC_PASSWORD with and account value matching the username to macOS keychain"
false
fi
echo "Sending dmg for notarization (2/7)"
xcrun altool --notarize-app -t osx -f $APP_NAME.dmg --primary-bundle-id $ID_BUNDLE -u $AC_USERNAME -p "@keychain:AC_PASSWORD" --output-format xml 2>&1 > staple.txt
RUUID=$(cat staple.txt | grep RequestUUID -A 1 | tail -n 1 | awk -F "[<>]" '{print $3}')
echo $RUUID
if [ ! -z "$RUUID" ] ; then
echo "Received UUID for notarization request. Checking state... (3/7)"
attempts=60
while [ $attempts -gt 0 ]
do
echo "Querying state of notarization..."
xcrun altool --notarization-info $RUUID -u $AC_USERNAME -p "@keychain:AC_PASSWORD" --output-format xml 2>&1 > querystatus.txt
RUUIDQUERY=$(cat querystatus.txt | grep RequestUUID -A 1 | tail -n 1 | awk -F "[<>]" '{print $3}')
if [[ "$RUUID" != "$RUUIDQUERY" ]]; then
echo "UUIDs missmatch"
false
fi
STATUS=$(cat querystatus.txt | grep -i ">Status<" -A 1 | tail -n 1 | awk -F "[<>]" '{print $3}')
if [[ $STATUS == "invalid" ]]; then
echo "INVALID status. Check file querystatus.txt for further information"
echo $STATUS
break
elif [[ $STATUS == "success" ]]; then
echo "Notarized ok. Stapling dmg file..."
xcrun stapler staple -v $APP_NAME.dmg
echo "Stapling ok"
#Mount dmg volume to check if app bundle is notarized
echo "Checking signature and notarization"
mkdir $MOUNTDIR || :
hdiutil attach $APP_NAME.dmg -mountroot $MOUNTDIR >/dev/null
spctl -v -a $MOUNTDIR/$APP_NAME/$APP_NAME.app
hdiutil detach $MOUNTDIR/$APP_NAME >/dev/null
rmdir $MOUNTDIR
break
else
echo $STATUS
fi
attempts=$((attempts - 1))
sleep 30
done
if [[ $attempts -eq 0 ]]; then
echo "Notarization still in process, timed out waiting for the process to end"
false
fi
fi
fi
echo "Cleaning"
rm -rf MEGAsync
rm -rf MEGALoader
rm -rf MEGAUpdater
rm -rf MEGADeprecatedVersion
echo "DONE"