2 # unpack-binpkg-l1 -- lintian unpack script (binary packages level 1)
4 # syntax: unpack-binpkg-l1 <base-dir> <deb-file>
6 # Note that <deb-file> must be specified with absolute path.
8 # Copyright (C) 1998 Christian Schwarz
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program. If not, you can find it on the World Wide
22 # Web at http://www.gnu.org/copyleft/gpl.html, or write to the Free
23 # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
27 use vars qw($verbose);
29 ($#ARGV == 1) or die "syntax: unpack-binpkg-l1 <base-dir> <deb-file>";
33 # import perl libraries
34 use lib "$ENV{'LINTIAN_ROOT'}/lib";
39 (my @stat = stat $file) or fail("$file: cannot stat: $!");
41 # create directory in lab
42 print "N: Creating directory $base_dir ...\n" if $verbose;
43 mkdir("$base_dir", 0777) or fail("mkdir $base_dir: $!");
44 mkdir("$base_dir/control", 0777) or fail("mkdir $base_dir/control: $!");
45 mkdir("$base_dir/fields", 0777) or fail("mkdir $base_dir/fields: $!");
46 symlink($file,"$base_dir/deb") or fail("symlink: $!");
48 # The following calls use knowledge of the .deb format for speed
50 # (replaces dpkg-deb -e)
51 # extract control files' tarball
52 pipeline((sub { exec 'ar', 'p', $file, 'control.tar.gz' }),
53 (sub { exec 'gzip', '-dc' }),
54 "$base_dir/control.tar") == 0
57 # extract the tarball's contents
58 spawn("tar", "xf", "$base_dir/control.tar", "-C", "$base_dir/control") == 0
61 # create index of control.tar.gz
62 pipeline((sub { exec "tar", "tvf", "$base_dir/control.tar" }),
63 (sub { exec "sort", "-k", "6" }),
64 "$base_dir/control-index") == 0
67 # clean up control.tar
68 unlink("$base_dir/control.tar") or fail();
71 spawn("chmod", "-R", "u+rX,o-w", "$base_dir/control") == 0
74 # (replaces dpkg-deb -c)
75 # create index file for package
76 pipeline((sub { exec "dpkg-deb", "--fsys-tarfile", $file }),
77 (sub { exec "tar", "tfv", "-" }),
78 (sub { exec "sed", "-e", "s/^h/-/" }),
79 (sub { exec "sort", "-k", "6" }),
80 "$base_dir/index") == 0
83 # (replaces dpkg-deb -c)
84 # create index file for package with owner IDs instead of names
85 pipeline((sub { exec "dpkg-deb", "--fsys-tarfile", $file }),
86 (sub { exec "tar", "--numeric-owner", "-tvf", "-" }),
87 (sub { exec "sed", "-e", "s/^h/-/" }),
88 (sub { exec "sort", "-k", "6" }),
89 "$base_dir/index-owner-id") == 0
92 # get package control information
93 my $data = (read_dpkg_control("$base_dir/control/control"))[0];
94 $data->{'source'} or ($data->{'source'} = $data->{'package'});
96 # create control field files
97 for my $field (keys %$data) {
98 my $field_file = "$base_dir/fields/$field";
99 open(F, '>', $field_file) or fail("cannot open file $field_file for writing: $!");
100 print F $data->{$field},"\n";
104 # create symlink to source package
105 $data->{'source'} =~ s/\s*\(.*\)\s*$//;
106 symlink("../../source/$data->{'source'}","$base_dir/source")
107 or fail("symlink: $!");