|
19 | 19 | # ---------------------------------------------------------------------------- |
20 | 20 | # NOTICE: This script has to be executed on a macOS system with the |
21 | 21 | # required certificate available. In order to sign the application for |
22 | | -# yourself, you need to obtain a Developer ID from Apple and set the |
23 | | -# KEY variable accordingly. |
| 22 | +# yourself, you need to obtain a Developer ID from Apple and set some |
| 23 | +# environment variables in the ".env" file. If it is not available, create a |
| 24 | +# copy from ".env.example". |
24 | 25 | # ---------------------------------------------------------------------------- |
25 | 26 |
|
26 | | -KEY="Developer ID Application: Andreas Rudolph (H48THMS543)" |
27 | | -DIR=$( cd $( dirname ${BASH_SOURCE[0]} ) && pwd ) |
28 | | -TARGET_DIR="$DIR/target" |
29 | | -SIGNED_DIR="$DIR/signed" |
30 | | -TEMP_DIR="$TARGET_DIR/codesign" |
| 27 | +DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) |
| 28 | +TARGET_DIR="${DIR}/target" |
| 29 | +SIGNED_DIR="${DIR}/signed" |
31 | 30 | FOUND="0" |
32 | 31 | set -e |
33 | 32 |
|
34 | | -mkdir -p "$SIGNED_DIR" |
35 | | -export LANG="en_US.UTF-8" |
| 33 | +APPLE_CODESIGN_KEY="" |
| 34 | +if [[ -f "${DIR}/.env" ]]; then |
| 35 | + source "${DIR}/.env" |
| 36 | +fi |
36 | 37 |
|
37 | | -for f in ${TARGET_DIR}/*.macos-*.tar.gz; do |
| 38 | +if [[ -z "${APPLE_CODESIGN_KEY}" ]]; then |
| 39 | + echo "ERROR: No signature key was specified!" |
| 40 | + exit 1 |
| 41 | +fi |
| 42 | + |
| 43 | +mkdir -p "${SIGNED_DIR}" |
| 44 | +export LANG="en_US.UTF-8" |
38 | 45 |
|
39 | | - if [[ "$FOUND" == "0" ]]; then |
40 | | - echo "" |
41 | | - printf "\e[1m\e[92m=======================================================================\e[0m\n" |
42 | | - printf "\e[1m\e[92m Unlocking keychain...\e[0m\n" |
43 | | - printf "\e[1m\e[92m=======================================================================\e[0m\n" |
44 | | - echo "" |
45 | | - security unlock-keychain |
46 | | - fi |
| 46 | +for f in "${TARGET_DIR}"/*.macos-*.tar.gz; do |
47 | 47 |
|
48 | | - FOUND="1" |
| 48 | + if [[ "${FOUND}" == "0" ]]; then |
49 | 49 | echo "" |
50 | 50 | printf "\e[1m\e[92m=======================================================================\e[0m\n" |
51 | | - printf "\e[1m\e[92m Processing $(basename "$f")...\e[0m\n" |
| 51 | + printf "\e[1m\e[92m Unlocking keychain...\e[0m\n" |
52 | 52 | printf "\e[1m\e[92m=======================================================================\e[0m\n" |
53 | 53 | echo "" |
54 | | - rm -Rf "$TEMP_DIR" |
55 | | - mkdir -p "$TEMP_DIR" |
56 | | - tar xfz "$f" -C "$TEMP_DIR" |
57 | | - pkg="$(ls -1 "$TEMP_DIR")" |
58 | | - codesign --deep -s "$KEY" "$TEMP_DIR/$pkg" |
59 | | - echo "Verifying signature:" |
60 | | - codesign -d --verbose=4 "$TEMP_DIR/$pkg" |
61 | | - echo "" |
62 | | - echo "Verifying access for Gatekeeper:" |
63 | | - spctl --assess --verbose=4 --type execute "$TEMP_DIR/$pkg" |
64 | | - echo "" |
65 | | - echo "Storing signed application bundle at:" |
66 | | - echo "$SIGNED_DIR/$(basename "$f")" |
67 | | - rm -f "$SIGNED_DIR/$(basename "$f")" |
68 | | - cd "$TEMP_DIR" |
69 | | - tar cfz "$SIGNED_DIR/$(basename "$f")" "$pkg" |
| 54 | + security unlock-keychain |
| 55 | + fi |
| 56 | + |
| 57 | + FOUND="1" |
| 58 | + archive="$(basename "${f}")" |
| 59 | + archive_name="$(basename "${archive}" ".tar.gz")" |
| 60 | + signed_dir="${SIGNED_DIR}/${archive_name}" |
| 61 | + rm -Rf "${signed_dir}" |
| 62 | + mkdir -p "${signed_dir}" |
| 63 | + |
| 64 | + echo "" |
| 65 | + printf "\e[1m\e[92m=======================================================================\e[0m\n" |
| 66 | + printf "\e[1m\e[92m Processing %s...\e[0m\n" "${archive}" |
| 67 | + printf "\e[1m\e[92m=======================================================================\e[0m\n" |
| 68 | + |
| 69 | + echo "" |
| 70 | + echo "Extracting application bundle." |
| 71 | + tar xfz "${f}" -C "${signed_dir}" |
| 72 | + pkg="$(ls -1 "${signed_dir}")" |
| 73 | + signed_bundle="${signed_dir}/${pkg}" |
| 74 | + |
| 75 | + echo "" |
| 76 | + echo "Signing application bundle at:" |
| 77 | + echo "" |
| 78 | + echo "${signed_bundle}" |
| 79 | + codesign --deep --force --verify --sign "${APPLE_CODESIGN_KEY}" --options runtime "${signed_bundle}" |
| 80 | + |
| 81 | + echo "" |
| 82 | + echo "Verifying signature:" |
| 83 | + codesign --verify --verbose=4 "${signed_bundle}" |
| 84 | + #codesign --display --verbose=4 "${signed_bundle}" |
| 85 | + |
| 86 | + echo "" |
| 87 | + echo "Verifying access for Gatekeeper:" |
| 88 | + spctl --assess --verbose=4 --type execute "${signed_dir}/${pkg}" |
| 89 | + |
| 90 | + echo "" |
| 91 | + echo "Compressing application bundle to:" |
| 92 | + signed_tar="${signed_dir}/${archive_name}.tar.gz" |
| 93 | + echo "${signed_tar}" |
| 94 | + cd "${signed_dir}" |
| 95 | + rm -f "${signed_tar}" |
| 96 | + tar cfz "${signed_tar}" "$(basename "${signed_bundle}")" |
| 97 | + |
| 98 | + echo "" |
| 99 | + echo "Compressing application bundle to:" |
| 100 | + signed_zip="${signed_dir}/${archive_name}.zip" |
| 101 | + echo "${signed_zip}" |
| 102 | + cd "${signed_dir}" |
| 103 | + rm -f "${signed_zip}" |
| 104 | + # According to Apples documentation "Customizing the Notarization Workflow" at |
| 105 | + # https://developer.apple.com/documentation/xcode/notarizing_macos_software_before_distribution/customizing_the_notarization_workflow |
| 106 | + # we can't use the ZIP command, as it leads to problems in the notarization process. |
| 107 | + # Therefore we're using ditto instead. |
| 108 | + #zip -r -q "${signed_zip}" "$(basename "${signed_bundle}")" |
| 109 | + ditto -c -k --keepParent "$(basename "${signed_bundle}")" "${signed_zip}" |
| 110 | + |
70 | 111 | done |
71 | 112 |
|
72 | | -if [[ "$FOUND" == "0" ]]; then |
73 | | - echo "ERROR: No macOS packages were found at:" |
74 | | - echo "$TARGET_DIR" |
| 113 | +if [[ "${FOUND}" == "0" ]]; then |
| 114 | + echo "ERROR: No macOS packages were found at:" |
| 115 | + echo "${TARGET_DIR}" |
| 116 | + exit 1 |
75 | 117 | fi |
76 | | - |
77 | | -rm -Rf "$TEMP_DIR" |
|
0 commit comments