docker-build.sh 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #!/bin/bash
  2. # Builds the RPM inside the Docker container
  3. set -o errexit
  4. set -o xtrace
  5. # Move to source directory
  6. pushd ${SOURCE_DIR}
  7. VERSION="$( grep '^Version:' ${SOURCE_DIR}/SOURCES/pkg-src/jellyfin.spec | awk '{ print $NF }' )"
  8. # Clone down and build Web frontend
  9. web_build_dir="$( mktemp -d )"
  10. web_target="${SOURCE_DIR}/MediaBrowser.WebDashboard/jellyfin-web"
  11. git clone https://github.com/jellyfin/jellyfin-web.git ${web_build_dir}/
  12. pushd ${web_build_dir}
  13. if [[ -n ${web_branch} ]]; then
  14. checkout -b origin/${web_branch}
  15. fi
  16. yarn install
  17. mkdir -p ${web_target}
  18. mv dist/* ${web_target}/
  19. popd
  20. rm -rf ${web_build_dir}
  21. # Create RPM source archive
  22. GNU_TAR=1
  23. echo "Bundling all sources for RPM build."
  24. tar \
  25. --transform "s,^\.,jellyfin-${VERSION}," \
  26. --exclude='.git*' \
  27. --exclude='**/.git' \
  28. --exclude='**/.hg' \
  29. --exclude='**/.vs' \
  30. --exclude='**/.vscode' \
  31. --exclude='deployment' \
  32. --exclude='**/bin' \
  33. --exclude='**/obj' \
  34. --exclude='**/.nuget' \
  35. --exclude='*.deb' \
  36. --exclude='*.rpm' \
  37. -czf "${SOURCE_DIR}/SOURCES/pkg-src/jellyfin-${VERSION}.tar.gz" \
  38. -C ${SOURCE_DIR} ./ || GNU_TAR=0
  39. if [ $GNU_TAR -eq 0 ]; then
  40. echo "The installed tar binary did not support --transform. Using workaround."
  41. package_temporary_dir="$( mktemp -d )"
  42. mkdir -p "${package_temporary_dir}/jellyfin"
  43. # Not GNU tar
  44. tar \
  45. --exclude='.git*' \
  46. --exclude='**/.git' \
  47. --exclude='**/.hg' \
  48. --exclude='**/.vs' \
  49. --exclude='**/.vscode' \
  50. --exclude='deployment' \
  51. --exclude='**/bin' \
  52. --exclude='**/obj' \
  53. --exclude='**/.nuget' \
  54. --exclude='*.deb' \
  55. --exclude='*.rpm' \
  56. -czf "${package_temporary_dir}/jellyfin/jellyfin-${VERSION}.tar.gz" \
  57. -C ${SOURCE_DIR} ./
  58. echo "Extracting filtered package."
  59. mkdir -p "${package_temporary_dir}/jellyfin-${VERSION}"
  60. tar -xzf "${package_temporary_dir}/jellyfin/jellyfin-${VERSION}.tar.gz" -C "${package_temporary_dir}/jellyfin-${VERSION}"
  61. echo "Removing filtered package."
  62. rm -f "${package_temporary_dir}/jellyfin/jellyfin-${VERSION}.tar.gz"
  63. echo "Repackaging package into final tarball."
  64. tar -czf "${SOURCE_DIR}/SOURCES/pkg-src/jellyfin-${VERSION}.tar.gz" -C "${package_temporary_dir}" "jellyfin-${VERSION}"
  65. rm -rf ${package_temporary_dir}
  66. fi
  67. # Build RPM
  68. spectool -g -R SPECS/jellyfin.spec
  69. rpmbuild -bs SPECS/jellyfin.spec --define "_sourcedir ${SOURCE_DIR}/SOURCES/pkg-src/"
  70. rpmbuild -bb SPECS/jellyfin.spec --define "_sourcedir ${SOURCE_DIR}/SOURCES/pkg-src/"
  71. # Move the artifacts out
  72. mkdir -p ${ARTIFACT_DIR}/rpm
  73. mv /root/rpmbuild/RPMS/x86_64/jellyfin-*.rpm /root/rpmbuild/SRPMS/jellyfin-*.src.rpm ${ARTIFACT_DIR}/rpm/
  74. chown -Rc $(stat -c %u:%g ${ARTIFACT_DIR}) ${ARTIFACT_DIR}