build.sh 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. --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. # generate license
  71. mvn -B -f../../../pom.xml license:add-third-party \
  72. -Dlicense.thirdPartyFilename=license.rtf \
  73. -Dlicense.outputDirectory=resources
  74. -Dlicense.fileTemplate=resources/licenseTemplate.ftl \
  75. -Dlicense.includeScopes=compile \
  76. -Dlicense.excludedGroups=^org\.cryptomator \
  77. -Dlicense.failOnMissing=true \
  78. -Dlicense.licenseMergesUrl=file:///../../../license/merges
  79. # codesign
  80. if [ -n "${CODESIGN_IDENTITY}" ]; then
  81. find Cryptomator.app/Contents/runtime/Contents/MacOS -name '*.dylib' -exec codesign --force -s ${CODESIGN_IDENTITY} {} \;
  82. for JAR_PATH in `find Cryptomator.app -name "*.jar"`; do
  83. if [[ `unzip -l ${JAR_PATH} | grep '.dylib\|.jnilib'` ]]; then
  84. JAR_FILENAME=$(basename ${JAR_PATH})
  85. OUTPUT_PATH=${JAR_PATH%.*}
  86. echo "Codesigning libs in ${JAR_FILENAME}..."
  87. unzip -q ${JAR_PATH} -d ${OUTPUT_PATH}
  88. find ${OUTPUT_PATH} -name '*.dylib' -exec codesign --force -s ${CODESIGN_IDENTITY} {} \;
  89. find ${OUTPUT_PATH} -name '*.jnilib' -exec codesign --force -s ${CODESIGN_IDENTITY} {} \;
  90. rm ${JAR_PATH}
  91. pushd ${OUTPUT_PATH} > /dev/null
  92. zip -qr ../${JAR_FILENAME} *
  93. popd > /dev/null
  94. rm -r ${OUTPUT_PATH}
  95. fi
  96. done
  97. echo "Codesigning Cryptomator.app..."
  98. codesign --force --deep --entitlements ../Cryptomator.entitlements -o runtime -s ${CODESIGN_IDENTITY} Cryptomator.app
  99. fi
  100. # prepare dmg contents
  101. mkdir dmg
  102. mv Cryptomator.app dmg
  103. cp resources/macFUSE.webloc dmg
  104. # create dmg
  105. create-dmg \
  106. --volname Cryptomator \
  107. --volicon "resources/Cryptomator-Volume.icns" \
  108. --background "resources/Cryptomator-background.tiff" \
  109. --window-pos 400 100 \
  110. --window-size 640 694 \
  111. --icon-size 128 \
  112. --icon "Cryptomator.app" 128 245 \
  113. --hide-extension "Cryptomator.app" \
  114. --icon "macFUSE.webloc" 320 501 \
  115. --hide-extension "macFUSE.webloc" \
  116. --app-drop-link 512 245 \
  117. --eula "resources/license.rtf" \
  118. --icon ".background" 128 758 \
  119. --icon ".fseventsd" 320 758 \
  120. --icon ".VolumeIcon.icns" 512 758 \
  121. Cryptomator-${VERSION_NO}.dmg dmg