summaryrefslogtreecommitdiffstats
path: root/debian/template-md5sum
blob: e043a82b00d0f7225c0e25607e040a1cfa2e6378 (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
#!/usr/bin/perl
use IPC::Open2;


	my($template) = @ARGV;
	my $state = 0;

	open(INPUT,$template) || return '';
	my($md5sum_fd,$output_fd);
	my $pid = open2($md5sum_fd, $output_fd, 'md5sum');
	return '' if (!$pid);

	while (<INPUT>) {
		if ($state == 1) {
			if (/^# here's the fallback if no module succeeds/) {
				print $output_fd $_;
				$state++;
			}
			next;
		}
		if ($state == 3) {
			if (/^# end of pam-auth-update config/) {
				print $output_fd $_;
				$state++;
			}
			next;
		}

		print $output_fd $_;

		my ($pattern,$val);
		if ($state == 0) {
			$pattern = '^# here are the per-package modules \(the "Primary" block\)';
		} elsif ($state == 2) {
			$pattern = '^# and here are more per-package modules \(the "Additional" block\)';
		} else {
			next;
		}

		if (/$pattern/) {
			$state++;
		}
	}
	close(INPUT);
	close($output_fd);
	my $md5sum = <$md5sum_fd>;
	close($md5sum_fd);
	waitpid $pid, 0;

	$md5sum = (split(/\s+/,$md5sum))[0];
	print $md5sum;