On Wed, 2010-03-10 at 23:19 +0100, Frank Lin PIAT wrote:
> Hello,
> 
> On Mon, 2010-03-08 at 17:36 +0100, Frank Lin PIAT wrote:
> > On Thu, 2010-03-04 at 20:08 +0100, Tollef Fog Heen wrote:
> > >  Frank Lin PIAT wrote:
> > > > What about a transitional dh_md5sums that would produce md5sum AND
> > > > invoke dh_sha ?
> > > 
> > > Or call it dh_checksums or something so we don't have to change the tool
> > > name each time we decide to change the algorithm.
> > 
> > Find a patch attached, for a smooth transition from DEBIAN/md5sums to a
> > recent checksum.
> 
> 
> Since SHA algorithms is a family, tools and API usually implement...

The patch was incomplete... here it is.
(it also include a fix for and eq/== error in my code)

Franklin
From 719c77dd8531e3edc09471398a4f63e0fae29215 Mon Sep 17 00:00:00 2001
From: Frank Lin PIAT <fp...@klabs.be>
Date: Mon, 8 Mar 2010 16:35:39 +0100
Subject: [PATCH] Implement dh_checksums.

---
 debian/copyright |    2 +-
 debian/links     |    3 +++
 dh               |    2 +-
 dh_md5sums       |   41 +++++++++++++++++++++++++++++++++--------
 4 files changed, 38 insertions(+), 10 deletions(-)
 create mode 100644 debian/links

diff --git a/debian/copyright b/debian/copyright
index a9f950d..162bfc0 100644
--- a/debian/copyright
+++ b/debian/copyright
@@ -48,7 +48,7 @@ Copyright: Steve Robbins <s...@debian.org>
 License: GPL-2+
 
 Files: dh_md5sums
-Copyright: Charles Briscoe-Smith <c...@ukc.ac.uk>
+Copyright: Charles Briscoe-Smith <c...@ukc.ac.uk>, Frank Lin PIAT 
<fp...@klabs.be>
 License: GPL-2+
 
 Files: dh_bugfiles
diff --git a/debian/links b/debian/links
new file mode 100644
index 0000000..3e7d603
--- /dev/null
+++ b/debian/links
@@ -0,0 +1,3 @@
+usr/share/man/man1/dh_md5sums.1.gz usr/share/man/man1/dh_checksums.1.gz
+usr/bin/dh_md5sums usr/bin/dh_checksums
+
diff --git a/dh b/dh
index bcac8da..0aa9bc3 100755
--- a/dh
+++ b/dh
@@ -322,7 +322,7 @@ $sequences{install} = [...@{$sequences{build}}, qw{
 my @b=qw{
        dh_installdeb
        dh_gencontrol
-       dh_md5sums
+       dh_checksums
        dh_builddeb
 };
 $sequences{'binary-indep'} = [...@{$sequences{install}}, @b];
diff --git a/dh_md5sums b/dh_md5sums
index da00090..da0d568 100755
--- a/dh_md5sums
+++ b/dh_md5sums
@@ -2,7 +2,7 @@
 
 =head1 NAME
 
-dh_md5sums - generate DEBIAN/md5sums file
+dh_checksums - generate DEBIAN/*sums files (md5, sha256)
 
 =cut
 
@@ -12,18 +12,24 @@ use Debian::Debhelper::Dh_Lib;
 
 =head1 SYNOPSIS
 
+B<dh_checksums> [S<I<debhelper options>>] [B<-x>] [B<-X>I<item>] 
[B<--include-conffiles>]
+
 B<dh_md5sums> [S<I<debhelper options>>] [B<-x>] [B<-X>I<item>] 
[B<--include-conffiles>]
 
 =head1 DESCRIPTION
 
-dh_md5sums is a debhelper program that is responsible for generating
-a DEBIAN/md5sums file, which lists the md5sums of each file in the package.
-These files are used by the debsums package.
+dh_checksums is a debhelper program that is responsible for generating
+a DEBIAN/md5sums and DEBIAN/shasums files, which respectively lists the
+md5sums and shasums of each file in the package. These files are used
+by the debsums package.
 
-All files in DEBIAN/ are omitted from the md5sums file, as are all
+All files in DEBIAN/ are omitted from the checksums files, as are all
 conffiles (unless you use the --include-conffiles switch).
 
-The md5sums file is installed with proper permissions and ownerships.
+The checksums files are installed with proper permissions and ownerships.
+
+dh_md5sums is deprecated, you should use dh_checksums instead, which generates 
the
+type of checksums files recommended by the Debian policy.
 
 =head1 OPTIONS
 
@@ -37,7 +43,7 @@ redundant since it is included elsewhere in debian packages.
 =item B<-X>I<item>, B<--exclude=>I<item>
 
 Exclude files that contain "item" anywhere in their filename from
-being listed in the md5sums file.
+being listed in the checkums file.
 
 =back
 
@@ -48,15 +54,26 @@ init(options => {
        "include-conffiles" => \$dh{INCLUDE_CONFFILES},
 });
 
+my ($basename) = $0=~m:.*/(.+):;
+
 foreach my $package (@{$dh{DOPACKAGES}}) {
        next if is_udeb($package);
-       
+
+       if (basename($0) eq 'dh_md5sums') {
+               warning("This program should no longer be used. Please read the 
dh_checksums(1) man page.");
+       }
+
        my $tmp=tmpdir($package);
 
        if (! -d "$tmp/DEBIAN") {
                doit("install","-d","$tmp/DEBIAN");
        }
 
+       # Detect if this is run multiple times (calling both dh_md5sums and 
dh_checksums?)
+       if (-f "$tmp/DEBIAN/md5sums" or -f "$tmp/DEBIAN/shasums") {
+               warning("Re-computing checksum file (even though md5sums and/or 
shasums exists)");
+       }
+
        # Check if we should exclude conffiles.
        my $exclude="";
        if (! $dh{INCLUDE_CONFFILES} && -r "$tmp/DEBIAN/conffiles") {
@@ -76,6 +93,7 @@ foreach my $package (@{$dh{DOPACKAGES}}) {
        }
        
        complex_doit("(cd $tmp >/dev/null ; find . -type f $exclude ! -regex 
'.*/DEBIAN/.*' -printf '%P\\0' | xargs -r0 md5sum > DEBIAN/md5sums) 
>/dev/null");
+       complex_doit("(cd $tmp >/dev/null ; find . -type f $exclude ! -regex 
'.*/DEBIAN/.*' -printf '%P\\0' | xargs -r0 sha256sum > DEBIAN/shasums) 
>/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");
@@ -84,6 +102,13 @@ foreach my $package (@{$dh{DOPACKAGES}}) {
                doit("chmod",644,"$tmp/DEBIAN/md5sums");
                doit("chown","0:0","$tmp/DEBIAN/md5sums");
        }
+       if (-z "$tmp/DEBIAN/shasums") {
+               doit("rm","-f","$tmp/DEBIAN/shasums");
+       }
+       else {
+               doit("chmod",644,"$tmp/DEBIAN/shasums");
+               doit("chown","0:0","$tmp/DEBIAN/shasums");
+       }
 }
 
 =head1 SEE ALSO
-- 
1.7.0

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to