summaryrefslogtreecommitdiff
path: root/dh_md5sums
blob: c94f8f2fa7286d36093bb31d7f56090a29103177 (plain)
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/perl

=head1 NAME

dh_md5sums - generate DEBIAN/md5sums file

=cut

use strict;
use warnings;
use Cwd;
use Debian::Debhelper::Dh_Lib;

our $VERSION = DH_BUILTIN_VERSION;

=head1 SYNOPSIS

B<dh_md5sums> [S<I<debhelper options>>] [B<-x>] [B<-X>I<item>] [B<--include-conffiles>]

=head1 DESCRIPTION

B<dh_md5sums> is a debhelper program that is responsible for generating
a F<DEBIAN/md5sums> file, which lists the md5sums of each file in the package.
These files are used by B<dpkg --verify> or the L<debsums(1)> program.

All files in F<DEBIAN/> are omitted from the F<md5sums> file, as are all
conffiles (unless you use the B<--include-conffiles> switch).

The md5sums file is installed with proper permissions and ownerships.

=head1 OPTIONS

=over 4

=item B<-x>, B<--include-conffiles>

Include conffiles in the md5sums list. Note that this information is
redundant since it is included elsewhere in Debian packages.

=item B<-X>I<item>, B<--exclude=>I<item>

Exclude files that contain I<item> anywhere in their filename from
being listed in the md5sums file.

=back

=cut

init(options => {
	"x" => \$dh{INCLUDE_CONFFILES}, # is -x for some unknown historical reason..
	"include-conffiles" => \$dh{INCLUDE_CONFFILES},
});

on_pkgs_in_parallel {
	foreach my $package (@_) {
		next if is_udeb($package);

		my $dbgsym_tmp = "debian/.debhelper/${package}/dbgsym-root";
		my $tmp=tmpdir($package);

		install_dir("$tmp/DEBIAN");

		# Check if we should exclude conffiles.
		my $exclude="";
		if (! $dh{INCLUDE_CONFFILES} && -r "$tmp/DEBIAN/conffiles") {
			# Generate exclude regexp.
			open(my $fd, '<', "$tmp/DEBIAN/conffiles")
				or die("open $tmp/DEBIAN/conffiles failed: $!");
			while (<$fd>) {
				chomp;
				s/^\///;
				$exclude.="! -path \"./$_\" ";
			}
			close($fd);
		}

		# See if we should exclude other files.
		if (defined($dh{EXCLUDE_FIND}) && $dh{EXCLUDE_FIND} ne '') {
			$exclude.="! \\( $dh{EXCLUDE_FIND} \\) ";
		}

		my $find="find . -type f $exclude ! -regex './DEBIAN/.*' -printf '%P\\0'";
		complex_doit("(cd $tmp >/dev/null ; $find | LC_ALL=C sort -z | xargs -r0 md5sum | " .
			q{perl -pe 'if (s@^\\\\@@) { s/\\\\\\\\/\\\\/g; }' > DEBIAN/md5sums) >/dev/null});
		# If the file's empty, no reason to waste inodes on it.
		if (-z "$tmp/DEBIAN/md5sums") {
			rm_files("$tmp/DEBIAN/md5sums");
		}
		else {
			reset_perm_and_owner(0644, "$tmp/DEBIAN/md5sums");
		}
		if ( -d $dbgsym_tmp) {
			install_dir("${dbgsym_tmp}/DEBIAN");

			$find = "find . -type f ! -regex './DEBIAN/.*' -printf '%P\\0'";
			complex_doit("(cd $dbgsym_tmp >/dev/null ; $find | LC_ALL=C sort -z | xargs -r0 md5sum | " .
				q{perl -pe 'if (s@^\\\\@@) { s/\\\\\\\\/\\\\/g; }' > DEBIAN/md5sums) >/dev/null});
			# If the file's empty, no reason to waste inodes on it.
			if (-z "${dbgsym_tmp}/DEBIAN/md5sums") {
				rm_files("${dbgsym_tmp}/DEBIAN/md5sums");
			}
			else {
				reset_perm_and_owner(0644, "${dbgsym_tmp}/DEBIAN/md5sums");
			}
		}
	}
};

=head1 SEE ALSO

L<debhelper(7)>

This program is a part of debhelper.

=head1 AUTHOR

Joey Hess <joeyh@debian.org>

=cut