[debhelper-devel] [RFC PATCH v1 2/3] Replace dh_md5sums debhelper with dh_checksums

Mimi Zohar zohar at linux.vnet.ibm.com
Mon Oct 20 12:57:31 UTC 2014


The new dh_checksums debhelper extends the existing dh_md5sums to
support larger file digests (eg. sha256, sha512).  The resulting
checksums are stored in an algorithm specific filename
DEBIAN/<algo sums>.

This patch defines a new option "--algo=" to specify the hash
algorithm.  For backwards compatability, the default hash
algorithm is md5.

Changelog v1:
- Based on the mailing list discussion, replace the existing dh_md5sums
script with a single debhelper script that supports larger hashes.
---
 dh                |   2 +-
 dh_checksums      | 118 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 dh_md5sums        | 100 ---------------------------------------------
 man/po4a/po4a.cfg |   2 +-
 4 files changed, 120 insertions(+), 102 deletions(-)
 create mode 100755 dh_checksums
 delete mode 100755 dh_md5sums

diff --git a/dh b/dh
index 4f80f75..127f3d5 100755
--- a/dh
+++ b/dh
@@ -408,7 +408,7 @@ if (! getpackages("arch")) {
 my @b=qw{
 	dh_installdeb
 	dh_gencontrol
-	dh_md5sums
+	dh_checksums
 	dh_builddeb
 };
 $sequences{clean} = [qw{
diff --git a/dh_checksums b/dh_checksums
new file mode 100755
index 0000000..408e192
--- /dev/null
+++ b/dh_checksums
@@ -0,0 +1,118 @@
+#!/usr/bin/perl -w
+
+=head1 NAME
+
+dh_checksums - generate the DEBIAN/<algo sums> file
+
+=cut
+
+use strict;
+use Cwd;
+use Debian::Debhelper::Dh_Lib;
+
+=head1 SYNOPSIS
+
+B<dh_checksums> [S<I<debhelper options>>] [B<-x>] [B<-X>I<item>] [B<--include-conffiles>] [B<--alg=>I<algorithm>]
+
+=head1 DESCRIPTION
+
+B<dh_checksums> is a debhelper program that is responsible for generating
+a checksums file, which lists the hashes of each file in the package.
+These files are used by the B<debsums> package.
+
+All files in F<DEBIAN/> are omitted from the F<checksums> file, as are all
+conffiles (unless you use the B<--include-conffiles> switch).
+
+The checksums file is installed with proper permissions and ownerships.
+
+=head1 OPTIONS
+
+=over 4
+
+=item B<-x>, B<--include-conffiles>
+
+Include conffiles in the checksums 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 checksums file.
+
+=item B<--alg=>I<algorithm>
+
+Used to override the default hash algorithm (md5).  The current set
+of valid hash algorithms are: b<md5>, b<sha256>, b<sha512>
+
+=back
+
+=cut
+
+init(options => {
+	"x" => \$dh{INCLUDE_CONFFILES}, # is -x for some unknown historical reason..
+	"include-conffiles" => \$dh{INCLUDE_CONFFILES},
+	"alg=s" => \$dh{ALG},
+});
+
+if (defined $dh{ALG}) {
+	my @algorithms = <md5 sha256 sha512>;
+	use List::MoreUtils 'any';
+	$dh{ALG}="sha256" unless any { /$dh{ALG}/ } @algorithms;
+} else {
+	$dh{ALG}="md5";
+}
+my $HASHCMD = $dh{ALG}."sum";
+my $hashsums = $dh{ALG}."sums";
+
+foreach my $package (@{$dh{DOPACKAGES}}) {
+	next if is_udeb($package);
+
+	my $tmp=tmpdir($package);
+
+	if (! -d "$tmp/DEBIAN") {
+		doit("install","-d","$tmp/DEBIAN");
+	}
+
+	# Check if we should exclude conffiles.
+	my $exclude="";
+	if (! $dh{INCLUDE_CONFFILES} && -r "$tmp/DEBIAN/conffiles") {
+		# Generate exclude regexp.
+		open (CONFF,"$tmp/DEBIAN/conffiles");
+		while (<CONFF>) {
+			chomp;
+			s/^\///;
+			$exclude.="! -path \"./$_\" ";
+		}
+		close CONFF;
+	}
+
+	# 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 $HASHCMD > DEBIAN/$hashsums) >/dev/null");
+	# If the file's empty, no reason to waste inodes on it.
+	if (-z "$tmp/DEBIAN/$hashsums") {
+		doit("rm","-f","$tmp/DEBIAN/$hashsums");
+	}
+	else {
+		doit("chmod",644,"$tmp/DEBIAN/$hashsums");
+		doit("chown","0:0","$tmp/DEBIAN/$hashsums");
+	}
+}
+
+=head1 SEE ALSO
+
+L<debhelper(7)>
+
+This program is a part of debhelper.
+
+=head1 AUTHOR
+
+Joey Hess <joeyh at debian.org>
+
+(Modified by Mimi Zohar <zohar at linux.vnet.ibm.com> to support other digests)
+
+=cut
diff --git a/dh_md5sums b/dh_md5sums
deleted file mode 100755
index 4a1264b..0000000
--- a/dh_md5sums
+++ /dev/null
@@ -1,100 +0,0 @@
-#!/usr/bin/perl -w
-
-=head1 NAME
-
-dh_md5sums - generate DEBIAN/md5sums file
-
-=cut
-
-use strict;
-use Cwd;
-use Debian::Debhelper::Dh_Lib;
-
-=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 the B<debsums> package.
-
-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},
-});
-
-foreach my $package (@{$dh{DOPACKAGES}}) {
-	next if is_udeb($package);
-	
-	my $tmp=tmpdir($package);
-
-	if (! -d "$tmp/DEBIAN") {
-		doit("install","-d","$tmp/DEBIAN");
-	}
-
-	# Check if we should exclude conffiles.
-	my $exclude="";
-	if (! $dh{INCLUDE_CONFFILES} && -r "$tmp/DEBIAN/conffiles") {
-		# Generate exclude regexp.
-		open (CONFF,"$tmp/DEBIAN/conffiles");
-		while (<CONFF>) {
-			chomp;
-			s/^\///;
-			$exclude.="! -path \"./$_\" ";
-		}
-		close CONFF;
-	}
-	
-	# 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 > DEBIAN/md5sums) >/dev/null");
-	# If the file's empty, no reason to waste inodes on it.
-	if (-z "$tmp/DEBIAN/md5sums") {
-		doit("rm","-f","$tmp/DEBIAN/md5sums");
-	}
-	else {
-		doit("chmod",644,"$tmp/DEBIAN/md5sums");
-		doit("chown","0:0","$tmp/DEBIAN/md5sums");
-	}
-}
-
-=head1 SEE ALSO
-
-L<debhelper(7)>
-
-This program is a part of debhelper.
-
-=head1 AUTHOR
-
-Joey Hess <joeyh at debian.org>
-
-=cut
diff --git a/man/po4a/po4a.cfg b/man/po4a/po4a.cfg
index 311762f..b89ca37 100644
--- a/man/po4a/po4a.cfg
+++ b/man/po4a/po4a.cfg
@@ -13,6 +13,7 @@
 [type: pod] dh_auto_test	$lang:man/$lang/dh_auto_test.pod	add_fr:man/po4a/add.fr	add_es:man/po4a/add3.es  add_de:man/po4a/add.de  add_pt:man/po4a/add.pt
 [type: pod] dh_bugfiles		$lang:man/$lang/dh_bugfiles.pod		add_fr:man/po4a/add.fr	add_es:man/po4a/add3.es  add_de:man/po4a/add.de  add_pt:man/po4a/add.pt
 [type: pod] dh_builddeb 	$lang:man/$lang/dh_builddeb.pod		add_fr:man/po4a/add.fr	add_es:man/po4a/add1.es  add_de:man/po4a/add.de  add_pt:man/po4a/add.pt
