source_package_build.bash 1.8 KB

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