]> git.donarmstrong.com Git - debhelper.git/blob - dh_md5sums
dh: Improve filtering in dh_listpackages example. Closes: #604561
[debhelper.git] / dh_md5sums
1 #!/usr/bin/perl -w
2
3 =head1 NAME
4
5 dh_md5sums - generate DEBIAN/md5sums file
6
7 =cut
8
9 use strict;
10 use Cwd;
11 use Debian::Debhelper::Dh_Lib;
12
13 =head1 SYNOPSIS
14
15 B<dh_md5sums> [S<I<debhelper options>>] [B<-x>] [B<-X>I<item>] [B<--include-conffiles>]
16
17 =head1 DESCRIPTION
18
19 B<dh_md5sums> is a debhelper program that is responsible for generating
20 a F<DEBIAN/md5sums> file, which lists the md5sums of each file in the package.
21 These files are used by the B<debsums> package.
22
23 All files in F<DEBIAN/> are omitted from the F<md5sums> file, as are all
24 conffiles (unless you use the B<--include-conffiles> switch).
25
26 The md5sums file is installed with proper permissions and ownerships.
27
28 =head1 OPTIONS
29
30 =over 4
31
32 =item B<-x>, B<--include-conffiles>
33
34 Include conffiles in the md5sums list. Note that this information is
35 redundant since it is included elsewhere in Debian packages.
36
37 =item B<-X>I<item>, B<--exclude=>I<item>
38
39 Exclude files that contain I<item> anywhere in their filename from
40 being listed in the md5sums file.
41
42 =back
43
44 =cut
45
46 init(options => {
47         "x" => \$dh{INCLUDE_CONFFILES}, # is -x for some unknown historical reason..
48         "include-conffiles" => \$dh{INCLUDE_CONFFILES},
49 });
50
51 foreach my $package (@{$dh{DOPACKAGES}}) {
52         next if is_udeb($package);
53         
54         my $tmp=tmpdir($package);
55
56         if (! -d "$tmp/DEBIAN") {
57                 doit("install","-d","$tmp/DEBIAN");
58         }
59
60         # Check if we should exclude conffiles.
61         my $exclude="";
62         if (! $dh{INCLUDE_CONFFILES} && -r "$tmp/DEBIAN/conffiles") {
63                 # Generate exclude regexp.
64                 open (CONFF,"$tmp/DEBIAN/conffiles");
65                 while (<CONFF>) {
66                         chomp;
67                         s/^\///;
68                         $exclude.="! -path \"./$_\" ";
69                 }
70                 close CONFF;
71         }
72         
73         # See if we should exclude other files.
74         if (defined($dh{EXCLUDE_FIND}) && $dh{EXCLUDE_FIND} ne '') {
75                 $exclude.="! \\( $dh{EXCLUDE_FIND} \\) ";
76         }
77         
78         my $find="find . -type f $exclude ! -regex '.*/DEBIAN/.*' -printf '%P\\0'";
79         complex_doit("(cd $tmp >/dev/null ; $find | LC_ALL=C sort -z | xargs -r0 md5sum > DEBIAN/md5sums) >/dev/null");
80         # If the file's empty, no reason to waste inodes on it.
81         if (-z "$tmp/DEBIAN/md5sums") {
82                 doit("rm","-f","$tmp/DEBIAN/md5sums");
83         }
84         else {
85                 doit("chmod",644,"$tmp/DEBIAN/md5sums");
86                 doit("chown","0:0","$tmp/DEBIAN/md5sums");
87         }
88 }
89
90 =head1 SEE ALSO
91
92 L<debhelper(7)>
93
94 This program is a part of debhelper.
95
96 =head1 AUTHOR
97
98 Joey Hess <joeyh@debian.org>
99
100 =cut