03_package_obs.sh 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. if ! exists xcnotary; then
  38. step "Install notarization dependency 'xcnotary'"
  39. brew install akeru-inc/tap/xcnotary
  40. fi
  41. ensure_dir "${CHECKOUT_DIR}"
  42. if [ "${NOTARIZE_IMAGE}" ]; then
  43. trap "_caught_error_xcnotary '${NOTARIZE_IMAGE}'" ERR
  44. step "Attach OBS disk image ${NOTARIZE_IMAGE}..."
  45. hdiutil attach -readonly -noverify -noautoopen -quiet "${NOTARIZE_IMAGE}"
  46. VOLUME_NAME=$(hdiutil info -plist | grep "/Volumes/OBS-" | sed 's/<string>\/Volumes\/\([^<]*\)<\/string>/\1/' | sed -e 's/^[[:space:]]*//')
  47. PRECHECK="/Volumes/${VOLUME_NAME}/OBS.app"
  48. NOTARIZE_TARGET="${NOTARIZE_IMAGE}"
  49. elif [ "${NOTARIZE_BUNDLE}" ]; then
  50. PRECHECK="${NOTARIZE_BUNDLE}"
  51. NOTARIZE_TARGET="${NOTARIZE_BUNDLE}"
  52. else
  53. OBS_IMAGE="${BUILD_DIR}/${FILE_NAME}"
  54. if [ -f "${OBS_IMAGE}" ]; then
  55. OBS_BUNDLE=$(/usr/bin/find "${BUILD_DIR}/_CPack_Packages" -type d -name "OBS.app")
  56. PRECHECK="${OBS_BUNDLE}"
  57. NOTARIZE_TARGET="${OBS_IMAGE}"
  58. else
  59. error "No notarization application bundle ('OBS.app') or disk image ('${NOTARIZE_IMAGE:-${FILE_NAME}}') found"
  60. return
  61. fi
  62. fi
  63. step "Run notarization pre-checks on OBS.app..."
  64. xcnotary precheck "${PRECHECK}"
  65. if [ "$?" -eq 0 ]; then
  66. read_codesign_ident
  67. read_codesign_pass
  68. step "Run xcnotary with ${NOTARIZE_TARGET}..."
  69. xcnotary notarize "${NOTARIZE_TARGET}" --developer-account "${CODESIGN_IDENT_USER}" --developer-password-keychain-item "OBS-Codesign-Password" --provider "${CODESIGN_IDENT_SHORT}"
  70. fi
  71. if [ "${NOTARIZE_IMAGE}" -a -d "/Volumes/${VOLUME_NAME}" ]; then
  72. step "Detach OBS disk image ${NOTARIZE_IMAGE}..."
  73. hdiutil detach "/Volumes/${VOLUME_NAME}" -quiet
  74. fi
  75. }
  76. _caught_error_xcnotary() {
  77. error "ERROR during notarization of image '${1}'"
  78. if [ -d "/Volumes/${1}" ]; then
  79. step "Detach OBS disk image ${1}..."
  80. hdiutil detach "/Volumes/${1}" -quiet
  81. fi
  82. cleanup
  83. exit 1
  84. }
  85. package-obs-standalone() {
  86. PRODUCT_NAME="OBS-Studio"
  87. CHECKOUT_DIR="$(/usr/bin/git rev-parse --show-toplevel)"
  88. DEPS_BUILD_DIR="${CHECKOUT_DIR}/../obs-build-dependencies"
  89. source "${CHECKOUT_DIR}/CI/include/build_support.sh"
  90. source "${CHECKOUT_DIR}/CI/include/build_support_macos.sh"
  91. check_archs
  92. check_macos_version
  93. step "Fetch OBS tags..."
  94. /usr/bin/git fetch origin --tags
  95. GIT_BRANCH=$(/usr/bin/git rev-parse --abbrev-ref HEAD)
  96. GIT_HASH=$(/usr/bin/git rev-parse --short HEAD)
  97. GIT_TAG=$(/usr/bin/git describe --tags --abbrev=0)
  98. if [ "${BUILD_FOR_DISTRIBUTION}" ]; then
  99. VERSION_STRING="${GIT_TAG}"
  100. else
  101. VERSION_STRING="${GIT_TAG}-${GIT_HASH}"
  102. fi
  103. if [ -z "${NOTARIZE_IMAGE}" -a -z "${NOTARIZE_BUNDLE}" ]; then
  104. if [ "${ARCH}" = "arm64" ]; then
  105. FILE_NAME="obs-studio-${VERSION_STRING}-macOS-Apple.dmg"
  106. elif [ "${ARCH}" = "universal" ]; then
  107. FILE_NAME="obs-studio-${VERSION_STRING}-macOS.dmg"
  108. else
  109. FILE_NAME="obs-studio-${VERSION_STRING}-macOS-Intel.dmg"
  110. fi
  111. package_obs
  112. fi
  113. if [ "${NOTARIZE}" ]; then
  114. notarize_obs
  115. fi
  116. }
  117. print_usage() {
  118. echo -e "Usage: ${0}\n" \
  119. "-h, --help : Print this help\n" \
  120. "-q, --quiet : Suppress most build process output\n" \
  121. "-v, --verbose : Enable more verbose build process output\n" \
  122. "-a, --architecture : Specify build architecture (default: x86_64, alternative: arm64)\n" \
  123. "-c, --codesign : Codesign OBS and all libraries (default: ad-hoc only)\n" \
  124. "-n, --notarize : Notarize OBS (default: off)\n" \
  125. "--notarize-image [IMAGE] : Specify existing OBS disk image for notarization\n" \
  126. "--notarize-bundle [BUNDLE] : Specify existing OBS application bundle for notarization\n" \
  127. "--build-dir : Specify alternative build directory (default: build)\n"
  128. }
  129. package-obs-main() {
  130. if [ -z "${_RUN_OBS_BUILD_SCRIPT}" ]; then
  131. while true; do
  132. case "${1}" in
  133. -h | --help ) print_usage; exit 0 ;;
  134. -q | --quiet ) export QUIET=TRUE; shift ;;
  135. -v | --verbose ) export VERBOSE=TRUE; shift ;;
  136. -a | --architecture ) ARCH="${2}"; shift 2 ;;
  137. -c | --codesign ) CODESIGN=TRUE; shift ;;
  138. -n | --notarize ) NOTARIZE=TRUE; CODESIGN=TRUE; shift ;;
  139. --build-dir ) BUILD_DIR="${2}"; shift 2 ;;
  140. --notarize-image ) NOTARIZE_IMAGE="${2}"; NOTARIZE=TRUE; CODESIGN=TRUE; shift 2 ;;
  141. --notarize-bundle ) NOTARIZE_BUNDLE="${2}"; NOTARIZE=TRUE; CODESIGN=TRUE; shift 2 ;;
  142. -- ) shift; break ;;
  143. * ) break ;;
  144. esac
  145. done
  146. package-obs-standalone
  147. fi
  148. }
  149. package-obs-main $*