|
1 | 1 | #!/bin/sh
|
2 | 2 |
|
3 |
| -# Uses gon, from https://github.com/mitchellh/gon, to notarize a generated node-<version>.pkg file |
4 |
| -# with Apple for installation on macOS Catalina and later as validated by Gatekeeper. |
| 3 | +# Notarize a generated node-<version>.pkg file as an Apple requirement for installation on macOS Catalina and later, as validated by Gatekeeper. |
| 4 | +# Uses gon (Xcode version < 13.0) or notarytool (Xcode >= 13.0). |
5 | 5 |
|
6 |
| -set -e |
7 |
| - |
8 |
| -gon_version="0.2.2" |
9 |
| -gon_exe="${HOME}/.gon/gon_${gon_version}" |
| 6 | +version() { |
| 7 | + echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }' || echo "0" |
| 8 | +} |
10 | 9 |
|
| 10 | +xcode_version=$(xcodebuild -version | awk '/Xcode/ {print $2}') |
| 11 | +xcode_version_result=$(version "$xcode_version") |
| 12 | +xcode_version_threshold=$(version "13.0") |
11 | 13 | pkgid="$1"
|
12 | 14 |
|
13 |
| -[ -z "$pkgid" ] && \ |
14 |
| - echo "Usage: $0 <pkgid>" \ |
| 15 | +if [ -z "$pkgid" ]; then |
| 16 | + echo "Usage: $0 <pkgid>" |
15 | 17 | exit 1
|
| 18 | +fi |
16 | 19 |
|
17 | 20 | # shellcheck disable=SC2154
|
18 |
| -[ -z "$NOTARIZATION_ID" ] && \ |
19 |
| - echo "No NOTARIZATION_ID environment var. Skipping notarization." \ |
| 21 | +if [ -z "$NOTARIZATION_ID" ]; then |
| 22 | + echo "No NOTARIZATION_ID environment variable. Skipping notarization." |
20 | 23 | exit 0
|
| 24 | +fi |
21 | 25 |
|
22 |
| -set -x |
23 |
| - |
24 |
| -mkdir -p "${HOME}/.gon/" |
| 26 | +if [ -z "$NOTARIZATION_PASSWORD" ]; then |
| 27 | + echo "No NOTARIZATION_PASSWORD environment variable. Skipping notarization." |
| 28 | + exit 0 |
| 29 | +fi |
25 | 30 |
|
26 |
| -if [ ! -f "${gon_exe}" ]; then |
27 |
| - curl -sL "https://github.com/mitchellh/gon/releases/download/v${gon_version}/gon_${gon_version}_macos.zip" -o "${gon_exe}.zip" |
28 |
| - (cd "${HOME}/.gon/" && rm -f gon && unzip "${gon_exe}.zip" && mv gon "${gon_exe}") |
| 31 | +if [ -z "$NOTARIZATION_TEAM_ID" ]; then |
| 32 | + echo "No NOTARIZATION_TEAM_ID environment variable. Skipping notarization." |
| 33 | + exit 0 |
29 | 34 | fi
|
30 | 35 |
|
31 |
| -sed -e "s/{{appleid}}/${NOTARIZATION_ID}/" -e "s/{{pkgid}}/${pkgid}/" tools/osx-gon-config.json.tmpl \ |
32 |
| - > gon-config.json |
| 36 | +# TODO(@ulisesGascon): remove support for gon |
| 37 | +# when https://github.com/nodejs/build/issues/3385#issuecomment-1729281269 is ready |
| 38 | +if [ "$xcode_version_result" -lt "$xcode_version_threshold" ]; then |
| 39 | + echo "Notarization process is done with gon." |
| 40 | + set -x |
| 41 | + |
| 42 | + gon_version="0.2.2" |
| 43 | + gon_exe="${HOME}/.gon/gon_${gon_version}" |
33 | 44 |
|
34 |
| -"${gon_exe}" -log-level=info gon-config.json |
| 45 | + mkdir -p "${HOME}/.gon/" |
| 46 | + |
| 47 | + if [ ! -f "${gon_exe}" ]; then |
| 48 | + curl -sL "https://github.com/mitchellh/gon/releases/download/v${gon_version}/gon_${gon_version}_macos.zip" -o "${gon_exe}.zip" |
| 49 | + (cd "${HOME}/.gon/" && rm -f gon && unzip "${gon_exe}.zip" && mv gon "${gon_exe}") |
| 50 | + fi |
| 51 | + |
| 52 | + sed -e "s/{{appleid}}/${NOTARIZATION_ID}/" -e "s/{{pkgid}}/${pkgid}/" tools/osx-gon-config.json.tmpl \ |
| 53 | + > gon-config.json |
| 54 | + |
| 55 | + "${gon_exe}" -log-level=info gon-config.json |
| 56 | + |
| 57 | +else |
| 58 | + echo "Notarization process is done with Notarytool." |
| 59 | + |
| 60 | + if ! command -v xcrun notarytool > /dev/null |
| 61 | + then |
| 62 | + echo "Notarytool is not present in the system. Notarization has failed." |
| 63 | + exit 1 |
| 64 | + fi |
| 65 | + |
| 66 | + # Submit the package for notarization |
| 67 | + # TODO(@ulisesGascon): refactor to use --keychain-profile |
| 68 | + # when https://github.com/nodejs/build/issues/3385#issuecomment-1729281269 is ready |
| 69 | + notarization_output=$( |
| 70 | + xcrun notarytool submit \ |
| 71 | + --apple-id "$NOTARIZATION_ID" \ |
| 72 | + --password "$NOTARIZATION_PASSWORD" \ |
| 73 | + --team-id "$NOTARIZATION_TEAM_ID" \ |
| 74 | + --wait \ |
| 75 | + "node-$pkgid.pkg" 2>&1 |
| 76 | + ) |
| 77 | + |
| 78 | + if [ $? -eq 0 ]; then |
| 79 | + # Extract the operation ID from the output |
| 80 | + operation_id=$(echo "$notarization_output" | awk '/RequestUUID/ {print $NF}') |
| 81 | + echo "Notarization submitted. Operation ID: $operation_id" |
| 82 | + exit 0 |
| 83 | + else |
| 84 | + echo "Notarization failed. Error: $notarization_output" |
| 85 | + exit 1 |
| 86 | + fi |
| 87 | +fi |
0 commit comments