package.sh 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. docker_sudo=""
  16. if ! $(id -Gn | grep -q 'docker') && [ ! ${EUID:-1000} -eq 0 ] && \
  17. [ ! $USER == "root" ] && ! $(echo "$OSTYPE" | grep -q "darwin"); then
  18. docker_sudo=sudo
  19. fi
  20. cleanup() {
  21. set +o errexit
  22. $docker_sudo docker image rm $image_name --force
  23. rm -rf "$package_temporary_dir"
  24. rm -rf "$pkg_src_dir/jellyfin-${VERSION}.tar.gz"
  25. }
  26. trap cleanup EXIT INT
  27. GNU_TAR=1
  28. mkdir -p "$package_temporary_dir"
  29. echo "Bundling all sources for RPM build."
  30. tar \
  31. --transform "s,^\.,jellyfin-${VERSION}," \
  32. --exclude='.git*' \
  33. --exclude='**/.git' \
  34. --exclude='**/.hg' \
  35. --exclude='**/.vs' \
  36. --exclude='**/.vscode' \
  37. --exclude='deployment' \
  38. --exclude='**/bin' \
  39. --exclude='**/obj' \
  40. --exclude='**/.nuget' \
  41. --exclude='*.deb' \
  42. --exclude='*.rpm' \
  43. -zcf "$pkg_src_dir/jellyfin-${VERSION}.tar.gz" \
  44. -C "../.." ./ || GNU_TAR=0
  45. if [ $GNU_TAR -eq 0 ]; then
  46. echo "The installed tar binary did not support --transform. Using workaround."
  47. mkdir -p "$package_temporary_dir/jellyfin-${VERSION}"
  48. # Not GNU tar
  49. tar \
  50. --exclude='.git*' \
  51. --exclude='**/.git' \
  52. --exclude='**/.hg' \
  53. --exclude='**/.vs' \
  54. --exclude='**/.vscode' \
  55. --exclude='deployment' \
  56. --exclude='**/bin' \
  57. --exclude='**/obj' \
  58. --exclude='**/.nuget' \
  59. --exclude='*.deb' \
  60. --exclude='*.rpm' \
  61. -zcf \
  62. "$package_temporary_dir/jellyfin-${VERSION}/jellyfin.tar.gz" \
  63. -C "../.." \
  64. ./
  65. echo "Extracting filtered package."
  66. tar -xzf "$package_temporary_dir/jellyfin-${VERSION}/jellyfin.tar.gz" -C "$package_temporary_dir/jellyfin-${VERSION}"
  67. echo "Removing filtered package."
  68. rm "$package_temporary_dir/jellyfin-${VERSION}/jellyfin.tar.gz"
  69. echo "Repackaging package into final tarball."
  70. tar -zcf "$pkg_src_dir/jellyfin-${VERSION}.tar.gz" -C "$package_temporary_dir" "jellyfin-${VERSION}"
  71. fi
  72. $docker_sudo docker build ../.. -t "$image_name" -f ./Dockerfile
  73. mkdir -p "$output_dir"
  74. $docker_sudo 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 \;'
  75. chown -R "$current_user" "$package_temporary_dir" \
  76. || sudo chown -R "$current_user" "$package_temporary_dir"
  77. mv "$package_temporary_dir"/*.rpm "$output_dir"