File: repack

package info (click to toggle)
rtv 1.25.1+dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 6,704 kB
  • sloc: python: 10,905; sh: 67; makefile: 4
file content (83 lines) | stat: -rwxr-xr-x 2,108 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#! /bin/bash
# debian/repack
# Re-build the pristine upstream source to serve as the Debian upstream source.

set -o errexit
set -o errtrace
set -o nounset

function usage() {
    progname="$(basename "$0")"
    printf "$progname --upstream-version VERSION FILENAME\n"
}

if [ $# -ne 3 ] ; then
    usage
    exit 1
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_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"

tar -xzf "${downloaded_file}" --directory "${working_dir}"

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"

mv "${upstream_source_dir}" "${repack_dir}"

printf "Removing non-DFSG-free files:\n"

nonfree_files=(
        tests/cassettes
        )

for f in "${nonfree_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}"

printf "Moving completed upstream tarball to ‘${target_file}’:\n"

rm -v "${downloaded_file}"
mv "${target_working_file}" "${target_file}"

printf "Done.\n"


# Local variables:
# coding: utf-8
# mode: sh
# End:
# vim: fileencoding=utf-8 filetype=sh :