2 # unpack-binpkg-l1 -- maemian 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{'MAEMIAN_ROOT'}/lib";
36 use Maemian::Command qw(spawn reap);
39 (my @stat = stat $file) or fail("$file: cannot stat: $!");
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: $!");
50 # The following calls use knowledge of the .deb format for speed
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']);
58 $job = { fail => 'error', err => "$base_dir/control-errors" };
60 # extract the tarball's contents
62 ["tar", "xf", "$base_dir/control.tar", "-C", "$base_dir/control", '&']);
64 $job = { fail => 'error',
65 out => "$base_dir/control-index",
66 err => "$base_dir/control-index-errors" };
68 # create index of control.tar.gz
70 ["tar", "tvf", "$base_dir/control.tar"],
71 '|', ["sort", "-k", "6"], '&');
75 # clean up control.tar
76 unlink("$base_dir/control.tar") or fail();
79 spawn({ fail => 'error' },
80 ["chmod", "-R", "u+rX,o-w", "$base_dir/control"]);
82 $job = { fail => 'error',
83 out => "$base_dir/index",
84 err => "$base_dir/index-errors" };
86 # (replaces dpkg-deb -c)
87 # create index file for package
89 ["dpkg-deb", "--fsys-tarfile", $file ],
90 '|', ["tar", "tfv", "-"],
91 '|', ["sed", "-e", "s/^h/-/"],
92 '|', ["sort", "-k", "6"], '&');
94 $job = { fail => 'error',
95 out => "$base_dir/index-owner-id",
98 # (replaces dpkg-deb -c)
99 # create index file for package with owner IDs instead of names
101 ["dpkg-deb", "--fsys-tarfile", $file],
102 '|', ["tar", "--numeric-owner", "-tvf", "-"],
103 '|', ["sed", "-e", "s/^h/-/"],
104 '|', ["sort", "-k", "6"], '&');
106 # get package control information
107 my $data = (read_dpkg_control("$base_dir/control/control"))[0];
108 $data->{'source'} or ($data->{'source'} = $data->{'package'});
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";
118 # create symlink to source package
119 $data->{'source'} =~ s/\s*\(.*\)\s*$//;
120 symlink("../../source/$data->{'source'}","$base_dir/source")
121 or fail("symlink: $!");