]> git.deb.at Git - deb/packages.git/blob - bin/build-maintainerdb
9125664822f9c9aa617e5a25a20903da0aa4a06b
[deb/packages.git] / bin / build-maintainerdb
1 #! /usr/bin/perl
2
3 #   build-maintainerdb - convert several Packages files to maintainer database
4 #   Copyright (c) 1998,9,2001,3,4,6  Martin Schulze <joey@debian.org>
5 #
6 #   This program is free software; you can redistribute it and/or modify
7 #   it under the terms of the GNU General Public License as published by
8 #   the Free Software Foundation; either version 2 of the License, or
9 #   (at your option) any later version.
10 #
11 #   This program is distributed in the hope that it will be useful,
12 #   but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 #   GNU General Public License for more details.
15 #
16 #   You should have received a copy of the GNU General Public License
17 #   along with this program; if not, write to the Free Software
18 #   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20 #   Todo:
21 #    . Read maintainer changes from overrides file(s), need to rub
22 #      out all existing entries
23
24 use strict;
25 use warnings;
26
27 # read the configuration
28 if (!open (C, "../config.sh")) {
29     print "\nInternal Error: Cannot open configuration file.\n\n";
30     exit 0;
31 }
32 my $topdir = "/org/packages.debian.org";
33 while (<C>) {
34     $topdir = $1 if (/^\s*topdir="?(.*)"?\s*$/);
35 }
36 close (C);
37
38 my $maildomain = "packages.debian.org";
39
40 my $maintainerfile = "$topdir/archive/Maintainers";
41 my $maintainerdb = "$topdir/conf/maintainer";
42 my $overridefile = "$topdir/conf/maintainerdb.override";
43 my @postcall = ( "/usr/sbin/postmap", $maintainerdb );
44 my $opt_verbose = 0;
45
46 my %maint;
47
48 sub package_maintainer
49 {
50     my $pkg = shift;
51     my $login = shift;
52     my $addr = shift;
53     my $home = "/debian/home/$login";
54
55     if (-d $home) {
56         if (-f "$home/.forward-$pkg") {
57             return "$login-$pkg\@master.debian.org";
58         }
59     }
60     return $addr;
61 }
62
63 sub read_maintainer
64 {
65     my $file = shift;
66     my $package;
67     my $maintainer;
68     my $maint;
69
70     open (F, "$file") || die "Can't open $file, $!";
71     printf "Reading %s\n", $file if ($opt_verbose);
72     while (<F>) {
73         next if (/^#/);
74         next if (/^$/);
75         /(\S+)\s+(.*)/;
76         $package=$1; $maint=$2;
77         if (! exists $maint{$package}) {
78             printf "  EVAL (%s, \"%s\")\n", $package, $maint if ($opt_verbose > 2);
79
80                 if (exists $maint{$package}) {
81                     $maint{$package} .= " ";
82                     printf "  EXPAND (%s)\n", $package if ($opt_verbose > 2);
83                 }
84                 if ($maint =~ /.*<(.*)>/) {
85                     $maint{$package} .= $1;
86                     printf "  ADD (%s, %s)\n", $package, $1 if ($opt_verbose > 2);
87                 } elsif ($maint =~ /\s*(\S+)\s+\(.*\)/) {
88                     $maint{$package} .= $1;
89                     printf "  ADD (%s, %s)\n", $package, $1 if ($opt_verbose > 2);
90                 } else {
91                     $maint{$package} .= $maint;
92                     printf "  ADD (%s, %s)\n", $package, $maint if ($opt_verbose > 2);
93                 }
94
95             printf "  %s: %s\n", $package, $maint{$package} if ($opt_verbose > 1);
96             my $pkgshort = "";
97             if ($package =~ /(.*[^\d\.]+)([\d\.]*\d)$/) {
98                 $pkgshort = $1;
99                 $maint{$pkgshort} = $maint{$package} if (! exists $maint{$pkgshort});
100                 printf "  %s: %s\n", $pkgshort, $maint{$package} if ($opt_verbose > 1);
101             }
102             if ($maint{$package} =~ /([^\@]+)\@(master\.)?debian\.org/) {
103                 my $addrsave = $maint{$package} if ($opt_verbose > 1);
104                 $maint{$package} = package_maintainer ($package, $1, $maint{$package});
105                 printf "  Changed to %s\n", $maint{$package} if ($opt_verbose > 1 && ($addrsave ne $maint{$package}));
106                 if (length ($pkgshort) > 0) {
107                     $maint{$pkgshort} = package_maintainer ($pkgshort, $1, $maint{$pkgshort});
108                 }
109             }
110         } else {
111             printf "Skipping double $package\n" if ($opt_verbose);
112             printf "LINE: $_" if ($opt_verbose > 2);
113         }
114     }
115     close (F);
116 }
117
118 sub write_maintainer
119 {
120     my $file = shift;
121
122     printf "Writing to %s.new\n", $file if ($opt_verbose > 0);
123     open (CONF, ">$file.new") || die "Can't open $file.new, $!";
124     foreach my $package (sort(keys(%maint))) {
125         printf "%s -> %s\n", $package, $maint{$package} if ($opt_verbose > 1);
126         printf CONF "%s@%s\t%s\n", $package, $maildomain, $maint{$package};
127     }
128     close (CONF);
129     printf "Renaming to %s\n", $file if ($opt_verbose > 0);
130     system "mv -f $file.new $file";
131     printf "Executing @postcall\n" if ($opt_verbose > 0);
132     system @postcall;
133 }
134
135 sub help
136 {
137     print "build-maintainerdb - Build the maintainer db for packages.debian.org.\n";
138     print "-d     debug, changes output file to ./maintainerdb\n";
139     print "-h     This help\n";
140     print "-v     Increase verbosity by 1\n";
141     print "-vv    Increase verbosity by 2\n";
142     print "-vvv   Increase verbosity by 3\n";
143 }
144
145
146 # Main program
147 #
148 while ($#ARGV > -1) {
149     if ($ARGV[0] eq "-v") {
150         $opt_verbose++;
151     } elsif ($ARGV[0] eq "-vv") {
152         $opt_verbose+= 2;
153     } elsif ($ARGV[0] eq "-vvv") {
154         $opt_verbose+= 3;
155     } elsif ($ARGV[0] eq "-h") {
156         help();
157     } elsif ($ARGV[0] eq "-d") {
158         $maintainerdb = "./maintainerdb";
159     }
160     shift;
161 }
162
163 &read_maintainer ($overridefile);
164 &read_maintainer ($maintainerfile);
165
166 &write_maintainer ($maintainerdb);
167