From 6eedec6d959ceb0d91a85bf7f54ecc5b77b4f02c Mon Sep 17 00:00:00 2001 From: Ben Finney Date: Sat, 12 Mar 2016 18:19:59 +1100 Subject: [PATCH] Incorporate improvements to repack program. --- debian/repack | 51 ++++++++++++++--------------------- debian/source_package_build.bash | 58 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 31 deletions(-) create mode 100644 debian/source_package_build.bash diff --git a/debian/repack b/debian/repack index 81b697a..b870f2f 100755 --- a/debian/repack +++ b/debian/repack @@ -16,10 +16,14 @@ set -o errexit set -o errtrace +set -o pipefail set -o nounset +program_dir="$(dirname "$(realpath --strip "$0")")" +source "${program_dir}"/source_package_build.bash + function usage() { - progname="$(basename "$0")" + local progname=$(basename $0) printf "$progname --upstream-version VERSION FILENAME\n" } @@ -31,58 +35,42 @@ fi upstream_version="$2" downloaded_file="$3" -working_dir="$(mktemp -d -t)" - -function cleanup_exit() { - exit_status=$? - trap - ERR EXIT SIGTERM SIGHUP SIGINT SIGQUIT - - rm -rf "${working_dir}" - - exit $exit_status -} -trap "cleanup_exit" ERR EXIT SIGTERM SIGHUP SIGINT SIGQUIT - -package_name=$(dpkg-parsechangelog | sed -n -e 's/^Source: //p') -release_version=$(dpkg-parsechangelog | sed -n -e 's/^Version: //p') -upstream_version=$(printf "${release_version}" \ - | sed -e 's/^[[:digit:]]\+://' -e 's/[-][^-]\+$//') -upstream_dirname="${package_name}-${upstream_version}.orig" - -target_filename="${package_name}_${upstream_version}.orig.tar.gz" +target_filename="${upstream_tarball_basename}.tar.gz" target_working_file="${working_dir}/${target_filename}" target_file="$(dirname "${downloaded_file}")/${target_filename}" repack_dir="${working_dir}/${upstream_dirname}" -printf "Unpacking pristine upstream source ‘${downloaded_file}’:\n" +printf "Unpacking pristine upstream source ‘%s’:\n" "${downloaded_file}" -tar -xf "${downloaded_file}" --directory "${working_dir}" +extract_tarball_to_working_dir "${downloaded_file}" upstream_source_dirname=$(ls -1 "${working_dir}") upstream_source_dir="${working_dir}/${upstream_source_dirname}" -printf "Repackaging upstream source from ‘${upstream_source_dir}’ to ‘${repack_dir}’:\n" +printf "Repackaging upstream source from ‘%s’ to ‘%s’:\n" \ + "${upstream_source_dir}" "${repack_dir}" mv "${upstream_source_dir}" "${repack_dir}" -printf "Removing non-DFSG-free files:\n" +printf "Removing non-source files:\n" -nonfree_files=( +nonsource_files=( + # Compiled JavaScript files without corresponding source. coverage/htmlfiles/jquery.min.js coverage/htmlfiles/jquery.debounce.min.js coverage/htmlfiles/jquery.tablesorter.min.js ) -for f in "${nonfree_files[@]}" ; do - rm -v "${repack_dir}/$f" +for f in "${nonsource_files[@]}" ; do + rm -rv "${repack_dir}/$f" done printf "Rebuilding DFSG-free upstream source tarball:\n" -GZIP="--best" tar --directory "${working_dir}" -czf "${target_working_file}" "${upstream_dirname}" +archive_working_dir_to_tarball "${upstream_dirname}" "${target_working_file}" -printf "Moving completed upstream tarball to ‘${target_file}’:\n" +printf "Moving completed upstream tarball to ‘%s’:\n" "${target_file}" rm -v "${downloaded_file}" mv "${target_working_file}" "${target_file}" @@ -92,6 +80,7 @@ printf "Done.\n" # Local variables: # coding: utf-8 -# mode: sh +# mode: shell-script +# indent-tabs-mode: nil # End: -# vim: fileencoding=utf-8 filetype=sh : +# vim: fileencoding=utf-8 filetype=bash expandtab : diff --git a/debian/source_package_build.bash b/debian/source_package_build.bash new file mode 100644 index 0000000..3499f68 --- /dev/null +++ b/debian/source_package_build.bash @@ -0,0 +1,58 @@ +# debian/source_package_build.bash +# Part of the Debian package ‘python-coverage’. +# +# Copyright © 2010–2016 Ben Finney +# +# This is free software; you may copy, modify, and/or distribute this +# work under the terms of the Apache License, version 2.0 as published +# by the Apache Software Foundation. No warranty expressed or implied. +# See the file ‘/usr/share/common-licenses/Apache-2.0’ for details. + +# Common code for building Debian upstream source package. + +working_dir="$(mktemp -d -t)" + +exit_sigspecs="ERR EXIT SIGTERM SIGHUP SIGINT SIGQUIT" + +function cleanup_exit() { + exit_status=$? + trap - $exit_sigspecs + + rm -rf "${working_dir}" + printf "Cleaned up working directory ‘%s’\n" "${working_dir}" + + exit $exit_status +} +trap cleanup_exit $exit_sigspecs + +package_name=$(dpkg-parsechangelog | sed -n -e 's/^Source: //p') +release_version=$(dpkg-parsechangelog | sed -n -e 's/^Version: //p') +upstream_version=$(printf "${release_version}" \ + | sed -e 's/^[[:digit:]]\+://' -e 's/[-][^-]\+$//') +upstream_dirname="${package_name}-${upstream_version}.orig" +upstream_tarball_basename="${package_name}_${upstream_version}.orig" + +function extract_tarball_to_working_dir() { + # Extract the specified tarball to the program's working directory. + local tarball="$1" + tar -xf "${tarball}" --directory "${working_dir}" +} + +function archive_working_dir_to_tarball() { + # Archive the specified directory, relative to the working directory, + # to a new tarball of the specified name. + local source_dirname="$1" + local tarball="$2" + GZIP="--best" tar \ + --directory "${working_dir}" \ + -czf "${tarball}" \ + "${source_dirname}" +} + + +# Local variables: +# coding: utf-8 +# mode: shell-script +# indent-tabs-mode: nil +# End: +# vim: fileencoding=utf-8 filetype=bash expandtab : -- 2.11.4.GIT