+[type: pod] dh_checksums	$lang:man/$lang/dh_checksums.pod	add_fr:man/po4a/add.fr	add_es:man/po4a/add2.es  add_de:man/po4a/add.de  add_pt:man/po4a/add.pt
 [type: pod] dh_clean 		$lang:man/$lang/dh_clean.pod		add_fr:man/po4a/add.fr	add_es:man/po4a/add1.es  add_de:man/po4a/add.de  add_pt:man/po4a/add.pt
 [type: pod] dh_compress 	$lang:man/$lang/dh_compress.pod		add_fr:man/po4a/add.fr	add_es:man/po4a/add1.es  add_de:man/po4a/add.de  add_pt:man/po4a/add.pt
 [type: pod] dh_desktop		$lang:man/$lang/dh_desktop.pod		add_fr:man/po4a/add.fr	add_es:man/po4a/add1.es  add_de:man/po4a/add.de  add_pt:man/po4a/add.pt
@@ -49,7 +50,6 @@
 [type: pod] dh_lintian		$lang:man/$lang/dh_lintian.pod		add_fr:man/po4a/add.fr	add_es:man/po4a/add2.es  add_de:man/po4a/add.de  add_pt:man/po4a/add.pt
 [type: pod] dh_listpackages	$lang:man/$lang/dh_listpackages.pod	add_fr:man/po4a/add.fr	add_es:man/po4a/add2.es  add_de:man/po4a/add.de  add_pt:man/po4a/add.pt
 [type: pod] dh_makeshlibs	$lang:man/$lang/dh_makeshlibs.pod	add_fr:man/po4a/add.fr	add_es:man/po4a/add2.es  add_de:man/po4a/add.de  add_pt:man/po4a/add.pt
-[type: pod] dh_md5sums		$lang:man/$lang/dh_md5sums.pod		add_fr:man/po4a/add.fr	add_es:man/po4a/add2.es  add_de:man/po4a/add.de  add_pt:man/po4a/add.pt
 [type: pod] dh_movefiles	$lang:man/$lang/dh_movefiles.pod	add_fr:man/po4a/add.fr	add_es:man/po4a/add2.es  add_de:man/po4a/add.de  add_pt:man/po4a/add.pt
 [type: pod] dh_perl		$lang:man/$lang/dh_perl.pod		add_fr:man/po4a/add.fr	add_es:man/po4a/add2.es  add_de:man/po4a/add.de  add_pt:man/po4a/add.pt
 [type: pod] dh_prep		$lang:man/$lang/dh_prep.pod		add_fr:man/po4a/add.fr	add_es:man/po4a/add2.es  add_de:man/po4a/add.de  add_pt:man/po4a/add.pt
-- 
1.8.1.4




More information about the debhelper-devel mailing list