File: sum-packages

package info (click to toggle)
debmirror 1%3A2.47
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 488 kB
  • sloc: perl: 2,765; sh: 93; makefile: 19
file content (75 lines) | stat: -rwxr-xr-x 2,497 bytes parent folder | download
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/perl
use warnings;
use strict;
use integer;
use FindBin;

our @kind = (
    { cmd => 'md5sum'   , name => 'MD5sum' },
    { cmd => 'sha1sum'  , name => 'SHA1'   },
    { cmd => 'sha256sum', name => 'SHA256' },
);

@ARGV == 5 or die "usage: $0"
 . " [OLD-PACKAGES-FILE] [OLD-I18N-DIRECTORY]"
 . " [NEW-PACKAGES-FILE] [NEW-I18N-DIRECTORY] [NEW-ARCHIVE-DIRECTORY]\n";
my ($file_pkg1, $dir_i18n1, $file_pkg2, $dir_i18n2, $dir_arc) = @ARGV;

my @file_i18n;
opendir my $dir, $dir_i18n1 or die "$0: cannot open i18n directory\n";
while(readdir $dir) {
    push @file_i18n, $_
      unless $_ eq "Translation-en" || $_ eq '.' || $_ eq '..';
}
closedir $dir;

local $/ = '';
my %md; # md5sums of package descriptions

for my $basename ('Translation-en', @file_i18n) {
    open my $f1, '<', "$dir_i18n1/$basename"
      or die "$0: failed to open i18n source directory";
    open my $f2, '>', "$dir_i18n2/$basename"
      or die "$0: failed to open i18n destination directory";
    my $tempfilename = `mktemp`; chomp $tempfilename;
    open my $temp, '>', $tempfilename; close $temp;
    while (<$f1>) {
        my ($pkg) = /^Package:\s*(\S+)$/m;
        my ($desc) = /^Description-(?!md5:)\w+: (.*\n(?: .*\n)*)/m;
        open my $temp, '>', $tempfilename;
        print $temp $desc;
        close $temp;
        # The following probably should have been done using Perl's
        # Digest::MD5 module, but the matter is unimportant and the
        # writer lacks time to reconsider the design.  This is just
        # uninstalled test software, after all.
        my $md = `md5sum <$tempfilename`; chomp $md; $md =~ s/^(\S+).*$/$1/;
        s/^(Description-md5:).*/$1 $md/m;
        print $f2 $_;
        $md{$pkg} = $md if $basename eq 'Translation-en';
        (defined($md) && defined($pkg)) or die "$0: missing fields in i18n\n";
    }
    unlink $tempfilename;
    close $f2;
    close $f1;
}

open my $f1, '<', $file_pkg1
  or die "$0: failed to open Packages source file";
open my $f2, '>', $file_pkg2
  or die "$0: failed to open Packages destination file";
while (<$f1>) {
    my ($pkg) = /^Package:\s*(\S+)$/m;
    s/^(Description-md5:).*$/$1 ${md{$pkg}}/m if defined $md{$pkg};
    my ($fn) = /^Filename:\s*(\S+)/m;
    for my $kind (@kind) {
        my ($sum) = `$kind->{cmd} $dir_arc/$fn` =~ /(\S+)/;
        s/^($kind->{name}:).*/$1 $sum/m;
    }
    my @stat = stat "$dir_arc/$fn";
    my $size = $stat[7];
    s/^(Size:).*$/$1 $size/m;
    print $f2 $_;
}
close $f2;
close $f1;