build.sh 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. #!/bin/bash
  2. # parse options
  3. usage() { echo "Usage: $0 [-s <codesign-identity>] [-t <team-identifier>]" 1>&2; exit 1; }
  4. while getopts ":s:t:" o; do
  5. case "${o}" in
  6. s)
  7. CODESIGN_IDENTITY=${OPTARG}
  8. ;;
  9. t)
  10. TEAM_IDENTIFIER=${OPTARG}
  11. ;;
  12. *)
  13. usage
  14. ;;
  15. esac
  16. done
  17. shift "$((OPTIND-1))"
  18. # prepare working dir
  19. cd $(dirname $0)
  20. rm -rf runtime dmg *.app *.dmg
  21. # set variables
  22. APP_NAME="Cryptomator"
  23. VENDOR="Skymatic GmbH"
  24. COPYRIGHT_YEARS="2016 - 2024"
  25. PACKAGE_IDENTIFIER="org.cryptomator"
  26. MAIN_JAR_GLOB="cryptomator-*.jar"
  27. MODULE_AND_MAIN_CLASS="org.cryptomator.desktop/org.cryptomator.launcher.Cryptomator"
  28. REVISION_NO=`git rev-list --count HEAD`
  29. VERSION_NO=`mvn -f../../../pom.xml help:evaluate -Dexpression=project.version -q -DforceStdout | sed -rn 's/.*([0-9]+\.[0-9]+\.[0-9]+).*/\1/p'`
  30. FUSE_LIB="FUSE-T"
  31. JAVAFX_VERSION=22.0.2
  32. JAVAFX_ARCH="undefined"
  33. JAVAFX_JMODS_SHA256="undefined"
  34. if [ "$(machine)" = "arm64e" ]; then
  35. JAVAFX_ARCH="aarch64"
  36. JAVAFX_JMODS_SHA256="813c6748f7c99cb7a579d48b48a087b4682b1fad1fc1a4fe5f9b21cf872b15a7"
  37. else
  38. JAVAFX_ARCH="x64"
  39. JAVAFX_JMODS_SHA256="115cb08bb59d880cfff6e51e0bf0dcc45785ed9d456b8b8425597b04da6ab3d4"
  40. fi
  41. JAVAFX_JMODS_URL="https://download2.gluonhq.com/openjfx/${JAVAFX_VERSION}/openjfx-${JAVAFX_VERSION}_osx-${JAVAFX_ARCH}_bin-jmods.zip"
  42. # check preconditions
  43. if [ -z "${JAVA_HOME}" ]; then echo "JAVA_HOME not set. Run using JAVA_HOME=/path/to/jdk ./build.sh"; exit 1; fi
  44. command -v mvn >/dev/null 2>&1 || { echo >&2 "mvn not found. Fix by 'brew install maven'."; exit 1; }
  45. command -v create-dmg >/dev/null 2>&1 || { echo >&2 "create-dmg not found. Fix by 'brew install create-dmg'."; exit 1; }
  46. if [ -n "${CODESIGN_IDENTITY}" ]; then
  47. command -v codesign >/dev/null 2>&1 || { echo >&2 "codesign not found. Fix by 'xcode-select --install'."; exit 1; }
  48. if [[ ! `security find-identity -v -p codesigning | grep -w "${CODESIGN_IDENTITY}"` ]]; then echo "Given codesign identity is invalid."; exit 1; fi
  49. fi
  50. # download and check jmods
  51. curl -L ${JAVAFX_JMODS_URL} -o openjfx-jmods.zip
  52. echo "${JAVAFX_JMODS_SHA256} openjfx-jmods.zip" | shasum -a256 --check
  53. mkdir -p openjfx-jmods/
  54. unzip -jo openjfx-jmods.zip \*/javafx.base.jmod \*/javafx.controls.jmod \*/javafx.fxml.jmod \*/javafx.graphics.jmod -d openjfx-jmods
  55. JMOD_VERSION=$(jmod describe openjfx-jmods/javafx.base.jmod | head -1)
  56. JMOD_VERSION=${JMOD_VERSION#*@}
  57. JMOD_VERSION=${JMOD_VERSION%%.*}
  58. POM_JFX_VERSION=$(mvn -f../../../pom.xml help:evaluate "-Dexpression=javafx.version" -q -DforceStdout)
  59. POM_JFX_VERSION=${POM_JFX_VERSION#*@}
  60. POM_JFX_VERSION=${POM_JFX_VERSION%%.*}
  61. if [ "${POM_JFX_VERSION}" -ne "${JMOD_VERSION}" ]; then
  62. >&2 echo "Major JavaFX version in pom.xml (${POM_JFX_VERSION}) != jmod version (${JMOD_VERSION})"
  63. exit 1
  64. fi
  65. # compile
  66. mvn -B -Djavafx.platform=mac -f../../../pom.xml clean package -DskipTests -Pmac
  67. cp ../../../LICENSE.txt ../../../target
  68. cp ../../../target/${MAIN_JAR_GLOB} ../../../target/mods
  69. # add runtime
  70. ${JAVA_HOME}/bin/jlink \
  71. --output runtime \
  72. --module-path "${JAVA_HOME}/jmods:openjfx-jmods" \
  73. --add-modules java.base,java.desktop,java.instrument,java.logging,java.naming,java.net.http,java.scripting,java.sql,java.xml,javafx.base,javafx.graphics,javafx.controls,javafx.fxml,jdk.unsupported,jdk.security.auth,jdk.accessibility,jdk.management.jfr,java.compiler \
  74. --strip-native-commands \
  75. --no-header-files \
  76. --no-man-pages \
  77. --strip-debug \
  78. --compress zip-0
  79. # create app dir
  80. ${JAVA_HOME}/bin/jpackage \
  81. --verbose \
  82. --type app-image \
  83. --runtime-image runtime \
  84. --input ../../../target/libs \
  85. --module-path ../../../target/mods \
  86. --module ${MODULE_AND_MAIN_CLASS} \
  87. --dest . \
  88. --name ${APP_NAME} \
  89. --vendor "${VENDOR}" \
  90. --copyright "(C) ${COPYRIGHT_YEARS} ${VENDOR}" \
  91. --app-version "${VERSION_NO}" \
  92. --java-options "--enable-preview" \
  93. --java-options "--enable-native-access=org.cryptomator.jfuse.mac" \
  94. --java-options "-Xss5m" \
  95. --java-options "-Xmx256m" \
  96. --java-options "-Dfile.encoding=\"utf-8\"" \
  97. --java-options "-Djava.net.useSystemProxies=true" \
  98. --java-options "-Dapple.awt.enableTemplateImages=true" \
  99. --java-options "-Dsun.java2d.metal=true" \
  100. --java-options "-Dcryptomator.appVersion=\"${VERSION_NO}\"" \
  101. --java-options "-Dcryptomator.logDir=\"@{userhome}/Library/Logs/${APP_NAME}\"" \
  102. --java-options "-Dcryptomator.pluginDir=\"@{userhome}/Library/Application Support/${APP_NAME}/Plugins\"" \
  103. --java-options "-Dcryptomator.settingsPath=\"@{userhome}/Library/Application Support/${APP_NAME}/settings.json\"" \
  104. --java-options "-Dcryptomator.ipcSocketPath=\"@{userhome}/Library/Application Support/${APP_NAME}/ipc.socket\"" \
  105. --java-options "-Dcryptomator.p12Path=\"@{userhome}/Library/Application Support/${APP_NAME}/key.p12\"" \
  106. --java-options "-Dcryptomator.integrationsMac.keychainServiceName=\"${APP_NAME}\"" \
  107. --java-options "-Dcryptomator.mountPointsDir=\"@{userhome}/Library/Application Support${APP_NAME}/mnt\"" \
  108. --java-options "-Dcryptomator.showTrayIcon=true" \
  109. --java-options "-Dcryptomator.buildNumber=\"dmg-${REVISION_NO}\"" \
  110. --mac-package-identifier ${PACKAGE_IDENTIFIER} \
  111. --resource-dir ../resources
  112. # transform app dir
  113. cp ../resources/${APP_NAME}-Vault.icns ${APP_NAME}.app/Contents/Resources/
  114. sed -i '' "s|###BUNDLE_SHORT_VERSION_STRING###|${VERSION_NO}|g" ${APP_NAME}.app/Contents/Info.plist
  115. sed -i '' "s|###BUNDLE_VERSION###|${REVISION_NO}|g" ${APP_NAME}.app/Contents/Info.plist
  116. cp ../embedded.provisionprofile ${APP_NAME}.app/Contents/
  117. # generate license
  118. mvn -B -Djavafx.platform=mac -f../../../pom.xml license:add-third-party \
  119. -Dlicense.thirdPartyFilename=license.rtf \
  120. -Dlicense.outputDirectory=dist/mac/dmg/resources \
  121. -Dlicense.fileTemplate=resources/licenseTemplate.ftl \
  122. -Dlicense.includedScopes=compile \
  123. -Dlicense.excludedGroups=^org\.cryptomator \
  124. -Dlicense.failOnMissing=true \
  125. -Dlicense.licenseMergesUrl=file://$(pwd)/../../../license/merges
  126. # codesign
  127. if [ -n "${CODESIGN_IDENTITY}" ] && [ -n "${TEAM_IDENTIFIER}" ]; then
  128. echo "Codesigning jdk files..."
  129. find ${APP_NAME}.app/Contents/runtime/Contents/Home/lib/ -name '*.dylib' -exec codesign --force -s ${CODESIGN_IDENTITY} {} \;
  130. find ${APP_NAME}.app/Contents/runtime/Contents/Home/lib/ -name 'jspawnhelper' -exec codesign --force -o runtime -s ${CODESIGN_IDENTITY} {} \;
  131. echo "Codesigning jar contents..."
  132. find ${APP_NAME}.app/Contents/runtime/Contents/MacOS -name '*.dylib' -exec codesign --force -s ${CODESIGN_IDENTITY} {} \;
  133. for JAR_PATH in `find ${APP_NAME}.app -name "*.jar"`; do
  134. if [[ `unzip -l ${JAR_PATH} | grep '.dylib\|.jnilib'` ]]; then
  135. JAR_FILENAME=$(basename ${JAR_PATH})
  136. OUTPUT_PATH=${JAR_PATH%.*}
  137. echo "Codesigning libs in ${JAR_FILENAME}..."
  138. unzip -q ${JAR_PATH} -d ${OUTPUT_PATH}
  139. find ${OUTPUT_PATH} -name '*.dylib' -exec codesign --force -s ${CODESIGN_IDENTITY} {} \;
  140. find ${OUTPUT_PATH} -name '*.jnilib' -exec codesign --force -s ${CODESIGN_IDENTITY} {} \;
  141. rm ${JAR_PATH}
  142. pushd ${OUTPUT_PATH} > /dev/null
  143. zip -qr ../${JAR_FILENAME} *
  144. popd > /dev/null
  145. rm -r ${OUTPUT_PATH}
  146. fi
  147. done
  148. echo "Codesigning ${APP_NAME}.app..."
  149. cp ../${APP_NAME}.entitlements .
  150. sed -i '' "s|###APP_IDENTIFIER_PREFIX###|${TEAM_IDENTIFIER}.|g" ${APP_NAME}.entitlements
  151. sed -i '' "s|###TEAM_IDENTIFIER###|${TEAM_IDENTIFIER}|g" ${APP_NAME}.entitlements
  152. codesign --force --deep --entitlements ${APP_NAME}.entitlements -o runtime -s ${CODESIGN_IDENTITY} ${APP_NAME}.app
  153. fi
  154. # prepare dmg contents
  155. mkdir dmg
  156. mv ${APP_NAME}.app dmg
  157. cp resources/${FUSE_LIB}.webloc dmg
  158. # create dmg
  159. create-dmg \
  160. --volname ${APP_NAME} \
  161. --volicon "resources/${APP_NAME}-Volume.icns" \
  162. --background "resources/${APP_NAME}-${FUSE_LIB}-background.tiff" \
  163. --window-pos 400 100 \
  164. --window-size 640 694 \
  165. --icon-size 128 \
  166. --icon "${APP_NAME}.app" 128 245 \
  167. --hide-extension "${APP_NAME}.app" \
  168. --icon "${FUSE_LIB}.webloc" 320 501 \
  169. --hide-extension "${FUSE_LIB}.webloc" \
  170. --app-drop-link 512 245 \
  171. --eula "resources/license.rtf" \
  172. --icon ".background" 128 758 \
  173. --icon ".VolumeIcon.icns" 512 758 \
  174. ${APP_NAME}-${VERSION_NO}.dmg dmg