Skip to content

Commit bc34da9

Browse files
committed
fixup! tools: notarize bin/node in the darwin tarballs
Move helpers to the top of the script, make the cleanup trap script-wide and split the pkg and binary flows into functions. Signed-off-by: Ulises Gascon <ulisesgascongonzalez@gmail.com>
1 parent a67d9bc commit bc34da9

1 file changed

Lines changed: 73 additions & 67 deletions

File tree

‎tools/osx-notarize.sh‎

Lines changed: 73 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -18,52 +18,6 @@
1818
# For backwards compatibility a bare version id (for example v26.13.0) is
1919
# accepted and resolved to node-<version>.pkg.
2020

21-
target="$1"
22-
23-
if [ -z "$target" ]; then
24-
echo "Usage: $0 <path-to-pkg-or-binary>"
25-
exit 1
26-
fi
27-
28-
# shellcheck disable=SC2154
29-
if [ -z "$NOTARIZATION_ID" ]; then
30-
echo "No NOTARIZATION_ID environment variable. Skipping notarization."
31-
exit 0
32-
fi
33-
34-
if [ -z "$NOTARIZATION_PASSWORD" ]; then
35-
echo "No NOTARIZATION_PASSWORD environment variable. Skipping notarization."
36-
exit 0
37-
fi
38-
39-
if [ -z "$NOTARIZATION_TEAM_ID" ]; then
40-
echo "No NOTARIZATION_TEAM_ID environment variable. Skipping notarization."
41-
exit 0
42-
fi
43-
44-
# Legacy call form: a version id instead of a path.
45-
if [ ! -e "$target" ] && [ -e "node-$target.pkg" ]; then
46-
target="node-$target.pkg"
47-
fi
48-
49-
if [ ! -e "$target" ]; then
50-
echo "error: $target does not exist." 1>&2
51-
exit 1
52-
fi
53-
54-
case "$target" in
55-
*.pkg) kind=pkg ;;
56-
*) kind=binary ;;
57-
esac
58-
59-
echo "Notarization process is done with Notarytool."
60-
61-
if ! command -v xcrun notarytool > /dev/null
62-
then
63-
echo "Notarytool is not present in the system. Notarization has failed."
64-
exit 1
65-
fi
66-
6721
# The notarization ticket can take a while to become available from Apple's
6822
# servers after notarytool reports "Accepted", so retry with backoff.
6923
retry() {
@@ -93,36 +47,40 @@ submit() {
9347
fi
9448
}
9549

96-
if [ "$kind" = "pkg" ]; then
97-
submit "$target" || exit 1
50+
# Remove the upload zip on every exit path, including a failed ditto or an
51+
# interrupted build, the same way the dep_updaters scripts clean their
52+
# workspace. $zip is only set by notarize_binary.
53+
cleanup() {
54+
EXIT_CODE=$?
55+
if [ -n "$zip" ]; then
56+
rm -f "$zip"
57+
fi
58+
exit $EXIT_CODE
59+
}
60+
61+
notarize_pkg() {
62+
submit "$1" || exit 1
9863

99-
if ! retry xcrun spctl --assess --type install --context context:primary-signature --ignore-cache --verbose=2 "$target"; then
64+
if ! retry xcrun spctl --assess --type install --context context:primary-signature --ignore-cache --verbose=2 "$1"; then
10065
echo "error: Signature will not be accepted by Gatekeeper!" 1>&2
10166
exit 1
102-
else
103-
echo "Verification was successful."
10467
fi
68+
echo "Verification was successful."
10569

106-
if ! retry xcrun stapler staple "$target"; then
107-
echo "error: Stapling $target failed." 1>&2
70+
if ! retry xcrun stapler staple "$1"; then
71+
echo "error: Stapling $1 failed." 1>&2
10872
exit 1
10973
fi
11074
echo "Stapler was successful."
111-
else
75+
}
76+
77+
notarize_binary() {
11278
# ditto preserves the code signature and resource forks, which plain zip
11379
# does not, so it is the archiver Apple documents for notarization uploads.
114-
# The zip only exists for the upload. Remove it on every exit path,
115-
# including a failed ditto or an interrupted build, the same way the
116-
# dep_updaters scripts clean their workspace.
117-
zip="$target.notarize.zip"
118-
cleanup () {
119-
EXIT_CODE=$?
120-
rm -f "$zip"
121-
exit $EXIT_CODE
122-
}
123-
trap cleanup INT TERM EXIT
80+
# The zip only exists for the upload and is removed by cleanup.
81+
zip="$1.notarize.zip"
12482
rm -f "$zip"
125-
if ! ditto -c -k --keepParent "$target" "$zip"; then
83+
if ! ditto -c -k --keepParent "$1" "$zip"; then
12684
echo "error: Could not create $zip for submission." 1>&2
12785
exit 1
12886
fi
@@ -133,9 +91,57 @@ else
13391
# There is nothing to staple to a bare binary, so the only way to confirm
13492
# the ticket is live is to have codesign look it up. spctl cannot be used
13593
# here: it rejects command line tools with "does not seem to be an app".
136-
if ! retry codesign --verify --verbose=2 -R=notarized "$target"; then
137-
echo "error: $target will not be accepted by Gatekeeper!" 1>&2
94+
if ! retry codesign --verify --verbose=2 -R=notarized "$1"; then
95+
echo "error: $1 will not be accepted by Gatekeeper!" 1>&2
13896
exit 1
13997
fi
14098
echo "Verification was successful."
99+
}
100+
101+
target="$1"
102+
103+
if [ -z "$target" ]; then
104+
echo "Usage: $0 <path-to-pkg-or-binary>"
105+
exit 1
141106
fi
107+
108+
# shellcheck disable=SC2154
109+
if [ -z "$NOTARIZATION_ID" ]; then
110+
echo "No NOTARIZATION_ID environment variable. Skipping notarization."
111+
exit 0
112+
fi
113+
114+
if [ -z "$NOTARIZATION_PASSWORD" ]; then
115+
echo "No NOTARIZATION_PASSWORD environment variable. Skipping notarization."
116+
exit 0
117+
fi
118+
119+
if [ -z "$NOTARIZATION_TEAM_ID" ]; then
120+
echo "No NOTARIZATION_TEAM_ID environment variable. Skipping notarization."
121+
exit 0
122+
fi
123+
124+
# Legacy call form: a version id instead of a path.
125+
if [ ! -e "$target" ] && [ -e "node-$target.pkg" ]; then
126+
target="node-$target.pkg"
127+
fi
128+
129+
if [ ! -e "$target" ]; then
130+
echo "error: $target does not exist." 1>&2
131+
exit 1
132+
fi
133+
134+
echo "Notarization process is done with Notarytool."
135+
136+
if ! command -v xcrun notarytool > /dev/null
137+
then
138+
echo "Notarytool is not present in the system. Notarization has failed."
139+
exit 1
140+
fi
141+
142+
trap cleanup INT TERM EXIT
143+
144+
case "$target" in
145+
*.pkg) notarize_pkg "$target" ;;
146+
*) notarize_binary "$target" ;;
147+
esac

0 commit comments

Comments
 (0)