source_package_build.bash 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # debian/source_package_build.bash
  2. # Part of the Debian package ‘python-coverage’.
  3. #
  4. # Copyright © 2010–2016 Ben Finney <bignose@debian.org>
  5. #
  6. # This is free software; you may copy, modify, and/or distribute this
  7. # work under the terms of the Apache License, version 2.0 as published
  8. # by the Apache Software Foundation. No warranty expressed or implied.
  9. # See the file ‘/usr/share/common-licenses/Apache-2.0’ for details.
  10. # Common code for building Debian upstream source package.
  11. working_dir="$(mktemp -d -t)"
  12. exit_sigspecs="ERR EXIT SIGTERM SIGHUP SIGINT SIGQUIT"
  13. function cleanup_exit() {
  14. exit_status=$?
  15. trap - $exit_sigspecs
  16. rm -rf "${working_dir}"
  17. printf "Cleaned up working directory ‘%s’\n" "${working_dir}"
  18. exit $exit_status
  19. }
  20. trap cleanup_exit $exit_sigspecs
  21. package_name=$(dpkg-parsechangelog | sed -n -e 's/^Source: //p')
  22. release_version=$(dpkg-parsechangelog | sed -n -e 's/^Version: //p')
  23. upstream_version=$(printf "${release_version}" \
  24. | sed -e 's/^[[:digit:]]\+://' -e 's/[-][^-]\+$//')
  25. upstream_dirname="${package_name}-${upstream_version}.orig"
  26. upstream_tarball_basename="${package_name}_${upstream_version}.orig"
  27. function extract_tarball_to_working_dir() {
  28. # Extract the specified tarball to the program's working directory.
  29. local tarball="$1"
  30. tar -xf "${tarball}" --directory "${working_dir}"
  31. }
  32. function archive_working_dir_to_tarball() {
  33. # Archive the specified directory, relative to the working directory,
  34. # to a new tarball of the specified name.
  35. local source_dirname="$1"
  36. local tarball="$2"
  37. GZIP="--best" tar \
  38. --directory "${working_dir}" \
  39. -czf "${tarball}" \
  40. "${source_dirname}"
  41. }
  42. # Local variables:
  43. # coding: utf-8
  44. # mode: shell-script
  45. # indent-tabs-mode: nil
  46. # End:
  47. # vim: fileencoding=utf-8 filetype=bash expandtab :