package.sh 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #!/usr/bin/env sh
  2. source ../common.build.sh
  3. VERSION=`get_version ../..`
  4. # TODO get the version in the package automatically. And using the changelog to decide the debian package suffix version.
  5. # Build a Jellyfin .rpm file with Docker on Linux
  6. # Places the output .rpm file in the parent directory
  7. set -o errexit
  8. set -o xtrace
  9. set -o nounset
  10. package_temporary_dir="`pwd`/pkg-dist-tmp"
  11. output_dir="`pwd`/pkg-dist"
  12. pkg_src_dir="`pwd`/pkg-src"
  13. current_user="`whoami`"
  14. image_name="jellyfin-rpmbuild"
  15. cleanup() {
  16. set +o errexit
  17. docker image rm $image_name --force
  18. rm -rf "$package_temporary_dir"
  19. rm -rf "$pkg_src_dir/jellyfin-${VERSION}.tar.gz"
  20. }
  21. trap cleanup EXIT INT
  22. GNU_TAR=1
  23. mkdir -p "$package_temporary_dir"
  24. echo "Bundling all sources for RPM build."
  25. tar \
  26. --transform "s,^\.,jellyfin-${VERSION}" \
  27. --exclude='.git*' \
  28. --exclude='**/.git' \
  29. --exclude='**/.hg' \
  30. --exclude='**/.vs' \
  31. --exclude='**/.vscode' \
  32. --exclude='deployment' \
  33. --exclude='**/bin' \
  34. --exclude='**/obj' \
  35. --exclude='**/.nuget' \
  36. --exclude='*.deb' \
  37. --exclude='*.rpm' \
  38. -Jcvf \
  39. "$package_temporary_dir/jellyfin-${VERSION}.tar.xz" \
  40. -C "../.." \
  41. ./ || true && GNU_TAR=0
  42. if [ $GNU_TAR -eq 0 ]; then
  43. echo "The installed tar binary did not support --transform. Using workaround."
  44. mkdir -p "$package_temporary_dir/jellyfin-${VERSION}"
  45. # Not GNU tar
  46. tar \
  47. --exclude='.git*' \
  48. --exclude='**/.git' \
  49. --exclude='**/.hg' \
  50. --exclude='**/.vs' \
  51. --exclude='**/.vscode' \
  52. --exclude='deployment' \
  53. --exclude='**/bin' \
  54. --exclude='**/obj' \
  55. --exclude='**/.nuget' \
  56. --exclude='*.deb' \
  57. --exclude='*.rpm' \
  58. -zcf \
  59. "$package_temporary_dir/jellyfin-${VERSION}/jellyfin.tar.gz" \
  60. -C "../.." \
  61. ./
  62. echo "Extracting filtered package."
  63. tar -xzf "$package_temporary_dir/jellyfin-${VERSION}/jellyfin.tar.gz" -C "$package_temporary_dir/jellyfin-${VERSION}"
  64. echo "Removing filtered package."
  65. rm "$package_temporary_dir/jellyfin-${VERSION}/jellyfin.tar.gz"
  66. echo "Repackaging package into final tarball."
  67. tar -zcf "$pkg_src_dir/jellyfin-${VERSION}.tar.gz" -C "$package_temporary_dir" "jellyfin-${VERSION}"
  68. fi
  69. docker build ../.. -t "$image_name" -f ./Dockerfile
  70. mkdir -p "$output_dir"
  71. docker run --rm -v "$package_temporary_dir:/temp" "$image_name" sh -c 'find /build/rpmbuild -maxdepth 3 -type f -name "jellyfin*.rpm" -exec mv {} /temp \;'
  72. chown -R "$current_user" "$package_temporary_dir" \
  73. || sudo chown -R "$current_user" "$package_temporary_dir"
  74. mv "$package_temporary_dir"/*.rpm "$output_dir"