03_package_obs.sh 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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() {
  12. if [ "${CODESIGN}" ]; then
  13. read_codesign_ident
  14. fi
  15. status "Create macOS disk image"
  16. trap "caught_error 'package app'" ERR
  17. info "/!\\ CPack will use an AppleScript to create the disk image, this will lead to a Finder window opening to adjust window settings. /!\\"
  18. ensure_dir "${CHECKOUT_DIR}"
  19. step "Package OBS..."
  20. cmake --build ${BUILD_DIR} -t package
  21. DMG_NAME=$(/usr/bin/find "${BUILD_DIR}" -type f -name "OBS-*.dmg" -depth 1 | sort -rn | head -1)
  22. if [ "${DMG_NAME}" ]; then
  23. mv "${DMG_NAME}" "${BUILD_DIR}/${FILE_NAME}"
  24. step "Codesign OBS disk image..."
  25. /usr/bin/codesign --force --sign "${CODESIGN_IDENT:--}" "${BUILD_DIR}/${FILE_NAME}"
  26. else
  27. error "ERROR No suitable OBS disk image generated"
  28. fi
  29. }
  30. notarize_obs() {
  31. status "Notarize OBS"
  32. trap "caught_error 'notarizing app'" ERR
  33. if ! exists brew; then
  34. error "ERROR Homebrew not found - please install homebrew (https://brew.sh)"
  35. exit 1
  36. fi
  37. ensure_dir "${CHECKOUT_DIR}"
  38. if [ "${NOTARIZE_IMAGE}" ]; then
  39. trap "_caught_error_hdiutil_verify '${NOTARIZE_IMAGE}'" ERR
  40. step "Verify OBS disk image ${NOTARIZE_IMAGE}..."
  41. hdiutil verify "${NOTARIZE_IMAGE}"
  42. NOTARIZE_TARGET="${NOTARIZE_IMAGE}"
  43. elif [ "${NOTARIZE_BUNDLE}" ]; then
  44. NOTARIZE_TARGET="${NOTARIZE_BUNDLE}"
  45. else
  46. OBS_IMAGE="${BUILD_DIR}/${FILE_NAME}"
  47. if [ -f "${OBS_IMAGE}" ]; then
  48. NOTARIZE_TARGET="${OBS_IMAGE}"
  49. else
  50. error "No notarization application bundle ('OBS.app') or disk image ('${NOTARIZE_IMAGE:-${FILE_NAME}}') found"
  51. return
  52. fi
  53. fi
  54. if [ "$?" -eq 0 ]; then
  55. read_codesign_ident
  56. read_codesign_pass
  57. step "Notarize ${NOTARIZE_TARGET}..."
  58. /usr/bin/xcrun notarytool submit "${NOTARIZE_TARGET}" --keychain-profile "OBS-Codesign-Password" --wait
  59. step "Staple the ticket to ${NOTARIZE_TARGET}..."
  60. /usr/bin/xcrun stapler staple "${NOTARIZE_TARGET}"
  61. fi
  62. }
  63. _caught_error_hdiutil_verify() {
  64. error "ERROR during verifying image '${1}'"
  65. cleanup
  66. exit 1
  67. }
  68. package-obs-standalone() {
  69. PRODUCT_NAME="OBS-Studio"
  70. CHECKOUT_DIR="$(/usr/bin/git rev-parse --show-toplevel)"
  71. DEPS_BUILD_DIR="${CHECKOUT_DIR}/../obs-build-dependencies"
  72. source "${CHECKOUT_DIR}/CI/include/build_support.sh"
  73. source "${CHECKOUT_DIR}/CI/include/build_support_macos.sh"
  74. check_archs
  75. check_macos_version
  76. if [ -z "${CI}" ]; then
  77. step "Fetch OBS tags..."
  78. /usr/bin/git fetch --tags origin
  79. fi
  80. GIT_BRANCH=$(/usr/bin/git rev-parse --abbrev-ref HEAD)
  81. GIT_HASH=$(/usr/bin/git rev-parse --short=9 HEAD)
  82. GIT_TAG=$(/usr/bin/git describe --tags --abbrev=0)
  83. if [ "${BUILD_FOR_DISTRIBUTION}" ]; then
  84. VERSION_STRING="${GIT_TAG}"
  85. else
  86. VERSION_STRING="${GIT_TAG}-${GIT_HASH}"
  87. fi
  88. if [ -z "${NOTARIZE_IMAGE}" -a -z "${NOTARIZE_BUNDLE}" ]; then
  89. if [ "${ARCH}" = "arm64" ]; then
  90. FILE_NAME="obs-studio-${VERSION_STRING}-macos-arm64.dmg"
  91. elif [ "${ARCH}" = "universal" ]; then
  92. FILE_NAME="obs-studio-${VERSION_STRING}-macos.dmg"
  93. else
  94. FILE_NAME="obs-studio-${VERSION_STRING}-macos-x86_64.dmg"
  95. fi
  96. package_obs
  97. fi
  98. if [ "${NOTARIZE}" ]; then
  99. notarize_obs
  100. fi
  101. }
  102. print_usage() {
  103. echo -e "Usage: ${0}\n" \
  104. "-h, --help : Print this help\n" \
  105. "-q, --quiet : Suppress most build process output\n" \
  106. "-v, --verbose : Enable more verbose build process output\n" \
  107. "-a, --architecture : Specify build architecture (default: x86_64, alternative: arm64)\n" \
  108. "-c, --codesign : Codesign OBS and all libraries (default: ad-hoc only)\n" \
  109. "-n, --notarize : Notarize OBS (default: off)\n" \
  110. "--notarize-image [IMAGE] : Specify existing OBS disk image for notarization\n" \
  111. "--notarize-bundle [BUNDLE] : Specify existing OBS application bundle for notarization\n" \
  112. "--build-dir : Specify alternative build directory (default: build)\n"
  113. }
  114. package-obs-main() {
  115. if [ -z "${_RUN_OBS_BUILD_SCRIPT}" ]; then
  116. while true; do
  117. case "${1}" in
  118. -h | --help ) print_usage; exit 0 ;;
  119. -q | --quiet ) export QUIET=TRUE; shift ;;
  120. -v | --verbose ) export VERBOSE=TRUE; shift ;;
  121. -a | --architecture ) ARCH="${2}"; shift 2 ;;
  122. -c | --codesign ) CODESIGN=TRUE; shift ;;
  123. -n | --notarize ) NOTARIZE=TRUE; CODESIGN=TRUE; shift ;;
  124. --build-dir ) BUILD_DIR="${2}"; shift 2 ;;
  125. --notarize-image ) NOTARIZE_IMAGE="${2}"; NOTARIZE=TRUE; CODESIGN=TRUE; shift 2 ;;
  126. --notarize-bundle ) NOTARIZE_BUNDLE="${2}"; NOTARIZE=TRUE; CODESIGN=TRUE; shift 2 ;;
  127. -- ) shift; break ;;
  128. * ) break ;;
  129. esac
  130. done
  131. package-obs-standalone
  132. fi
  133. }
  134. package-obs-main $*