Added lots more modules from lintian. Maemian appears to work.
[maemian] / collection / copyright-file
1 #!/usr/bin/perl -w
2 # copyright-file -- maemian collector script
3
4 # Copyright (C) 1998 Richard Braakman
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, you can find it on the World Wide
18 # Web at http://www.gnu.org/copyleft/gpl.html, or write to the Free
19 # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
20 # MA 02110-1301, USA.
21
22 use strict;
23
24 use lib "$ENV{'MAEMIAN_ROOT'}/lib";
25 use Util;
26
27 use File::Copy qw(copy);
28
29 ($#ARGV == 1) or fail("syntax: copyright-file <pkg> <type>");
30 my $pkg = shift;
31 my $type = shift;
32
33 -f "fields/package" or fail("copyright-file invoked in wrong directory");
34
35 unlink("copyright");
36
37 my $file1 = "unpacked/usr/share/doc/$pkg/copyright";
38 my $file2 = "unpacked/usr/doc/$pkg/copyright";
39
40 my $file;
41 if (-f $file1 ) { $file = $file1; }
42 else { $file = $file2; }
43
44 # If copyright was a symlink, we need to make a copy of it.  Just hardlinking
45 # to the symlink may leave a relative symlink into a directory we can't
46 # unpack.  Be careful about what symlinks we allow, though.
47 if (-l $file) {
48     my $link = readlink($file) or fail("cannot readlink $file: $!");
49     if ($link =~ /\.\./ || ($link =~ m%/% && $link !~ m%^[^/]+(/+[^/]+)*\z%)) {
50         touch_file("copyright");
51     } else {
52         copy($file, "copyright") or fail("cannot copy $file: $!");
53     }
54 } elsif (-f $file) {
55     link($file, "copyright")
56         or fail("cannot link $file to copyright: $!");
57 } elsif (-f "$file.gz") {
58     gunzip_file($file, 'copyright');
59 } else {
60     # no copyright file found
61     touch_file('copyright');
62 }