2 # changelog-file -- maemian collector script
4 # Copyright (C) 1998 Richard Braakman
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.
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.
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,
24 use lib "$ENV{'MAEMIAN_ROOT'}/lib";
27 ($#ARGV == 1) or fail("syntax: changelog-file <pkg> <type>");
31 -f "fields/package" or fail("changelog-file invoked in wrong directory");
35 # Pick the first of these files that exists.
36 my @changelogs = ("unpacked/usr/share/doc/$pkg/changelog.Debian.gz",
37 "unpacked/usr/share/doc/$pkg/changelog.Debian",
38 "unpacked/usr/share/doc/$pkg/changelog.debian.gz",
39 "unpacked/usr/share/doc/$pkg/changelog.debian",
40 "unpacked/usr/share/doc/$pkg/changelog.gz",
41 "unpacked/usr/share/doc/$pkg/changelog",
42 "unpacked/usr/doc/$pkg/changelog.Debian.gz",
43 "unpacked/usr/doc/$pkg/changelog.Debian",
44 "unpacked/usr/doc/$pkg/changelog.debian.gz",
45 "unpacked/usr/doc/$pkg/changelog.debian",
46 "unpacked/usr/doc/$pkg/changelog.gz",
47 "unpacked/usr/doc/$pkg/changelog");
58 # If the changelog file we found was a symlink, we have to be careful. It
59 # could be a symlink to some file outside of the laboratory and we don't want
60 # to end up reading that file by mistake. Relative links within the same
61 # directory or to a subdirectory we accept; anything else is replaced by an
62 # intentinally broken symlink so that checks can do the right thing.
63 if (defined ($chl) && -l $chl) {
64 my $link = readlink $chl or fail("cannot readlink $chl: $!");
65 if ($link =~ /\.\./ || ($link =~ m%/% && $link !~ m%^[^/]+(/+[^/]+)*\z%)) {
66 symlink('file-is-in-another-package', 'changelog')
67 or fail("cannot create changelog symlink: $!");
74 # If the changelog was a broken symlink, it will be undefined and we'll now
75 # treat it the same as if we didn't find a changelog and do nothing. If it
76 # was a symlink, copy the file, since otherwise the relative symlinks are
77 # going to break things.
78 if (not defined $chl) {
80 } elsif ($chl =~ /\.gz$/) {
81 gunzip_file($chl, 'changelog');
82 } elsif (-f $chl && -l $chl) {
84 open (CHL, '<', $chl) or fail("cannot open $chl: $!");
85 open (COPY, '>', 'changelog') or fail("cannot create changelog: $!");
86 print COPY while <CHL>;
90 link($chl, "changelog")
91 or fail("cannot link $chl to changelog: $!");
94 # Extract NEWS.Debian files as well, with similar precautious. Ignore any
95 # symlinks to other packages here; in that case, we just won't check the file.
96 unlink('NEWS.Debian');
97 my $news = "unpacked/usr/share/doc/$pkg/NEWS.Debian.gz";
100 my $link = readlink $news or fail("cannot readlink $chl: $!");
101 if ($link =~ /\.\./ || ($link =~ m%/% && $link !~ m%^[^/]+(/+[^/]+)*\z%)) {
103 } elsif (! -f $news) {
108 gunzip_file($news, "NEWS.Debian");