-
Notifications
You must be signed in to change notification settings - Fork 11
/
macos_notarize_dmg.sh
executable file
·210 lines (189 loc) · 6.02 KB
/
macos_notarize_dmg.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
#!/usr/bin/env bash
NOTARIZATION_TIMEOUT_SEC=600
NOTARIZATION_TIME_INCREMENT_SEC=5
PROJECT_DIR="$PWD"
BUILD_DIR="${PROJECT_DIR}/build"
CODESIGN_IDENTITY="Developer ID Application: Alexey Yudichev (J4R72JZQ9P)"
APP_NAME="${1}"
[[ -z "${APP_NAME}" ]] && {
echo "app name missing"
exit 1
}
VERSION="${2}"
[[ -z "${VERSION}" ]] && {
echo "version missing"
exit 1
}
JAVA_HOME="${3}"
[[ -z "${JAVA_HOME}" ]] && {
echo "java home missing"
exit 1
}
echo "Signing and notarizing $1 version $2"
function sign_jar_internals() {
local jar_dir="$1"
local jar_file_pattern="$2"
local jar_path
jar_path="$(find "${jar_dir}" -name "${jar_file_pattern}")"
local tmp_unpacked_path="${BUILD_DIR}/tmp/${jar_path}_unpacked"
rm -rf "${tmp_unpacked_path}"
if [[ $? -ne 0 ]]; then
echo >&2 "Failed to delete ${tmp_unpacked_path}"
exit 1
fi
mkdir -p "${tmp_unpacked_path}"
if [[ $? -ne 0 ]]; then
echo >&2 "Failed to create ${tmp_unpacked_path}"
exit 1
fi
unzip -q "${jar_path}" -d "${tmp_unpacked_path}"
if [[ $? -ne 0 ]]; then
echo >&2 "Failed to unzip"
exit 1
fi
find "${tmp_unpacked_path}" \
-type f \
-name "*lib" \
-exec codesign \
-f \
--timestamp \
--entitlements "${PROJECT_DIR}/src/main/packaging-resources/macOS/entitlements.plist" \
-s "${CODESIGN_IDENTITY}" \
--prefix net.yudichev.googlephotosupload.ui. \
--options runtime \
-vvvv \
{} \;
if [[ $? -ne 0 ]]; then
echo >&2 "Failed to sign"
exit 1
fi
rm -f "${jar_path}"
if [[ $? -ne 0 ]]; then
echo >&2 "Failed to delete ${jar_path}"
exit 1
fi
(cd "${tmp_unpacked_path}" && zip -q -r "${jar_path}" ./*)
if [[ $? -ne 0 ]]; then
echo >&2 "Failed to zip"
exit 1
fi
echo "signed ${jar_path}"
}
sign_jar_internals "${BUILD_DIR}/jpackage/${APP_NAME}.app/Contents/app" "grpc-netty-shaded-*.jar"
sign_jar_internals "${BUILD_DIR}/jpackage/${APP_NAME}.app/Contents/app" "javafx-graphics-*-mac.jar"
sign_jar_internals "${BUILD_DIR}/jpackage/${APP_NAME}.app/Contents/app" "javafx-media-*-mac.jar"
sign_jar_internals "${BUILD_DIR}/jpackage/${APP_NAME}.app/Contents/app" "javafx-web-*-mac.jar"
sign_jar_internals "${BUILD_DIR}/jpackage/${APP_NAME}.app/Contents/app" "conscrypt-openjdk-uber-*.jar"
find "${BUILD_DIR}/jpackage/${APP_NAME}.app" -type f \
-not -path "*/Contents/runtime/*" \
-not -path "*/Contents/MacOS/${APP_NAME}" \
-not -path "*libapplauncher.dylib" \
-exec codesign \
--timestamp \
--entitlements "${PROJECT_DIR}/src/main/packaging-resources/macOS/entitlements.plist" \
-s "${CODESIGN_IDENTITY}" \
--prefix net.yudichev.googlephotosupload.ui. \
--options runtime \
-vvvv \
{} \;
if [[ $? -ne 0 ]]; then
echo >&2 "Failed to sign"
exit 1
fi
find "${BUILD_DIR}/jpackage/${APP_NAME}.app/Contents/runtime" -type f \
-not -path "*/legal/*" \
-not -path "*/man/*" \
-exec codesign \
-f \
--timestamp \
--entitlements "${PROJECT_DIR}/src/main/packaging-resources/macOS/entitlements.plist" \
-s "${CODESIGN_IDENTITY}" \
--prefix net.yudichev.googlephotosupload.ui. \
--options runtime \
-vvvv \
{} \;
if [[ $? -ne 0 ]]; then
echo >&2 "Failed to sign"
exit 1
fi
codesign \
-f \
--timestamp \
--entitlements "${PROJECT_DIR}/src/main/packaging-resources/macOS/entitlements.plist" \
-s "${CODESIGN_IDENTITY}" \
--prefix net.yudichev.googlephotosupload.ui. \
--options runtime \
-vvvv \
"${BUILD_DIR}/jpackage/${APP_NAME}.app/Contents/runtime"
if [[ $? -ne 0 ]]; then
echo >&2 "Failed to sign"
exit 1
fi
codesign \
-f \
--timestamp \
--entitlements "${PROJECT_DIR}/src/main/packaging-resources/macOS/entitlements.plist" \
-s "${CODESIGN_IDENTITY}" \
--prefix net.yudichev.googlephotosupload.ui. \
--options runtime \
-vvvv \
"${BUILD_DIR}/jpackage/${APP_NAME}.app"
if [[ $? -ne 0 ]]; then
echo >&2 "Failed to sign"
exit 1
fi
"$JAVA_HOME/bin/jpackage" \
--type dmg \
--dest "${BUILD_DIR}/jpackage" \
--name "${APP_NAME}" \
--app-version "${VERSION}" \
--app-image "${BUILD_DIR}/jpackage/${APP_NAME}.app" \
--resource-dir "${PROJECT_DIR}/src/main/packaging-resources/macOS/out"
if [[ $? -ne 0 ]]; then
echo >&2 "jpackage failed"
exit 1
fi
echo "Uploading package for notarization..."
notarize_output="$(xcrun altool \
--notarize-app \
--primary-bundle-id "net.yudichev.jiottyphotosupload.dmg" \
--username "[email protected]" --password "@keychain:Apple Notarization Tool App Password" \
--file "${BUILD_DIR}/jpackage/${APP_NAME}-${VERSION}.dmg" 2>&1)"
if [[ $? -ne 0 ]]; then
echo >&2 "failed to invoke notarization:"
echo >&2 "${notarize_output}"
exit 1
fi
request_uuid="$(echo "${notarize_output}" | grep "RequestUUID = " | awk '{print $3}')"
if [[ -z "${request_uuid}" ]]; then
echo >&2 "Notarization command failed, output was:"
echo "${notarize_output}"
exit 1
fi
echo "Notarization command success, request ID ${request_uuid}, full output was:"
echo "${notarize_output}"
notarization_waited_sec=0
echo "Waiting for a max of ${NOTARIZATION_TIMEOUT_SEC} seconds for the package to be notarized..."
while [[ $notarization_waited_sec -lt $NOTARIZATION_TIMEOUT_SEC ]] && [[ "${notarization_status}" != "success" ]]; do
sleep $NOTARIZATION_TIME_INCREMENT_SEC
notarization_waited_sec=$((notarization_waited_sec + NOTARIZATION_TIME_INCREMENT_SEC))
notarization_status_str="$(xcrun altool --notarization-history 0 --username "[email protected]" --password "@keychain:Apple Notarization Tool App Password" 2>&1)"
if [[ $? -ne 0 ]]; then
echo >&2 "WARN: failed to check notarization history, output was: ${notarization_status_str}"
else
notarization_status_str="$(echo "${notarization_status_str}" | grep "${request_uuid}")"
fi
echo "${notarization_status_str}"
notarization_status="$(echo "${notarization_status_str}" | awk '{print $5}')"
done
if [[ "${notarization_status}" != "success" ]]; then
echo >&2 "Failed to notarize"
exit 1
fi
echo "Notarized, stapling..."
xcrun stapler staple "${BUILD_DIR}/jpackage/${APP_NAME}-${VERSION}.dmg"
if [[ $? -ne 0 ]]; then
echo >&2 "Failed to staple"
exit 1
fi
echo "All done"