build.sh 4.9 KB

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