Added some code to peer into a data structure in Maemian/Schedule.pm. Also added the
[maemian] / nokia-lintian / unpack / unpack-binpkg-l1
1 #!/usr/bin/perl
2 # unpack-binpkg-l1 -- lintian unpack script (binary packages level 1)
3 #
4 # syntax: unpack-binpkg-l1 <base-dir> <deb-file>
5 #
6 # Note that <deb-file> must be specified with absolute path.
7
8 # Copyright (C) 1998 Christian Schwarz
9 #
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.
14 #
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.
19 #
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,
24 # MA 02110-1301, USA.
25
26 use strict;
27 use vars qw($verbose);
28
29 ($#ARGV == 1) or die "syntax: unpack-binpkg-l1 <base-dir> <deb-file>";
30 my $base_dir = shift;
31 my $file = shift;
32
33 # import perl libraries
34 use lib "$ENV{'LINTIAN_ROOT'}/lib";
35 use Pipeline;
36 use Util;
37
38 # stat $file
39 (my @stat = stat $file) or fail("$file: cannot stat: $!");
40
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: $!");
47
48 # The following calls use knowledge of the .deb format for speed
49
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
55     or fail();
56
57 # extract the tarball's contents
58 spawn("tar", "xf", "$base_dir/control.tar", "-C", "$base_dir/control") == 0
59     or fail();
60
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
65     or fail();
66
67 # clean up control.tar
68 unlink("$base_dir/control.tar") or fail();
69
70 # fix permissions
71 spawn("chmod", "-R", "u+rX,o-w", "$base_dir/control") == 0
72     or fail();
73
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
81     or fail();
82
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
90     or fail();
91
92 # get package control information
93 my $data = (read_dpkg_control("$base_dir/control/control"))[0];
94 $data->{'source'} or ($data->{'source'} = $data->{'package'});
95
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";
101     close(F);
102 }
103
104 # create symlink to source package
105 $data->{'source'} =~ s/\s*\(.*\)\s*$//;
106 symlink("../../source/$data->{'source'}","$base_dir/source")
107     or fail("symlink: $!");
108
109 exit 0;