Added lots more modules from lintian. Maemian appears to work.
[maemian] / unpack / unpack-binpkg-l1
1 #!/usr/bin/perl
2 # unpack-binpkg-l1 -- maemian 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{'MAEMIAN_ROOT'}/lib";
35 use Util;
36 use Maemian::Command qw(spawn reap);
37
38 # stat $file
39 (my @stat = stat $file) or fail("$file: cannot stat: $!");
40
41 my (@jobs, $job);
42
43 # create directory in lab
44 print "N: Creating directory $base_dir ...\n" if $verbose;
45 mkdir("$base_dir", 0777) or fail("mkdir $base_dir: $!");
46 mkdir("$base_dir/control", 0777) or fail("mkdir $base_dir/control: $!");
47 mkdir("$base_dir/fields", 0777) or fail("mkdir $base_dir/fields: $!");
48 symlink($file,"$base_dir/deb") or fail("symlink: $!");
49
50 # The following calls use knowledge of the .deb format for speed
51
52 # (replaces dpkg-deb -e)
53 # extract control files' tarball
54 spawn({ fail => 'error', out => "$base_dir/control.tar" },
55       ['ar', 'p', $file, 'control.tar.gz'],
56       '|', ['gzip', '-dc']);
57
58 $job = { fail => 'error', err => "$base_dir/control-errors" };
59 push @jobs, $job;
60 # extract the tarball's contents
61 spawn($job,
62       ["tar", "xf", "$base_dir/control.tar", "-C", "$base_dir/control", '&']);
63
64 $job = { fail => 'error',
65          out  => "$base_dir/control-index",
66          err  => "$base_dir/control-index-errors" };
67 push @jobs, $job;
68 # create index of control.tar.gz
69 spawn($job,
70       ["tar", "tvf", "$base_dir/control.tar"],
71       '|', ["sort", "-k", "6"], '&');
72
73 reap(@jobs);
74 undef @jobs;
75 # clean up control.tar
76 unlink("$base_dir/control.tar") or fail();
77
78 # fix permissions
79 spawn({ fail => 'error' },
80       ["chmod", "-R", "u+rX,o-w", "$base_dir/control"]);
81
82 $job = { fail => 'error',
83          out  => "$base_dir/index",
84          err  => "$base_dir/index-errors" };
85 push @jobs, $job;
86 # (replaces dpkg-deb -c)
87 # create index file for package
88 spawn($job,
89       ["dpkg-deb", "--fsys-tarfile", $file ],
90       '|', ["tar", "tfv", "-"],
91       '|', ["sed", "-e", "s/^h/-/"],
92       '|', ["sort", "-k", "6"], '&');
93
94 $job = { fail => 'error',
95          out  => "$base_dir/index-owner-id",
96          err  => '/dev/null' };
97 push @jobs, $job;
98 # (replaces dpkg-deb -c)
99 # create index file for package with owner IDs instead of names
100 spawn($job,
101       ["dpkg-deb", "--fsys-tarfile", $file],
102       '|', ["tar", "--numeric-owner", "-tvf", "-"],
103       '|', ["sed", "-e", "s/^h/-/"],
104       '|', ["sort", "-k", "6"], '&');
105
106 # get package control information
107 my $data = (read_dpkg_control("$base_dir/control/control"))[0];
108 $data->{'source'} or ($data->{'source'} = $data->{'package'});
109
110 # create control field files
111 for my $field (keys %$data) {
112     my $field_file = "$base_dir/fields/$field";
113     open(F, '>', $field_file) or fail("cannot open file $field_file for writing: $!");
114     print F $data->{$field},"\n";
115     close(F);
116 }
117
118 # create symlink to source package
119 $data->{'source'} =~ s/\s*\(.*\)\s*$//;
120 symlink("../../source/$data->{'source'}","$base_dir/source")
121     or fail("symlink: $!");
122
123 reap(@jobs);
124 undef @jobs;
125
126 exit 0;