build.sh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #!/usr/bin/env bash
  2. # build.sh - Build Jellyfin binary packages
  3. # Part of the Jellyfin Project
  4. set -o errexit
  5. set -o pipefail
  6. usage() {
  7. echo -e "build.sh - Build Jellyfin binary packages"
  8. echo -e "Usage:"
  9. echo -e " $0 -t/--type <BUILD_TYPE> -p/--platform <PLATFORM> [-k/--keep-artifacts] [-l/--list-platforms]"
  10. echo -e "Notes:"
  11. echo -e " * BUILD_TYPE can be one of: [native, docker] and must be specified"
  12. echo -e " * native: Build using the build script in the host OS"
  13. echo -e " * docker: Build using the build script in a standardized Docker container"
  14. echo -e " * PLATFORM can be any platform shown by -l/--list-platforms and must be specified"
  15. echo -e " * If -k/--keep-artifacts is specified, transient artifacts (e.g. Docker containers) will be"
  16. echo -e " retained after the build is finished; the source directory will still be cleaned"
  17. echo -e " * If -l/--list-platforms is specified, all other arguments are ignored; the script will print"
  18. echo -e " the list of supported platforms and exit"
  19. }
  20. list_platforms() {
  21. declare -a platforms
  22. platforms=(
  23. $( find deployment -maxdepth 1 -mindepth 1 -name "build.*" | awk -F'.' '{ $1=""; printf $2; if ($3 != ""){ printf "." $3; }; if ($4 != ""){ printf "." $4; }; print ""; }' | sort )
  24. )
  25. echo -e "Valid platforms:"
  26. echo
  27. for platform in ${platforms[@]}; do
  28. echo -e "* ${platform} : $( grep '^#=' deployment/build.${platform} | sed 's/^#= //' )"
  29. done
  30. }
  31. do_build_native() {
  32. if [[ ! -f $( which dpkg ) || $( dpkg --print-architecture | head -1 ) != "${PLATFORM##*.}" ]]; then
  33. echo "Cross-building is not supported for native builds, use 'docker' builds on amd64 for cross-building."
  34. exit 1
  35. fi
  36. export IS_DOCKER=NO
  37. deployment/build.${PLATFORM}
  38. }
  39. do_build_docker() {
  40. if [[ -f $( which dpkg ) && $( dpkg --print-architecture | head -1 ) != "amd64" ]]; then
  41. echo "Docker-based builds only support amd64-based cross-building; use a 'native' build instead."
  42. exit 1
  43. fi
  44. if [[ ! -f deployment/Dockerfile.${PLATFORM} ]]; then
  45. echo "Missing Dockerfile for platform ${PLATFORM}"
  46. exit 1
  47. fi
  48. if [[ ${KEEP_ARTIFACTS} == YES ]]; then
  49. docker_args=""
  50. else
  51. docker_args="--rm"
  52. fi
  53. docker build . -t "jellyfin-builder.${PLATFORM}" -f deployment/Dockerfile.${PLATFORM}
  54. mkdir -p ${ARTIFACT_DIR}
  55. docker run $docker_args -v "${SOURCE_DIR}:/jellyfin" -v "${ARTIFACT_DIR}:/dist" "jellyfin-builder.${PLATFORM}"
  56. }
  57. while [[ $# -gt 0 ]]; do
  58. key="$1"
  59. case $key in
  60. -t|--type)
  61. BUILD_TYPE="$2"
  62. shift # past argument
  63. shift # past value
  64. ;;
  65. -p|--platform)
  66. PLATFORM="$2"
  67. shift # past argument
  68. shift # past value
  69. ;;
  70. -k|--keep-artifacts)
  71. KEEP_ARTIFACTS=YES
  72. shift # past argument
  73. ;;
  74. -l|--list-platforms)
  75. list_platforms
  76. exit 0
  77. ;;
  78. -h|--help)
  79. usage
  80. exit 0
  81. ;;
  82. *) # unknown option
  83. echo "Unknown option $1"
  84. usage
  85. exit 1
  86. ;;
  87. esac
  88. done
  89. if [[ -z ${BUILD_TYPE} || -z ${PLATFORM} ]]; then
  90. usage
  91. exit 1
  92. fi
  93. export SOURCE_DIR="$( pwd )"
  94. export ARTIFACT_DIR="${SOURCE_DIR}/../bin/${PLATFORM}"
  95. # Determine build type
  96. case ${BUILD_TYPE} in
  97. native)
  98. do_build_native
  99. ;;
  100. docker)
  101. do_build_docker
  102. ;;
  103. esac