build.sh 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #!/bin/bash
  2. # parse options
  3. usage() { echo "Usage: $0 [-s <codesign-identity>]" 1>&2; exit 1; }
  4. while getopts ":s:" o; do
  5. case "${o}" in
  6. s)
  7. CODESIGN_IDENTITY=${OPTARG}
  8. ;;
  9. *)
  10. usage
  11. ;;
  12. esac
  13. done
  14. shift "$((OPTIND-1))"
  15. # prepare working dir and variables
  16. cd $(dirname $0)
  17. rm -rf runtime *.app
  18. REVISION_NO=`git rev-list --count HEAD`
  19. VERSION_NO=`mvn -f../../../pom.xml help:evaluate -Dexpression=project.version -q -DforceStdout | sed -rn 's/.*([0-9]+\.[0-9]+\.[0-9]+).*/\1/p'`
  20. # check preconditions
  21. if [ -z "${JAVA_HOME}" ]; then echo "JAVA_HOME not set. Run using JAVA_HOME=/path/to/jdk ./build.sh"; exit 1; fi
  22. command -v mvn >/dev/null 2>&1 || { echo >&2 "mvn not found."; exit 1; }
  23. if [ -n "${CODESIGN_IDENTITY}" ]; then
  24. command -v codesign >/dev/null 2>&1 || { echo >&2 "codesign not found. Fix by 'xcode-select --install'."; exit 1; }
  25. if [[ ! `security find-identity -v -p codesigning | grep -w "${CODESIGN_IDENTITY}"` ]]; then echo "Given codesign identity is invalid."; exit 1; fi
  26. fi
  27. # compile
  28. mvn -B -f../../../pom.xml clean package -DskipTests -Pmac
  29. cp ../../../target/cryptomator-*.jar ../../../target/mods
  30. # add runtime
  31. ${JAVA_HOME}/bin/jlink \
  32. --output runtime \
  33. --module-path "${JAVA_HOME}/jmods" \
  34. --add-modules java.base,java.desktop,java.logging,java.naming,java.net.http,java.scripting,java.sql,java.xml,jdk.unsupported,jdk.crypto.ec,jdk.accessibility \
  35. --no-header-files \
  36. --no-man-pages \
  37. --strip-debug \
  38. --compress=1
  39. # create app dir
  40. ${JAVA_HOME}/bin/jpackage \
  41. --verbose \
  42. --type app-image \
  43. --runtime-image runtime \
  44. --input ../../../target/libs \
  45. --module-path ../../../target/mods \
  46. --module org.cryptomator.desktop/org.cryptomator.launcher.Cryptomator \
  47. --dest . \
  48. --name Cryptomator \
  49. --vendor "Skymatic GmbH" \
  50. --copyright "(C) 2016 - 2021 Skymatic GmbH" \
  51. --java-options "-Xss5m" \
  52. --java-options "-Xmx256m" \
  53. --java-options "-Dcryptomator.appVersion=\"${VERSION_NO}\"" \
  54. --app-version "${VERSION_NO}" \
  55. --java-options "-Dfile.encoding=\"utf-8\"" \
  56. --java-options "-Dcryptomator.logDir=\"~/Library/Logs/Cryptomator\"" \
  57. --java-options "-Dcryptomator.pluginDir=\"~/Library/Application Support/Cryptomator/Plugins\"" \
  58. --java-options "-Dcryptomator.settingsPath=\"~/Library/Application Support/Cryptomator/settings.json\"" \
  59. --java-options "-Dcryptomator.ipcSocketPath=\"~/Library/Application Support/Cryptomator/ipc.socket\"" \
  60. --java-options "-Dcryptomator.showTrayIcon=true" \
  61. --java-options "-Dcryptomator.buildNumber=\"dmg-${REVISION_NO}\"" \
  62. --mac-package-identifier org.cryptomator \
  63. --resource-dir ../resources
  64. # transform app dir
  65. cp ../resources/Cryptomator-Vault.icns Cryptomator.app/Contents/Resources/
  66. sed -i '' "s|###BUNDLE_SHORT_VERSION_STRING###|${VERSION_NO}|g" Cryptomator.app/Contents/Info.plist
  67. sed -i '' "s|###BUNDLE_VERSION###|${REVISION_NO}|g" Cryptomator.app/Contents/Info.plist
  68. # codesign
  69. if [ -n "${CODESIGN_IDENTITY}" ]; then
  70. find Cryptomator.app/Contents/runtime/Contents/MacOS -name '*.dylib' -exec codesign --force -s ${CODESIGN_IDENTITY} {} \;
  71. for JAR_PATH in `find Cryptomator.app -name "*.jar"`; do
  72. if [[ `unzip -l ${JAR_PATH} | grep '.dylib\|.jnilib'` ]]; then
  73. JAR_FILENAME=$(basename ${JAR_PATH})
  74. OUTPUT_PATH=${JAR_PATH%.*}
  75. echo "Codesigning libs in ${JAR_FILENAME}..."
  76. unzip -q ${JAR_PATH} -d ${OUTPUT_PATH}
  77. find ${OUTPUT_PATH} -name '*.dylib' -exec codesign --force -s ${CODESIGN_IDENTITY} {} \;
  78. find ${OUTPUT_PATH} -name '*.jnilib' -exec codesign --force -s ${CODESIGN_IDENTITY} {} \;
  79. rm ${JAR_PATH}
  80. pushd ${OUTPUT_PATH} > /dev/null
  81. zip -qr ../${JAR_FILENAME} *
  82. popd > /dev/null
  83. rm -r ${OUTPUT_PATH}
  84. fi
  85. done
  86. echo "Codesigning Cryptomator.app..."
  87. codesign --force --deep --entitlements ../Cryptomator.entitlements -o runtime -s ${CODESIGN_IDENTITY} Cryptomator.app
  88. fi