[16776] | 1 | #!/bin/bash
|
---|
| 2 |
|
---|
[17487] | 3 | ## Expected environment, passed from GitHub secrets:
|
---|
| 4 | # https://docs.github.com/en/free-pro-team@latest/actions/reference/encrypted-secrets
|
---|
| 5 | # APPLE_ID_PW Password for the Apple ID
|
---|
| 6 | # CERT_MACOS_P12 Certificate used for code signing, base64 encoded
|
---|
| 7 | # CERT_MACOS_PW Password for that certificate
|
---|
| 8 |
|
---|
[18146] | 9 | set -Eeo pipefail
|
---|
[16776] | 10 |
|
---|
| 11 | # Don't show one time passwords
|
---|
| 12 | set +x
|
---|
| 13 |
|
---|
| 14 | IMPORT_AND_UNLOCK_KEYCHAIN=${IMPORT_AND_UNLOCK_KEYCHAIN:-1}
|
---|
| 15 |
|
---|
| 16 | if [ -z "${1-}" ]
|
---|
| 17 | then
|
---|
[19030] | 18 | echo "Usage: $0 josm_revision [other_arch_jdk]"
|
---|
[16776] | 19 | exit 1
|
---|
| 20 | fi
|
---|
| 21 |
|
---|
| 22 | echo "Building JOSM.app"
|
---|
| 23 |
|
---|
[17239] | 24 | mkdir app
|
---|
[16776] | 25 |
|
---|
[18904] | 26 | if [ -z "$CERT_MACOS_P12" ] || [ -z "$CERT_MACOS_PW" ] || [ -z "$APPLE_ID_PW" ] || [ -z "$APPLE_ID_TEAM" ] || [ -z "$APPLE_ID" ]
|
---|
[17487] | 27 | then
|
---|
[18904] | 28 | echo "CERT_MACOS_P12, CERT_MACOS_PW, APPLE_ID, APPLE_ID_PW, or APPLE_ID_TEAM are not set in the environment."
|
---|
[18146] | 29 | echo "A JOSM.app will be created but not signed nor notarized."
|
---|
[17487] | 30 | SIGNAPP=false
|
---|
[18476] | 31 | KEYCHAINPATH=false
|
---|
| 32 | JPACKAGEOPTIONS=""
|
---|
[17487] | 33 | else
|
---|
[16776] | 34 | echo "Preparing certificates/keychain for signing…"
|
---|
| 35 |
|
---|
| 36 | KEYCHAIN=build.keychain
|
---|
[17373] | 37 | KEYCHAINPATH=~/Library/Keychains/$KEYCHAIN-db
|
---|
[17487] | 38 | KEYCHAIN_PW=$(head /dev/urandom | base64 | head -c 20)
|
---|
[16776] | 39 | CERTIFICATE_P12=certificate.p12
|
---|
| 40 |
|
---|
[17487] | 41 | echo "$CERT_MACOS_P12" | base64 --decode > $CERTIFICATE_P12
|
---|
| 42 | security create-keychain -p "$KEYCHAIN_PW" $KEYCHAIN
|
---|
[16776] | 43 | security default-keychain -s $KEYCHAIN
|
---|
[17487] | 44 | security unlock-keychain -p "$KEYCHAIN_PW" $KEYCHAIN
|
---|
| 45 | security import $CERTIFICATE_P12 -k $KEYCHAIN -P "$CERT_MACOS_PW" -T /usr/bin/codesign
|
---|
| 46 | security set-key-partition-list -S apple-tool:,apple: -s -k "$KEYCHAIN_PW" $KEYCHAIN
|
---|
[16776] | 47 | rm $CERTIFICATE_P12
|
---|
[17487] | 48 | SIGNAPP=true
|
---|
[16776] | 49 | echo "Signing preparation done."
|
---|
[18476] | 50 | JPACKAGEOPTIONS="--mac-sign --mac-signing-keychain $KEYCHAINPATH"
|
---|
[16776] | 51 | fi
|
---|
| 52 |
|
---|
[18146] | 53 | set -u
|
---|
| 54 |
|
---|
[19030] | 55 | function do_jpackage() {
|
---|
| 56 | echo "Building app (${JAVA_HOME})"
|
---|
| 57 | # We specifically need the options to not be quoted -- we _want_ the word splitting.
|
---|
| 58 | # shellcheck disable=SC2086
|
---|
| 59 | "${JAVA_HOME}/bin/jpackage" $JPACKAGEOPTIONS -n "JOSM" --input dist --main-jar josm-custom.jar \
|
---|
| 60 | --main-class org.openstreetmap.josm.gui.MainApplication \
|
---|
| 61 | --icon ./native/macosx/JOSM.icns --type app-image --dest app \
|
---|
[19215] | 62 | --java-options "-XX:MaxRAMPercentage=75.0" \
|
---|
| 63 | --java-options "-Xms256m" \
|
---|
[19030] | 64 | --java-options "--add-modules java.scripting,java.sql,javafx.controls,javafx.media,javafx.swing,javafx.web" \
|
---|
| 65 | --java-options "--add-exports=java.base/sun.security.action=ALL-UNNAMED" \
|
---|
| 66 | --java-options "--add-exports=java.desktop/com.apple.eawt=ALL-UNNAMED" \
|
---|
| 67 | --java-options "--add-exports=java.desktop/com.sun.imageio.plugins.jpeg=ALL-UNNAMED" \
|
---|
| 68 | --java-options "--add-exports=java.desktop/com.sun.imageio.spi=ALL-UNNAMED" \
|
---|
| 69 | --java-options "--add-opens=java.base/java.lang=ALL-UNNAMED" \
|
---|
| 70 | --java-options "--add-opens=java.base/java.nio=ALL-UNNAMED" \
|
---|
| 71 | --java-options "--add-opens=java.base/jdk.internal.loader=ALL-UNNAMED" \
|
---|
| 72 | --java-options "--add-opens=java.base/jdk.internal.ref=ALL-UNNAMED" \
|
---|
| 73 | --java-options "--add-opens=java.desktop/javax.imageio.spi=ALL-UNNAMED" \
|
---|
| 74 | --java-options "--add-opens=java.desktop/javax.swing.text.html=ALL-UNNAMED" \
|
---|
| 75 | --java-options "--add-opens=java.prefs/java.util.prefs=ALL-UNNAMED" \
|
---|
| 76 | --app-version "$1" \
|
---|
| 77 | --copyright "JOSM, and all its integral parts, are released under the GNU General Public License v2 or later" \
|
---|
| 78 | --vendor "JOSM" \
|
---|
| 79 | --mac-package-identifier de.openstreetmap.josm \
|
---|
| 80 | --mac-package-signing-prefix de.openstreetmap.josm \
|
---|
| 81 | --file-associations native/file-associations/bz2.properties \
|
---|
| 82 | --file-associations native/file-associations/geojson.properties \
|
---|
| 83 | --file-associations native/file-associations/gpx.properties \
|
---|
| 84 | --file-associations native/file-associations/gz.properties \
|
---|
| 85 | --file-associations native/file-associations/jos.properties \
|
---|
| 86 | --file-associations native/file-associations/joz.properties \
|
---|
| 87 | --file-associations native/file-associations/osm.properties \
|
---|
| 88 | --file-associations native/file-associations/xz.properties \
|
---|
| 89 | --file-associations native/file-associations/zip.properties \
|
---|
| 90 | --add-modules java.compiler,java.base,java.datatransfer,java.desktop,java.logging,java.management,java.naming,java.net.http,java.prefs,java.rmi,java.scripting,java.sql,java.transaction.xa,java.xml,jdk.crypto.ec,jdk.jfr,jdk.jsobject,jdk.unsupported,jdk.unsupported.desktop,jdk.xml.dom,javafx.controls,javafx.media,javafx.swing,javafx.web
|
---|
| 91 | echo "Building done (${JAVA_HOME})."
|
---|
| 92 | }
|
---|
| 93 | function do_signapp() {
|
---|
| 94 | echo "Compressing app (${1})"
|
---|
| 95 | ditto -c -k --zlibCompressionLevel 9 --keepParent "app/${1}.app" "app/${1}.zip"
|
---|
| 96 | if $SIGNAPP; then
|
---|
| 97 | echo "Signing app (${1})"
|
---|
| 98 | echo "Preparing for notarization"
|
---|
| 99 | echo "Uploading to Apple"
|
---|
| 100 | xcrun notarytool submit --apple-id "$APPLE_ID" --password "$APPLE_ID_PW" --team-id "$APPLE_ID_TEAM" --wait "app/${1}.zip"
|
---|
| 101 | fi
|
---|
| 102 | }
|
---|
[16776] | 103 |
|
---|
[19030] | 104 | function merge() {
|
---|
| 105 | if [ "$(command -v lipo)" ]; then
|
---|
| 106 | lipo -create -output "${1}" "${2}" "${3}"
|
---|
| 107 | elif [ "$(command -v llvm-lipo-15)" ]; then
|
---|
| 108 | llvm-lipo-15 -create -output "${1}" "${2}" "${3}"
|
---|
| 109 | fi
|
---|
| 110 | }
|
---|
[16776] | 111 |
|
---|
[19030] | 112 | function copy() {
|
---|
| 113 | # Trim the root path
|
---|
| 114 | FILE="${1#*/}"
|
---|
| 115 | if [ ! -e "${2}/${FILE}" ]; then
|
---|
| 116 | # Only make directories if we aren't looking at the root files
|
---|
| 117 | if [[ "${FILE}" == *"/"* ]]; then mkdir -p "${2}/${FILE%/*}"; fi
|
---|
| 118 | if file "${1}" | grep -q 'Mach-O' ; then
|
---|
| 119 | merge "${2}/${FILE}" "${3}/${FILE}" "${4}/${FILE}"
|
---|
| 120 | if file "${1}" | grep -q 'executable'; then
|
---|
| 121 | chmod 755 "${2}/${FILE}"
|
---|
| 122 | fi
|
---|
| 123 | else
|
---|
| 124 | cp -a "${1}" "${2}/${FILE}"
|
---|
| 125 | fi
|
---|
| 126 | fi
|
---|
| 127 | }
|
---|
[16776] | 128 |
|
---|
[19030] | 129 | function directory_iterate() {
|
---|
| 130 | while IFS= read -r -d '' file
|
---|
| 131 | do
|
---|
| 132 | copy "${file}" "${2}" "${3}" "${4}" &
|
---|
| 133 | done < <(find "${1}" -type f,l -print0)
|
---|
| 134 | wait
|
---|
| 135 | }
|
---|
| 136 |
|
---|
| 137 | do_jpackage "${1}"
|
---|
| 138 | if [ -n "${2}" ]; then
|
---|
| 139 | function get_name() {
|
---|
| 140 | echo "$("${JAVA_HOME}/bin/java" --version | head -n1 | awk '{print $2}' | awk -F'.' '{print $1}')_$(file "${JAVA_HOME}/bin/java" | awk -F' executable ' '{print $2}')"
|
---|
| 141 | }
|
---|
| 142 | first="$(get_name)"
|
---|
| 143 | JAVA_HOME="${2}" second="$(get_name)"
|
---|
| 144 | mv app/JOSM.app "app/JOSM_${first}.app"
|
---|
| 145 | JAVA_HOME="${2}" do_jpackage "${1}"
|
---|
| 146 | mv app/JOSM.app "app/JOSM_${second}.app"
|
---|
| 147 | mkdir app/JOSM.app
|
---|
| 148 | (cd app
|
---|
| 149 | directory_iterate "JOSM_${first}.app" "JOSM.app" "JOSM_${first}.app" "JOSM_${second}.app"
|
---|
| 150 | directory_iterate "JOSM_${second}.app" "JOSM.app" "JOSM_${first}.app" "JOSM_${second}.app"
|
---|
| 151 | )
|
---|
| 152 | do_signapp "JOSM_${first}"
|
---|
| 153 | do_signapp "JOSM_${second}"
|
---|
[19061] | 154 | if [ "${KEYCHAINPATH}" != "false" ]; then
|
---|
[19032] | 155 | function do_codesign() {
|
---|
| 156 | codesign --sign "FOSSGIS e.V." \
|
---|
| 157 | --force \
|
---|
| 158 | --keychain "${KEYCHAINPATH}" \
|
---|
| 159 | --timestamp \
|
---|
| 160 | --prefix "de.openstreetmap.josm" \
|
---|
| 161 | --identifier "${2}" \
|
---|
| 162 | --options runtime \
|
---|
[19036] | 163 | --entitlements "$(dirname "${BASH_SOURCE[0]}")/josm.entitlements" \
|
---|
[19032] | 164 | --verbose=4 "${1}"
|
---|
| 165 | }
|
---|
| 166 | do_codesign app/JOSM.app/Contents/runtime "com.oracle.java.de.openstreetmap.josm"
|
---|
| 167 | do_codesign app/JOSM.app/ "de.openstreetmap.josm"
|
---|
| 168 | fi
|
---|
[17711] | 169 | fi
|
---|
[19030] | 170 | do_signapp JOSM
|
---|