build 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. #!/usr/bin/env bash
  2. # build - build Jellyfin binaries or packages
  3. set -o errexit
  4. set -o pipefail
  5. # The list of possible package actions (except 'clean')
  6. declare -a actions=( 'build' 'package' 'sign' 'publish' )
  7. # The list of possible platforms, based on directories under 'deployment/'
  8. declare -a platforms=( $(
  9. find deployment/ -maxdepth 1 -mindepth 1 -type d -exec basename {} \; | sort
  10. ) )
  11. # The list of standard dependencies required by all build scripts; individual
  12. # action scripts may specify their own dependencies
  13. declare -a dependencies=( 'tar' 'zip' )
  14. usage() {
  15. echo -e "build - build Jellyfin binaries or packages"
  16. echo -e ""
  17. echo -e "Usage:"
  18. echo -e " $ build --list-platforms"
  19. echo -e " $ build --list-actions <platform>"
  20. echo -e " $ build [-b/--web-branch <web_branch>] <platform> <action>"
  21. echo -e ""
  22. echo -e "The web_branch defaults to the same branch name as the current main branch."
  23. echo -e "To build all platforms, use 'all'."
  24. echo -e "To perform all build actions, use 'all'."
  25. echo -e "Build output files are collected at '../jellyfin-build/<platform>'."
  26. }
  27. # Show usage on stderr with exit 1 on argless
  28. if [[ -z $1 ]]; then
  29. usage >&2
  30. exit 1
  31. fi
  32. # Show usage if -h or --help are specified in the args
  33. if [[ $@ =~ '-h' || $@ =~ '--help' ]]; then
  34. usage
  35. exit 0
  36. fi
  37. # List all available platforms then exit
  38. if [[ $1 == '--list-platforms' ]]; then
  39. echo -e "Available platforms:"
  40. for platform in ${platforms[@]}; do
  41. echo -e " ${platform}"
  42. done
  43. exit 0
  44. fi
  45. # List all available actions for a given platform then exit
  46. if [[ $1 == '--list-actions' ]]; then
  47. platform="$2"
  48. if [[ ! " ${platforms[@]} " =~ " ${platform} " ]]; then
  49. echo "ERROR: Platform ${platform} does not exist."
  50. exit 1
  51. fi
  52. echo -e "Available actions for platform ${platform}:"
  53. for action in ${actions[@]}; do
  54. if [[ -f deployment/${platform}/${action}.sh ]]; then
  55. echo -e " ${action}"
  56. fi
  57. done
  58. exit 0
  59. fi
  60. # Parse branch option
  61. if [[ $1 == '-b' || $1 == '--web-branch' ]]; then
  62. web_branch="$2"
  63. shift 2
  64. else
  65. web_branch="$( git branch 2>/dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/' )"
  66. fi
  67. # Parse platform option
  68. if [[ -n $1 ]]; then
  69. cli_platform="$1"
  70. shift
  71. else
  72. echo "ERROR: A platform must be specified. Use 'all' to specify all platforms."
  73. exit 1
  74. fi
  75. if [[ ${cli_platform} == 'all' ]]; then
  76. declare -a platform=( ${platforms[@]} )
  77. else
  78. if [[ ! " ${platforms[@]} " =~ " ${cli_platform} " ]]; then
  79. echo "ERROR: Platform ${cli_platform} is invalid. Use the '--list-platforms' option to list available platforms."
  80. exit 1
  81. else
  82. declare -a platform=( "${cli_platform}" )
  83. fi
  84. fi
  85. # Parse action option
  86. if [[ -n $1 ]]; then
  87. cli_action="$1"
  88. shift
  89. else
  90. echo "ERROR: An action must be specified. Use 'all' to specify all actions."
  91. exit 1
  92. fi
  93. if [[ ${cli_action} == 'all' ]]; then
  94. declare -a action=( ${actions[@]} )
  95. else
  96. if [[ ! " ${actions[@]} " =~ " ${cli_action} " ]]; then
  97. echo "ERROR: Action ${cli_action} is invalid. Use the '--list-actions <platform>' option to list available actions."
  98. exit 1
  99. else
  100. declare -a action=( "${cli_action}" )
  101. fi
  102. fi
  103. # Verify required utilities are installed
  104. missing_deps=()
  105. for utility in ${dependencies[@]}; do
  106. if ! which ${utility} &>/dev/null; then
  107. missing_deps+=( ${utility} )
  108. fi
  109. done
  110. # Error if we're missing anything
  111. if [[ ${#missing_deps[@]} -gt 0 ]]; then
  112. echo -e "ERROR: This script requires the following missing utilities:"
  113. for utility in ${missing_deps[@]}; do
  114. echo -e " ${utility}"
  115. done
  116. exit 1
  117. fi
  118. # Parse platform-specific dependencies
  119. for target_platform in ${platform[@]}; do
  120. # Read platform-specific dependencies
  121. if [[ -f deployment/${target_platform}/dependencies.txt ]]; then
  122. platform_dependencies="$( grep -v '^#' deployment/${target_platform}/dependencies.txt )"
  123. # Verify required utilities are installed
  124. missing_deps=()
  125. for utility in ${platform_dependencies[@]}; do
  126. if ! which ${utility} &>/dev/null; then
  127. missing_deps+=( ${utility} )
  128. fi
  129. done
  130. # Error if we're missing anything
  131. if [[ ${#missing_deps[@]} -gt 0 ]]; then
  132. echo -e "ERROR: The ${target_platform} platform requires the following utilities:"
  133. for utility in ${missing_deps[@]}; do
  134. echo -e " ${utility}"
  135. done
  136. exit 1
  137. fi
  138. fi
  139. done
  140. # Initialize submodules
  141. git submodule update --init --recursive
  142. # configure branch
  143. pushd MediaBrowser.WebDashboard/jellyfin-web
  144. if ! git diff-index --quiet HEAD --; then
  145. popd
  146. echo
  147. echo "ERROR: Your 'jellyfin-web' submodule working directory is not clean!"
  148. echo "This script will overwrite your unstaged and unpushed changes."
  149. echo "Please do development on 'jellyfin-web' outside of the submodule."
  150. exit 1
  151. fi
  152. git fetch --all
  153. # If this is an official branch name, fetch it from origin
  154. official_branches_regex="^master$|^dev$|^release-.*$|^hotfix-.*$"
  155. if [[ ${web_branch} =~ ${official_branches_regex} ]]; then
  156. git checkout origin/${web_branch} || {
  157. echo "ERROR: 'jellyfin-web' branch 'origin/${web_branch}' is invalid."
  158. exit 1
  159. }
  160. # Otherwise, just check out the local branch (for testing, etc.)
  161. else
  162. git checkout ${web_branch} || {
  163. echo "ERROR: 'jellyfin-web' branch '${web_branch}' is invalid."
  164. exit 1
  165. }
  166. fi
  167. popd
  168. # Execute each platform and action in order, if said action is enabled
  169. pushd deployment/
  170. for target_platform in ${platform[@]}; do
  171. echo -e "> Processing platform ${target_platform}"
  172. date_start=$( date +%s )
  173. pushd ${target_platform}
  174. for target_action in ${action[@]}; do
  175. echo -e ">> Processing action ${target_action}"
  176. if [[ -f ${target_action}.sh && -x ${target_action}.sh ]]; then
  177. ./${target_action}.sh
  178. fi
  179. done
  180. if [[ -d pkg-dist/ ]]; then
  181. echo -e ">> Collecting build artifacts"
  182. target_dir="../../../jellyfin-build/${target_platform}"
  183. mkdir -p ${target_dir}
  184. mv pkg-dist/* ${target_dir}/
  185. echo -e ">> Processing action clean"
  186. if [[ -f clean.sh && -x clean.sh ]]; then
  187. ./clean.sh
  188. fi
  189. fi
  190. date_end=$( date +%s )
  191. echo -e "> Completed platform ${target_platform} in $( expr ${date_end} - ${date_start} ) seconds."
  192. popd
  193. done
  194. popd