|
18 | 18 | # For backwards compatibility a bare version id (for example v26.13.0) is |
19 | 19 | # accepted and resolved to node-<version>.pkg. |
20 | 20 |
|
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 | | - |
67 | 21 | # The notarization ticket can take a while to become available from Apple's |
68 | 22 | # servers after notarytool reports "Accepted", so retry with backoff. |
69 | 23 | retry() { |
@@ -93,36 +47,40 @@ submit() { |
93 | 47 | fi |
94 | 48 | } |
95 | 49 |
|
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 |
98 | 63 |
|
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 |
100 | 65 | echo "error: Signature will not be accepted by Gatekeeper!" 1>&2 |
101 | 66 | exit 1 |
102 | | - else |
103 | | - echo "Verification was successful." |
104 | 67 | fi |
| 68 | + echo "Verification was successful." |
105 | 69 |
|
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 |
108 | 72 | exit 1 |
109 | 73 | fi |
110 | 74 | echo "Stapler was successful." |
111 | | -else |
| 75 | +} |
| 76 | + |
| 77 | +notarize_binary() { |
112 | 78 | # ditto preserves the code signature and resource forks, which plain zip |
113 | 79 | # 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" |
124 | 82 | rm -f "$zip" |
125 | | - if ! ditto -c -k --keepParent "$target" "$zip"; then |
| 83 | + if ! ditto -c -k --keepParent "$1" "$zip"; then |
126 | 84 | echo "error: Could not create $zip for submission." 1>&2 |
127 | 85 | exit 1 |
128 | 86 | fi |
|
133 | 91 | # There is nothing to staple to a bare binary, so the only way to confirm |
134 | 92 | # the ticket is live is to have codesign look it up. spctl cannot be used |
135 | 93 | # 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 |
138 | 96 | exit 1 |
139 | 97 | fi |
140 | 98 | 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 |
141 | 106 | 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