summaryrefslogtreecommitdiff
path: root/dh_md5sums
blob: 80b5f4794f9f3014af5d4621a40c2722f931ba61 (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
#!/usr/bin/perl -w
#
# Generate a DEBIAN/md5sums file, that lists the md5sums of all files in the
# package.

use Cwd;
BEGIN { push @INC, "debian", "/usr/share/debhelper" }
use Dh_Lib;
init();

foreach $PACKAGE (@{$dh{DOPACKAGES}}) {
	$TMP=tmpdir($PACKAGE);

	if (! -d "$TMP/DEBIAN") {
		doit("install","-d","$TMP/DEBIAN");
	}

	# Check if we should exclude conffiles.
	my $exclude="";
	if (! $dh{INCLUDE} && -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} \\) ";
	}
	
	$olddir=getcwd();
	complex_doit("cd $TMP >/dev/null ; find * -type f $exclude ! -regex '^DEBIAN/.*' -print0 | xargs -r0 md5sum > DEBIAN/md5sums ; cd $olddir >/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","root.root","$TMP/DEBIAN/md5sums");
	}
}