package.sh 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/usr/bin/env bash
  2. source ../common.build.sh
  3. WORKDIR="$( pwd )"
  4. VERSION="$( grep '^Version:' ${WORKDIR}/pkg-src/jellyfin.spec | awk '{ print $NF }' )"
  5. package_temporary_dir="${WORKDIR}/pkg-dist-tmp"
  6. output_dir="${WORKDIR}/pkg-dist"
  7. pkg_src_dir="${WORKDIR}/pkg-src"
  8. current_user="$( whoami )"
  9. image_name="jellyfin-centos-build"
  10. # Determine if sudo should be used for Docker
  11. if [[ ! -z $(id -Gn | grep -q 'docker') ]] \
  12. && [[ ! ${EUID:-1000} -eq 0 ]] \
  13. && [[ ! ${USER} == "root" ]] \
  14. && [[ ! -z $( echo "${OSTYPE}" | grep -q "darwin" ) ]]; then
  15. docker_sudo="sudo"
  16. else
  17. docker_sudo=""
  18. fi
  19. # Create RPM source archive
  20. GNU_TAR=1
  21. mkdir -p "${package_temporary_dir}"
  22. echo "Bundling all sources for RPM build."
  23. tar \
  24. --transform "s,^\.,jellyfin-${VERSION}," \
  25. --exclude='.git*' \
  26. --exclude='**/.git' \
  27. --exclude='**/.hg' \
  28. --exclude='**/.vs' \
  29. --exclude='**/.vscode' \
  30. --exclude='deployment' \
  31. --exclude='**/bin' \
  32. --exclude='**/obj' \
  33. --exclude='**/.nuget' \
  34. --exclude='*.deb' \
  35. --exclude='*.rpm' \
  36. -czf "${pkg_src_dir}/jellyfin-${VERSION}.tar.gz" \
  37. -C "../.." ./ || GNU_TAR=0
  38. if [ $GNU_TAR -eq 0 ]; then
  39. echo "The installed tar binary did not support --transform. Using workaround."
  40. mkdir -p "${package_temporary_dir}/jellyfin"
  41. # Not GNU tar
  42. tar \
  43. --exclude='.git*' \
  44. --exclude='**/.git' \
  45. --exclude='**/.hg' \
  46. --exclude='**/.vs' \
  47. --exclude='**/.vscode' \
  48. --exclude='deployment' \
  49. --exclude='**/bin' \
  50. --exclude='**/obj' \
  51. --exclude='**/.nuget' \
  52. --exclude='*.deb' \
  53. --exclude='*.rpm' \
  54. -zcf \
  55. "${package_temporary_dir}/jellyfin/jellyfin-${VERSION}.tar.gz" \
  56. -C "../.." ./
  57. echo "Extracting filtered package."
  58. tar -xzf "${package_temporary_dir}/jellyfin/jellyfin-${VERSION}.tar.gz" -C "${package_temporary_dir}/jellyfin-${VERSION}"
  59. echo "Removing filtered package."
  60. rm -f "${package_temporary_dir}/jellyfin/jellyfin-${VERSION}.tar.gz"
  61. echo "Repackaging package into final tarball."
  62. tar -czf "${pkg_src_dir}/jellyfin-${VERSION}.tar.gz" -C "${package_temporary_dir}" "jellyfin-${VERSION}"
  63. fi
  64. # Set up the build environment Docker image
  65. ${docker_sudo} docker build ../.. -t "${image_name}" -f ./Dockerfile
  66. # Build the RPMs and copy out to ${package_temporary_dir}
  67. ${docker_sudo} docker run --rm -v "${package_temporary_dir}:/dist" "${image_name}"
  68. # Correct ownership on the RPMs (as current user, then as root if that fails)
  69. chown -R "${current_user}" "${package_temporary_dir}" \
  70. || sudo chown -R "${current_user}" "${package_temporary_dir}"
  71. # Move the RPMs to the output directory
  72. mkdir -p "${output_dir}"
  73. mv "${package_temporary_dir}"/rpm/* "${output_dir}"