04_package_plugin.sh 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. #!/bin/bash
  2. ##############################################################################
  3. # macOS libobs plugin package function
  4. ##############################################################################
  5. #
  6. # This script file can be included in build scripts for macOS or run directly
  7. #
  8. ##############################################################################
  9. # Halt on errors
  10. set -eE
  11. package_obs_plugin() {
  12. if [ "${CODESIGN}" ]; then
  13. read_codesign_ident
  14. fi
  15. status "Package OBS plugin ${PRODUCT_NAME}"
  16. trap "caught_error 'package_obs_plugin'" ERR
  17. ensure_dir "${CHECKOUT_DIR}"
  18. if [ -d "${BUILD_DIR}/rundir/${PRODUCT_NAME}.plugin" ]; then
  19. rm -rf "${BUILD_DIR}/rundir/${PRODUCT_NAME}.plugin"
  20. fi
  21. cmake --install ${BUILD_DIR}
  22. if ! type packagesbuild &>/dev/null; then
  23. status "Setting up dependency Packages.app"
  24. step "Download..."
  25. check_and_fetch "http://s.sudre.free.fr/Software/files/Packages.dmg" "70ac111417728c17b1f27d5520afd87c33f899f12de8ace0f703e3e1c500b28e"
  26. step "Mount disk image..."
  27. hdiutil attach -noverify Packages.dmg
  28. step "Install Packages.app"
  29. PACKAGES_VOLUME=$(hdiutil info -plist | grep "/Volumes/Packages" | sed 's/<string>\/Volumes\/\([^<]*\)<\/string>/\1/' | sed -e 's/^[[:space:]]*//')
  30. sudo installer -pkg "/Volumes/${PACKAGES_VOLUME}/packages/Packages.pkg" -target /
  31. hdiutil detach "/Volumes/${PACKAGES_VOLUME}"
  32. fi
  33. step "Package ${PRODUCT_NAME}..."
  34. packagesbuild ./bundle/installer-macOS.generated.pkgproj
  35. step "Codesigning installer package..."
  36. read_codesign_ident_installer
  37. /usr/bin/productsign --sign "${CODESIGN_IDENT_INSTALLER}" "${BUILD_DIR}/${PRODUCT_NAME}.pkg" "${FILE_NAME}"
  38. }
  39. notarize_obs_plugin() {
  40. status "Notarize ${PRODUCT_NAME}"
  41. trap "caught_error 'notarize_obs_plugin'" ERR
  42. if ! exists brew; then
  43. error "Homebrew not found - please install homebrew (https://brew.sh)"
  44. exit 1
  45. fi
  46. if ! exists xcnotary; then
  47. step "Install notarization dependency 'xcnotary'"
  48. brew install akeru-inc/tap/xcnotary
  49. fi
  50. ensure_dir "${CHECKOUT_DIR}"
  51. if [ -f "${FILE_NAME}" ]; then
  52. xcnotary precheck "${FILE_NAME}"
  53. else
  54. error "No notarization package installer ('${FILE_NAME}') found"
  55. return
  56. fi
  57. if [ "$?" -eq 0 ]; then
  58. read_codesign_ident_installer
  59. read_codesign_pass
  60. step "Run xcnotary with ${FILE_NAME}..."
  61. xcnotary notarize "${FILE_NAME}" --developer-account "${CODESIGN_IDENT_USER}" --developer-password-keychain-item "OBS-Codesign-Password" --provider "${CODESIGN_IDENT_SHORT}"
  62. fi
  63. }
  64. package-plugin-standalone() {
  65. CHECKOUT_DIR="$(/usr/bin/git rev-parse --show-toplevel)"
  66. ensure_dir "${CHECKOUT_DIR}"
  67. if [ -f "${CHECKOUT_DIR}/CI/include/build_environment.sh" ]; then
  68. source "${CHECKOUT_DIR}/CI/include/build_environment.sh"
  69. fi
  70. PRODUCT_NAME="${PRODUCT_NAME:-obs-plugin}"
  71. source "${CHECKOUT_DIR}/CI/include/build_support.sh"
  72. source "${CHECKOUT_DIR}/CI/include/build_support_macos.sh"
  73. GIT_BRANCH=$(/usr/bin/git rev-parse --abbrev-ref HEAD)
  74. GIT_HASH=$(/usr/bin/git rev-parse --short HEAD)
  75. GIT_TAG=$(/usr/bin/git describe --tags --abbrev=0 2&>/dev/null || true)
  76. check_macos_version
  77. check_archs
  78. if [ "${ARCH}" = "arm64" ]; then
  79. FILE_NAME="${PRODUCT_NAME}-${GIT_TAG:-${PRODUCT_VERSION}}-${GIT_HASH}-macOS-Apple.pkg"
  80. elif [ "${ARCH}" = "x86_64" ]; then
  81. FILE_NAME="${PRODUCT_NAME}-${GIT_TAG:-${PRODUCT_VERSION}}-${GIT_HASH}-macOS-Intel.pkg"
  82. else
  83. FILE_NAME="${PRODUCT_NAME}-${GIT_TAG:-${PRODUCT_VERSION}}-${GIT_HASH}-macOS-Universal.pkg"
  84. fi
  85. check_curl
  86. package_obs_plugin
  87. if [ "${NOTARIZE}" ]; then
  88. notarize_obs_plugin
  89. fi
  90. }
  91. print_usage() {
  92. echo -e "Usage: ${0}\n" \
  93. "-h, --help : Print this help\n" \
  94. "-q, --quiet : Suppress most build process output\n" \
  95. "-v, --verbose : Enable more verbose build process output\n" \
  96. "-a, --architecture : Specify build architecture (default: x86_64, alternative: arm64)\n" \
  97. "-c, --codesign : Codesign OBS and all libraries (default: ad-hoc only)\n" \
  98. "-n, --notarize : Notarize OBS (default: off)\n" \
  99. "--build-dir : Specify alternative build directory (default: build)\n"
  100. }
  101. package-plugin-main() {
  102. if [ -z "${_RUN_OBS_BUILD_SCRIPT}" ]; then
  103. while true; do
  104. case "${1}" in
  105. -h | --help ) print_usage; exit 0 ;;
  106. -q | --quiet ) export QUIET=TRUE; shift ;;
  107. -v | --verbose ) export VERBOSE=TRUE; shift ;;
  108. -a | --architecture ) ARCH="${2}"; shift 2 ;;
  109. -c | --codesign ) CODESIGN=TRUE; shift ;;
  110. -n | --notarize ) NOTARIZE=TRUE; CODESIGN=TRUE; shift ;;
  111. -s | --standalone ) STANDALONE=TRUE; shift ;;
  112. --build-dir ) BUILD_DIR="${2}"; shift 2 ;;
  113. -- ) shift; break ;;
  114. * ) break ;;
  115. esac
  116. done
  117. package-plugin-standalone
  118. fi
  119. }
  120. package-plugin-main $*