build.sh 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 dmg
  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. command -v create-dmg >/dev/null 2>&1 || { echo >&2 "create-dmg not found."; exit 1; }
  24. if [ -n "${CODESIGN_IDENTITY}" ]; then
  25. command -v codesign >/dev/null 2>&1 || { echo >&2 "codesign not found. Fix by 'xcode-select --install'."; exit 1; }
  26. if [[ ! `security find-identity -v -p codesigning | grep -w "${CODESIGN_IDENTITY}"` ]]; then echo "Given codesign identity is invalid."; exit 1; fi
  27. fi
  28. # compile
  29. mvn -B -f../../../pom.xml clean package -DskipTests -Pmac
  30. cp ../../../target/cryptomator-*.jar ../../../target/mods
  31. # add runtime
  32. ${JAVA_HOME}/bin/jlink \
  33. --output runtime \
  34. --module-path "${JAVA_HOME}/jmods" \
  35. --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 \
  36. --no-header-files \
  37. --no-man-pages \
  38. --strip-debug \
  39. --compress=1
  40. # create app dir
  41. ${JAVA_HOME}/bin/jpackage \
  42. --verbose \
  43. --type app-image \
  44. --runtime-image runtime \
  45. --input ../../../target/libs \
  46. --module-path ../../../target/mods \
  47. --module org.cryptomator.desktop/org.cryptomator.launcher.Cryptomator \
  48. --dest . \
  49. --name Cryptomator \
  50. --vendor "Skymatic GmbH" \
  51. --copyright "(C) 2016 - 2022 Skymatic GmbH" \
  52. --java-options "-Xss5m" \
  53. --java-options "-Xmx256m" \
  54. --java-options "-Dcryptomator.appVersion=\"${VERSION_NO}\"" \
  55. --app-version "${VERSION_NO}" \
  56. --java-options "-Dfile.encoding=\"utf-8\"" \
  57. --java-options "-Dapple.awt.enableTemplateImages=true" \
  58. --java-options "-Dcryptomator.logDir=\"~/Library/Logs/Cryptomator\"" \
  59. --java-options "-Dcryptomator.pluginDir=\"~/Library/Application Support/Cryptomator/Plugins\"" \
  60. --java-options "-Dcryptomator.settingsPath=\"~/Library/Application Support/Cryptomator/settings.json\"" \
  61. --java-options "-Dcryptomator.ipcSocketPath=\"~/Library/Application Support/Cryptomator/ipc.socket\"" \
  62. --java-options "-Dcryptomator.showTrayIcon=true" \
  63. --java-options "-Dcryptomator.buildNumber=\"dmg-${REVISION_NO}\"" \
  64. --mac-package-identifier org.cryptomator \
  65. --resource-dir ../resources
  66. # transform app dir
  67. cp ../resources/Cryptomator-Vault.icns Cryptomator.app/Contents/Resources/
  68. sed -i '' "s|###BUNDLE_SHORT_VERSION_STRING###|${VERSION_NO}|g" Cryptomator.app/Contents/Info.plist
  69. sed -i '' "s|###BUNDLE_VERSION###|${REVISION_NO}|g" Cryptomator.app/Contents/Info.plist
  70. # codesign
  71. if [ -n "${CODESIGN_IDENTITY}" ]; then
  72. find Cryptomator.app/Contents/runtime/Contents/MacOS -name '*.dylib' -exec codesign --force -s ${CODESIGN_IDENTITY} {} \;
  73. for JAR_PATH in `find Cryptomator.app -name "*.jar"`; do
  74. if [[ `unzip -l ${JAR_PATH} | grep '.dylib\|.jnilib'` ]]; then
  75. JAR_FILENAME=$(basename ${JAR_PATH})
  76. OUTPUT_PATH=${JAR_PATH%.*}
  77. echo "Codesigning libs in ${JAR_FILENAME}..."
  78. unzip -q ${JAR_PATH} -d ${OUTPUT_PATH}
  79. find ${OUTPUT_PATH} -name '*.dylib' -exec codesign --force -s ${CODESIGN_IDENTITY} {} \;
  80. find ${OUTPUT_PATH} -name '*.jnilib' -exec codesign --force -s ${CODESIGN_IDENTITY} {} \;
  81. rm ${JAR_PATH}
  82. pushd ${OUTPUT_PATH} > /dev/null
  83. zip -qr ../${JAR_FILENAME} *
  84. popd > /dev/null
  85. rm -r ${OUTPUT_PATH}
  86. fi
  87. done
  88. echo "Codesigning Cryptomator.app..."
  89. codesign --force --deep --entitlements ../Cryptomator.entitlements -o runtime -s ${CODESIGN_IDENTITY} Cryptomator.app
  90. fi
  91. # prepare dmg contents
  92. mkdir dmg
  93. mv Cryptomator.app dmg
  94. cp resources/macFUSE.webloc dmg
  95. # create dmg
  96. create-dmg \
  97. --volname Cryptomator \
  98. --volicon "resources/Cryptomator-Volume.icns" \
  99. --background "resources/Cryptomator-background.tiff" \
  100. --window-pos 400 100 \
  101. --window-size 640 694 \
  102. --icon-size 128 \
  103. --icon "Cryptomator.app" 128 245 \
  104. --hide-extension "Cryptomator.app" \
  105. --icon "macFUSE.webloc" 320 501 \
  106. --hide-extension "macFUSE.webloc" \
  107. --app-drop-link 512 245 \
  108. --eula "resources/license.rtf" \
  109. --icon ".background" 128 758 \
  110. --icon ".fseventsd" 320 758 \
  111. --icon ".VolumeIcon.icns" 512 758 \
  112. Cryptomator-${VERSION_NO}.dmg dmg