build 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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 | sed 's/deployment\///' | 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
  14. dependencies=( 'tar' 'zip' 'dotnet' )
  15. usage() {
  16. echo -e "build - build Jellyfin binaries or packages"
  17. echo -e ""
  18. echo -e "Usage:"
  19. echo -e " $ build --list-platforms"
  20. echo -e " $ build --list-actions <platform>"
  21. echo -e " $ build [-b/--web-branch <web_branch>] <platform> <action>"
  22. echo -e ""
  23. echo -e "The web_branch defaults to 'master'."
  24. echo -e "To build all platforms, use 'all'."
  25. echo -e "To perform all build actions, use 'all'."
  26. echo -e "Build output files are collected at '../jellyfin-build/<platform>'."
  27. }
  28. if [[ -z $1 ]]; then
  29. usage
  30. exit 0
  31. fi
  32. # List all available platforms then exit
  33. if [[ $1 == '--list-platforms' ]]; then
  34. echo -e "Available platforms:"
  35. for platform in ${platforms[@]}; do
  36. echo -e " ${platform}"
  37. done
  38. exit 0
  39. fi
  40. # List all available actions for a given platform then exit
  41. if [[ $1 == '--list-actions' ]]; then
  42. platform="$2"
  43. if [[ ! " ${platforms[@]} " =~ " ${platform} " ]]; then
  44. echo "ERROR: Platform $platform does not exist."
  45. exit 1
  46. fi
  47. echo -e "Available actions for platform ${platform}:"
  48. for action in ${actions[@]}; do
  49. if [[ -f deployment/${platform}/${action}.sh ]]; then
  50. echo -e " ${action}"
  51. fi
  52. done
  53. exit 0
  54. fi
  55. # Parse branch option
  56. if [[ $1 == '-b' || $1 == '--web-branch' ]]; then
  57. web_branch="$2"
  58. shift 2
  59. else
  60. web_branch="master"
  61. fi
  62. # Parse platform option
  63. if [[ -n $1 ]]; then
  64. cli_platform="$1"
  65. shift
  66. else
  67. echo "ERROR: A platform must be specified. Use 'all' to specify all platforms."
  68. exit 1
  69. fi
  70. if [[ $cli_platform == 'all' ]]; then
  71. declare -a platform=( ${platforms[@]} )
  72. else
  73. if [[ ! " ${platforms[@]} " =~ " ${cli_platform} " ]]; then
  74. echo "ERROR: Platform $cli_platform is invalid. Use the '--list-platforms' option to list available platforms."
  75. exit 1
  76. else
  77. declare -a platform=( "${cli_platform}" )
  78. fi
  79. fi
  80. # Parse action option
  81. if [[ -n $1 ]]; then
  82. cli_action="$1"
  83. shift
  84. else
  85. echo "ERROR: An action must be specified. Use 'all' to specify all actions."
  86. exit 1
  87. fi
  88. if [[ $cli_action == 'all' ]]; then
  89. declare -a action=( ${actions[@]} )
  90. else
  91. if [[ ! " ${actions[@]} " =~ " ${cli_action} " ]]; then
  92. echo "ERROR: Action $cli_action is invalid. Use the '--list-actions <platform>' option to list available actions."
  93. exit 1
  94. else
  95. declare -a action=( "${cli_action}" )
  96. fi
  97. fi
  98. # Verify required utilities are installed
  99. missing_deps=()
  100. for utility in ${dependencies[@]}; do
  101. if ! which ${utility} &>/dev/null; then
  102. missing_deps+=( ${utility} )
  103. fi
  104. done
  105. # Error if we're missing anything
  106. if [[ ${#missing_deps[@]} -gt 0 ]]; then
  107. echo -e "ERROR: This script requires the following missing utilities:"
  108. for utility in ${missing_deps[@]}; do
  109. echo -e " ${utility}"
  110. done
  111. exit 1
  112. fi
  113. # Parse platform-specific dependencies
  114. for target_platform in ${platform[@]}; do
  115. # Read platform-specific dependencies
  116. if [[ -f deployment/${target_platform}/dependencies.txt ]]; then
  117. platform_dependencies="$( grep -v '^#' deployment/${target_platform}/dependencies.txt )"
  118. # Verify required utilities are installed
  119. missing_deps=()
  120. for utility in ${platform_dependencies[@]}; do
  121. if ! which ${utility} &>/dev/null; then
  122. missing_deps+=( ${utility} )
  123. fi
  124. done
  125. # Error if we're missing anything
  126. if [[ ${#missing_deps[@]} -gt 0 ]]; then
  127. echo -e "ERROR: The ${target_platform} platform requires the following utilities:"
  128. for utility in ${missing_deps[@]}; do
  129. echo -e " ${utility}"
  130. done
  131. exit 1
  132. fi
  133. fi
  134. done
  135. # Initialize submodules
  136. git submodule update --init --recursive
  137. # configure branch
  138. pushd MediaBrowser.WebDashboard/jellyfin-web
  139. if ! git diff-index --quiet HEAD --; then
  140. popd
  141. echo
  142. echo "ERROR: Your 'jellyfin-web' submodule working directory is not clean!"
  143. echo "This script will overwrite your unstaged and unpushed changes."
  144. echo "Please do development on 'jellyfin-web' outside of the submodule."
  145. exit 1
  146. fi
  147. git fetch --all
  148. git checkout origin/${web_branch} || {
  149. echo "Error: 'jellyfin-web' branch ${web_branch} is invalid."
  150. exit 1
  151. }
  152. popd
  153. # Execute each platform and action in order, if said action is enabled
  154. pushd deployment/
  155. for target_platform in ${platform[@]}; do
  156. echo -e "> Processing platform ${target_platform}"
  157. pushd ${target_platform}
  158. for target_action in ${action[@]}; do
  159. echo -e ">> Processing action ${target_action}"
  160. if [[ -f ${target_action}.sh && -x ${target_action}.sh ]]; then
  161. ./${target_action}.sh
  162. fi
  163. done
  164. if [[ -d pkg-dist/ ]]; then
  165. echo -e ">> Collecting build artifacts"
  166. target_dir="../../../jellyfin-build/${target_platform}"
  167. mkdir -p ${target_dir}
  168. mv pkg-dist/* ${target_dir}/
  169. echo -e ">> Processing action clean"
  170. if [[ -f clean.sh && -x clean.sh ]]; then
  171. ./clean.sh
  172. fi
  173. fi
  174. popd
  175. done
  176. popd