03_package_obs.sh 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. ensure_dir "${CHECKOUT_DIR}"
  18. step "Package OBS..."
  19. BUILD_DIR="build_${ARCH}"
  20. root_dir="$(pwd)"
  21. pushd "${BUILD_DIR}" > /dev/null > /dev/null
  22. mkdir -p "${FILE_NAME//.dmg/}/.background"
  23. cp "${root_dir}/cmake/macos/resources/background.tiff" "${FILE_NAME//.dmg/}/.background/"
  24. cp "${root_dir}/cmake/macos/resources/AppIcon.icns" "${FILE_NAME//.dmg/}/.VolumeIcon.icns"
  25. ln -s /Applications "${FILE_NAME//.dmg/}/Applications"
  26. mkdir -p "${FILE_NAME//.dmg/}/OBS.app"
  27. ditto OBS.app "${FILE_NAME//.dmg/}/OBS.app"
  28. hdiutil create -volname "${FILE_NAME//.dmg/}" -srcfolder "${FILE_NAME//.dmg/}" -ov -fs APFS -format UDRW temp.dmg
  29. hdiutil attach -noverify -readwrite temp.dmg
  30. osascript package.applescript "${FILE_NAME//.dmg/}"
  31. hdiutil detach "/Volumes/${FILE_NAME//.dmg/}"
  32. hdiutil convert -format ULMO -o "${FILE_NAME}" temp.dmg
  33. rm temp.dmg
  34. step "Codesign OBS disk image..."
  35. /usr/bin/codesign --force --sign "${CODESIGN_IDENT:--}" "${FILE_NAME}"
  36. rm -rf "${FILE_NAME//.dmg/}"
  37. popd > /dev/null
  38. }
  39. notarize_obs() {
  40. status "Notarize OBS"
  41. trap "caught_error 'notarizing app'" ERR
  42. if ! exists brew; then
  43. error "ERROR Homebrew not found - please install homebrew (https://brew.sh)"
  44. exit 1
  45. fi
  46. ensure_dir "${CHECKOUT_DIR}"
  47. if [ "${NOTARIZE_IMAGE}" ]; then
  48. trap "_caught_error_hdiutil_verify '${NOTARIZE_IMAGE}'" ERR
  49. step "Verify OBS disk image ${NOTARIZE_IMAGE}..."
  50. hdiutil verify "${NOTARIZE_IMAGE}"
  51. NOTARIZE_TARGET="${NOTARIZE_IMAGE}"
  52. elif [ "${NOTARIZE_BUNDLE}" ]; then
  53. NOTARIZE_TARGET="${NOTARIZE_BUNDLE}"
  54. else
  55. OBS_IMAGE="${BUILD_DIR}/${FILE_NAME}"
  56. if [ -f "${OBS_IMAGE}" ]; then
  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. if [ "$?" -eq 0 ]; then
  64. read_codesign_ident
  65. read_codesign_pass
  66. step "Notarize ${NOTARIZE_TARGET}..."
  67. /usr/bin/xcrun notarytool submit "${NOTARIZE_TARGET}" --keychain-profile "OBS-Codesign-Password" --wait
  68. step "Staple the ticket to ${NOTARIZE_TARGET}..."
  69. /usr/bin/xcrun stapler staple "${NOTARIZE_TARGET}"
  70. fi
  71. }
  72. _caught_error_hdiutil_verify() {
  73. error "ERROR during verifying image '${1}'"
  74. cleanup
  75. exit 1
  76. }
  77. package-obs-standalone() {
  78. PRODUCT_NAME="OBS-Studio"
  79. CHECKOUT_DIR="$(/usr/bin/git rev-parse --show-toplevel)"
  80. DEPS_BUILD_DIR="${CHECKOUT_DIR}/../obs-build-dependencies"
  81. source "${CHECKOUT_DIR}/CI/include/build_support.sh"
  82. source "${CHECKOUT_DIR}/CI/include/build_support_macos.sh"
  83. check_archs
  84. check_macos_version
  85. if [ -z "${CI}" ]; then
  86. step "Fetch OBS tags..."
  87. /usr/bin/git fetch --tags origin
  88. fi
  89. GIT_BRANCH=$(/usr/bin/git rev-parse --abbrev-ref HEAD)
  90. GIT_HASH=$(/usr/bin/git rev-parse --short=9 HEAD)
  91. GIT_TAG=$(/usr/bin/git describe --tags --abbrev=0)
  92. if [ "${BUILD_FOR_DISTRIBUTION}" ]; then
  93. VERSION_STRING="${GIT_TAG}"
  94. else
  95. VERSION_STRING="${GIT_TAG}-${GIT_HASH}"
  96. fi
  97. if [ -z "${NOTARIZE_IMAGE}" -a -z "${NOTARIZE_BUNDLE}" ]; then
  98. if [ "${ARCH}" = "arm64" ]; then
  99. FILE_NAME="obs-studio-${VERSION_STRING}-macos-arm64.dmg"
  100. elif [ "${ARCH}" = "universal" ]; then
  101. FILE_NAME="obs-studio-${VERSION_STRING}-macos.dmg"
  102. else
  103. FILE_NAME="obs-studio-${VERSION_STRING}-macos-x86_64.dmg"
  104. fi
  105. package_obs
  106. fi
  107. if [ "${NOTARIZE}" ]; then
  108. notarize_obs
  109. fi
  110. }
  111. print_usage() {
  112. echo -e "Usage: ${0}\n" \
  113. "-h, --help : Print this help\n" \
  114. "-q, --quiet : Suppress most build process output\n" \
  115. "-v, --verbose : Enable more verbose build process output\n" \
  116. "-a, --architecture : Specify build architecture (default: x86_64, alternative: arm64)\n" \
  117. "-c, --codesign : Codesign OBS and all libraries (default: ad-hoc only)\n" \
  118. "-n, --notarize : Notarize OBS (default: off)\n" \
  119. "--notarize-image [IMAGE] : Specify existing OBS disk image for notarization\n" \
  120. "--notarize-bundle [BUNDLE] : Specify existing OBS application bundle for notarization\n" \
  121. "--build-dir : Specify alternative build directory (default: build)\n"
  122. }
  123. package-obs-main() {
  124. if [ -z "${_RUN_OBS_BUILD_SCRIPT}" ]; then
  125. while true; do
  126. case "${1}" in
  127. -h | --help ) print_usage; exit 0 ;;
  128. -q | --quiet ) export QUIET=TRUE; shift ;;
  129. -v | --verbose ) export VERBOSE=TRUE; shift ;;
  130. -a | --architecture ) ARCH="${2}"; shift 2 ;;
  131. -c | --codesign ) CODESIGN=TRUE; shift ;;
  132. -n | --notarize ) NOTARIZE=TRUE; CODESIGN=TRUE; shift ;;
  133. --build-dir ) BUILD_DIR="${2}"; shift 2 ;;
  134. --notarize-image ) NOTARIZE_IMAGE="${2}"; NOTARIZE=TRUE; CODESIGN=TRUE; shift 2 ;;
  135. --notarize-bundle ) NOTARIZE_BUNDLE="${2}"; NOTARIZE=TRUE; CODESIGN=TRUE; shift 2 ;;
  136. -- ) shift; break ;;
  137. * ) break ;;
  138. esac
  139. done
  140. package-obs-standalone
  141. fi
  142. }
  143. package-obs-main $*