-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmacBuild.sh
332 lines (271 loc) · 8.05 KB
/
macBuild.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
#!/usr/bin/env bash
#
# macBuild.sh
# version 1.0.3
#
# Created by Sergey Balalaev on 23.04.21.
# Copyright (c) 2021 ByteriX. All rights reserved.
#
SRC_DIR=${PWD}
BUILD_DIR=${SRC_DIR}/.build
RESULT_DIR=${SRC_DIR}/build
OUTPUT_NAME=""
NAME=""
BUNDLE_NAME=""
TEAM_ID=""
DEV_ID=""
USERNAME=""
PASSWORD=""
IS_BUILD=false
IS_DEPLOY=false
IS_ADDING_VERSION=false
CMAKE_PARAMS=""
# get parameters of script
POSITIONAL=()
if [ "$#" -le 0 ]; then
echo -e '\nSomething is missing... Type "sh macBuild.sh -h" without the quotes to find out more...\n'
exit 0
fi
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-on|--outputName)
OUTPUT_NAME="$2"
shift # past argument
shift # past value
;;
-p|--project)
NAME="$2"
shift # past argument
shift # past value
;;
-bu|--bundle)
BUNDLE_NAME="$2"
shift # past argument
shift # past value
;;
-u|--user)
USERNAME="$2"
PASSWORD="$3"
if [ PASSWORD == "" ]; then
echo "ERROR: $1 need 2 parameters"
exit
fi
shift # past argument
shift # past value 1
shift # past value 2
;;
-t|--team)
TEAM_ID=$2
shift # past argument
shift # past value
;;
-de|--developer)
DEV_ID=$2
shift # past argument
shift # past value
;;
-b|--build)
IS_BUILD=true
shift # past argument
;;
-d|--deploy)
IS_DEPLOY=true
shift # past argument
;;
-a|--all)
IS_BUILD=true
IS_DEPLOY=true
shift # past argument
;;
-c|--cmake)
CMAKE_PARAMS="$2"
shift # past argument
shift # past value
;;
-av|--addVersion)
IS_ADDING_VERSION=true
shift # past argument
;;
-h|--help)
echo ""
echo "Help for call build script with parameters:"
echo " -on, --outputName : name of app file. Not requered param. If empty then use project name:"
echo " -p, --project : name of project. Requered param."
echo " -bu, --bundle : name of bundle for Application. Requered param."
echo " -u, --user : 2 params: login password. It specialized user, who created in Connection of developer programm. If defined then App will be uploaded to Store."
echo " -t, --team : team identifier of your developer program for a upload IPA to Connection AppSore. If defined -ep doesn't meater and export plist will created automaticle."
echo " -de, --developer : developer identifier: please create 'Developer ID Application' certificate and use this name here"
echo " -b, --build : If selected then will build Application"
echo " -d, --deploy : If selected then will create signed DMG installer"
echo " -a, --all : If selected then will make all features."
echo " -c, --cmake : Params of cmake build"
echo " -av, --addVersion : Add to the name of installer current version"
echo ""
echo "Emample: sh build.sh --project ProjectName --bundle ProjectName.Orgaization.com --user UserName Password123 --team 123456 --developer 'Developer ID Application: Ivan Pupkin (123456)' --all --cmake '-DCMAKE_PREFIX_PATH=/usr/local/Cellar/qt'\n\n"
exit 0
;;
*)
shift
;;
esac
done
set -- "${POSITIONAL[@]}" # restore positional parameters
# Initalize
APP=${NAME}.app
DMG=""
if [ $OUTPUT_NAME == "" ]; then
OUTPUT_NAME=$NAME
fi
TEMP_DMG="temp_${NAME}.dmg"
backgroundPictureName=back.png
checkExit(){
if [ $? != 0 ]; then
echo "Building failed\n"
exit 1
fi
}
prepareBuild(){
rm -rf "$RESULT_DIR"
mkdir -pv "$RESULT_DIR"
rm -rf "$BUILD_DIR"
mkdir -pv "$BUILD_DIR"
}
buildRelease(){
cd "${BUILD_DIR}"
cmake .. -DCMAKE_INSTALL_PREFIX="${RESULT_DIR}"\
-DCMAKE_BUILD_TYPE=Release\
${CMAKE_PARAMS}\
-DNO_SHIBBOLETH=1
# -Wno-dev
# cd ..
make install
}
signBuild(){
cd "${RESULT_DIR}"
rm -rf ./sign
mkdir -pv ./sign
NEW_APP=${OUTPUT_NAME}.app
echo "Creating ${NEW_APP}"
mv ./${APP} "./${NEW_APP}"
APP=${NEW_APP}
cp -R "./${APP}" ./sign
cd ./sign
#sign
codesign --deep --force --verify --verbose --options runtime --timestamp --sign "${DEV_ID}" "${APP}"
#verify
codesign --verify --verbose=4 "${APP}"
# Prepare link
ln -s "/Applications" "${RESULT_DIR}/sign/Applications"
mkdir "${RESULT_DIR}/sign/.background"
cp "$SRC_DIR/$backgroundPictureName" "${RESULT_DIR}/sign/.background"
}
prepareInstaller(){
cd "${RESULT_DIR}"
VERSION_NAME=$(plutil -extract CFBundleShortVersionString xml1 -o - "${APP}/Contents/Info.plist" | sed -n "s/.*<string>\(.*\)<\/string>.*/\1/p")
echo "Version of ${APP} is ${VERSION_NAME}"
rm -f -d -r ./dmg
mkdir -p ./dmg
cd ./dmg
if $IS_ADDING_VERSION ; then
DMG=${NAME}${VERSION_NAME}.dmg
else
DMG=${NAME}.dmg
fi
echo "installer file: $DMG prepared"
}
# depricated easy installer
createInstaller(){
hdiutil create -volname ${NAME} -srcfolder "${RESULT_DIR}/sign" -ov -format UDBZ ${DMG}
}
createInstallerWithBeatyInterface(){
hdiutil create -volname ${NAME} -srcfolder "${RESULT_DIR}/sign" -fs HFS+ \
-fsargs "-c c=64,a=16,e=16" -format UDRW ${DMG}
mv ${DMG} ${TEMP_DMG}
title="${NAME}"
device=$(hdiutil attach -readwrite -noverify -noautoopen ${TEMP_DMG} | \
egrep '^/dev/' | sed 1q | awk '{print $1}')
echo '
tell application "Finder"
tell disk "'${title}'"
open
set current view of container window to icon view
set toolbar visible of container window to false
set statusbar visible of container window to false
set the bounds of container window to {400, 200, 790, 300}
set theViewOptions to the icon view options of container window
set arrangement of theViewOptions to not arranged
set icon size of theViewOptions to 48
set background picture of theViewOptions to file ".background:'${backgroundPictureName}'"
set position of item "'${APP}'" of container window to {90, 90}
set position of item "Applications" of container window to {300, 90}
set position of item ".background" of container window to {90, 300}
set position of item ".fseventsd" of container window to {300, 300}
update without registering applications
delay 5
close
end tell
end tell
' | osascript
chmod -Rf go-w /Volumes/"${NAME}"
sync
sync
hdiutil detach ${device}
hdiutil convert "${TEMP_DMG}" -format UDBZ -ov -o "${DMG}"
rm -f ${TEMP_DMG}
}
signInstallerAndCheckWithApple(){
# Sign installer and push to Apple
codesign -s "${DEV_ID}" --timestamp ${DMG}
REQUEST=$(xcrun altool --notarize-app -f ${DMG} --primary-bundle-id ${BUNDLE_NAME} -u $USERNAME -p $PASSWORD --team-id ${TEAM_ID})
# Cheching Apple approving
REQUEST_ID=$(echo "${REQUEST}" | awk -F'RequestUUID = ' '{print $2}' | awk '{print $1}')
echo "RequestUUID is ${REQUEST_ID}"
while : ; do
sleep 10
INFO=$(xcrun altool --notarization-info $REQUEST_ID -u $USERNAME -p $PASSWORD)
if [[ $INFO =~ 'Message: Package Approved' && $INFO =~ 'Status: success' ]]; then
echo "bingo!"
break
fi
echo "waiting information"
done
# Finising process and test
xcrun stapler staple -v ${DMG}
hdiutil attach ${DMG}
pushd /Volumes/${NAME}
spctl -a -v "/Volumes/${NAME}/${APP}"
popd
diskutil eject "/Volumes/${NAME}"
}
# Main code:
if $IS_BUILD ; then
echo "Prerare build..."
prepareBuild
checkExit
echo "Starting build:"
buildRelease
checkExit
echo ""
echo "Build success!!!"
echo ""
fi
if $IS_DEPLOY ; then
echo "Starting sign Application:"
signBuild
checkExit
echo "Prepare installer:"
prepareInstaller
checkExit
echo "Creating installer:"
#createInstaller
createInstallerWithBeatyInterface
checkExit
echo "Sign installer and check it with Apple:"
signInstallerAndCheckWithApple
checkExit
echo ""
echo "Deploy success!!!"
echo ""
fi