debian-cd-clone/tools/add_packages

295 lines
7.4 KiB
Plaintext
Raw Normal View History

1999-11-11 16:10:37 -01:00
#!/usr/bin/perl -w
use strict;
Merge of changes from Steve's development branch to take us to debian-cd version 3.0.0. Highlights: * Support now added for multi-arch CDs/DVDs, including mixed binary/source discs. Multi-arch discs should be bootable on those multiple arches, modulo boot-sector clashes. Extra support added in boot-i386 and boot-amd64 to make the 2 main arches happily co-exist. * Disc sizing is now much more intelligent - sizes are defined depending on the disk type chosen at the start, and discs are now filled exactly to those sizes while files are added rather than the old up-front guessing method. Equally, the metadata on the disc (Packages, Packages.gz, Sources, Sources.gz, md5sums.txt) is generated as much as possible while this is happening to make the sizing code incredibly accurate. Using this method of disc sizing means that customising discs should be much easier/safer - either add custom contents at the start and debian-cd will fill the remainder of the disc, or afterwards roll back the packages on the disc and add extras later. * Source is now treated as (almost) just another arch, with most of the special casing for source hidden internally. If asking for source-only discs, they will simply be built using all the available sources. If combined with other arches, the sources will automatically be chosen to match the binary packages. Meeting GPL requirements was never so easy! * Removed lots of old cruft to clean up the codebase: + non-US support + woody support + lots of old support scripts that have been made redundant + significantly simpler Makefile, much easier to follow + old boot-$ARCH.calc files for estimating boot-file sizes are now (obviously) obsolete and therefore gone
2006-12-07 22:09:01 -01:00
use Compress::Zlib;
1999-11-11 16:10:37 -01:00
Merge of changes from Steve's development branch to take us to debian-cd version 3.0.0. Highlights: * Support now added for multi-arch CDs/DVDs, including mixed binary/source discs. Multi-arch discs should be bootable on those multiple arches, modulo boot-sector clashes. Extra support added in boot-i386 and boot-amd64 to make the 2 main arches happily co-exist. * Disc sizing is now much more intelligent - sizes are defined depending on the disk type chosen at the start, and discs are now filled exactly to those sizes while files are added rather than the old up-front guessing method. Equally, the metadata on the disc (Packages, Packages.gz, Sources, Sources.gz, md5sums.txt) is generated as much as possible while this is happening to make the sizing code incredibly accurate. Using this method of disc sizing means that customising discs should be much easier/safer - either add custom contents at the start and debian-cd will fill the remainder of the disc, or afterwards roll back the packages on the disc and add extras later. * Source is now treated as (almost) just another arch, with most of the special casing for source hidden internally. If asking for source-only discs, they will simply be built using all the available sources. If combined with other arches, the sources will automatically be chosen to match the binary packages. Meeting GPL requirements was never so easy! * Removed lots of old cruft to clean up the codebase: + non-US support + woody support + lots of old support scripts that have been made redundant + significantly simpler Makefile, much easier to follow + old boot-$ARCH.calc files for estimating boot-file sizes are now (obviously) obsolete and therefore gone
2006-12-07 22:09:01 -01:00
my $dir;
my $rollback = 0;
my $option = shift;
if ($option =~ /--rollback/) {
$rollback = 1;
$dir = shift;
} else {
$dir = $option;
}
1999-11-11 16:10:37 -01:00
if (! -d $dir) {
die "$dir is not a directory ...";
}
my $mirror = $ENV{'MIRROR'} || die "Set the MIRROR var ...\n";
my $localdebs = $ENV{'LOCALDEBS'} || $mirror;
my $security = $ENV{'SECURITY'} || $mirror;
1999-11-11 16:10:37 -01:00
my $basedir = $ENV{'BASEDIR'} || die "Set the BASEDIR var ...\n";
my $codename = $ENV{'CODENAME'} || die "Set the CODENAME var ...\n";
Merge of changes from Steve's development branch to take us to debian-cd version 3.0.0. Highlights: * Support now added for multi-arch CDs/DVDs, including mixed binary/source discs. Multi-arch discs should be bootable on those multiple arches, modulo boot-sector clashes. Extra support added in boot-i386 and boot-amd64 to make the 2 main arches happily co-exist. * Disc sizing is now much more intelligent - sizes are defined depending on the disk type chosen at the start, and discs are now filled exactly to those sizes while files are added rather than the old up-front guessing method. Equally, the metadata on the disc (Packages, Packages.gz, Sources, Sources.gz, md5sums.txt) is generated as much as possible while this is happening to make the sizing code incredibly accurate. Using this method of disc sizing means that customising discs should be much easier/safer - either add custom contents at the start and debian-cd will fill the remainder of the disc, or afterwards roll back the packages on the disc and add extras later. * Source is now treated as (almost) just another arch, with most of the special casing for source hidden internally. If asking for source-only discs, they will simply be built using all the available sources. If combined with other arches, the sources will automatically be chosen to match the binary packages. Meeting GPL requirements was never so easy! * Removed lots of old cruft to clean up the codebase: + non-US support + woody support + lots of old support scripts that have been made redundant + significantly simpler Makefile, much easier to follow + old boot-$ARCH.calc files for estimating boot-file sizes are now (obviously) obsolete and therefore gone
2006-12-07 22:09:01 -01:00
my $tdir = $ENV{'TDIR'} || die "Set the TDIR var ...\n";
1999-11-11 16:10:37 -01:00
Merge of changes from Steve's development branch to take us to debian-cd version 3.0.0. Highlights: * Support now added for multi-arch CDs/DVDs, including mixed binary/source discs. Multi-arch discs should be bootable on those multiple arches, modulo boot-sector clashes. Extra support added in boot-i386 and boot-amd64 to make the 2 main arches happily co-exist. * Disc sizing is now much more intelligent - sizes are defined depending on the disk type chosen at the start, and discs are now filled exactly to those sizes while files are added rather than the old up-front guessing method. Equally, the metadata on the disc (Packages, Packages.gz, Sources, Sources.gz, md5sums.txt) is generated as much as possible while this is happening to make the sizing code incredibly accurate. Using this method of disc sizing means that customising discs should be much easier/safer - either add custom contents at the start and debian-cd will fill the remainder of the disc, or afterwards roll back the packages on the disc and add extras later. * Source is now treated as (almost) just another arch, with most of the special casing for source hidden internally. If asking for source-only discs, they will simply be built using all the available sources. If combined with other arches, the sources will automatically be chosen to match the binary packages. Meeting GPL requirements was never so easy! * Removed lots of old cruft to clean up the codebase: + non-US support + woody support + lots of old support scripts that have been made redundant + significantly simpler Makefile, much easier to follow + old boot-$ARCH.calc files for estimating boot-file sizes are now (obviously) obsolete and therefore gone
2006-12-07 22:09:01 -01:00
my $total_size = 0;
my $iso_blksize = 2048;
my $pkgname;
my $arch;
1999-11-11 16:10:37 -01:00
Merge of changes from Steve's development branch to take us to debian-cd version 3.0.0. Highlights: * Support now added for multi-arch CDs/DVDs, including mixed binary/source discs. Multi-arch discs should be bootable on those multiple arches, modulo boot-sector clashes. Extra support added in boot-i386 and boot-amd64 to make the 2 main arches happily co-exist. * Disc sizing is now much more intelligent - sizes are defined depending on the disk type chosen at the start, and discs are now filled exactly to those sizes while files are added rather than the old up-front guessing method. Equally, the metadata on the disc (Packages, Packages.gz, Sources, Sources.gz, md5sums.txt) is generated as much as possible while this is happening to make the sizing code incredibly accurate. Using this method of disc sizing means that customising discs should be much easier/safer - either add custom contents at the start and debian-cd will fill the remainder of the disc, or afterwards roll back the packages on the disc and add extras later. * Source is now treated as (almost) just another arch, with most of the special casing for source hidden internally. If asking for source-only discs, they will simply be built using all the available sources. If combined with other arches, the sources will automatically be chosen to match the binary packages. Meeting GPL requirements was never so easy! * Removed lots of old cruft to clean up the codebase: + non-US support + woody support + lots of old support scripts that have been made redundant + significantly simpler Makefile, much easier to follow + old boot-$ARCH.calc files for estimating boot-file sizes are now (obviously) obsolete and therefore gone
2006-12-07 22:09:01 -01:00
open(LOG, ">> $tdir/$codename/log.add_packages")
|| die "Can't write in $tdir/log.add_packages!\n";
1999-11-11 16:10:37 -01:00
Merge of changes from Steve's development branch to take us to debian-cd version 3.0.0. Highlights: * Support now added for multi-arch CDs/DVDs, including mixed binary/source discs. Multi-arch discs should be bootable on those multiple arches, modulo boot-sector clashes. Extra support added in boot-i386 and boot-amd64 to make the 2 main arches happily co-exist. * Disc sizing is now much more intelligent - sizes are defined depending on the disk type chosen at the start, and discs are now filled exactly to those sizes while files are added rather than the old up-front guessing method. Equally, the metadata on the disc (Packages, Packages.gz, Sources, Sources.gz, md5sums.txt) is generated as much as possible while this is happening to make the sizing code incredibly accurate. Using this method of disc sizing means that customising discs should be much easier/safer - either add custom contents at the start and debian-cd will fill the remainder of the disc, or afterwards roll back the packages on the disc and add extras later. * Source is now treated as (almost) just another arch, with most of the special casing for source hidden internally. If asking for source-only discs, they will simply be built using all the available sources. If combined with other arches, the sources will automatically be chosen to match the binary packages. Meeting GPL requirements was never so easy! * Removed lots of old cruft to clean up the codebase: + non-US support + woody support + lots of old support scripts that have been made redundant + significantly simpler Makefile, much easier to follow + old boot-$ARCH.calc files for estimating boot-file sizes are now (obviously) obsolete and therefore gone
2006-12-07 22:09:01 -01:00
sub msg {
my $level = shift;
print LOG @_;
}
require "$basedir/tools/link.pl";
my $old_split = $/;
1999-11-11 16:10:37 -01:00
$/ = ''; # Browse by paragraph
Merge of changes from Steve's development branch to take us to debian-cd version 3.0.0. Highlights: * Support now added for multi-arch CDs/DVDs, including mixed binary/source discs. Multi-arch discs should be bootable on those multiple arches, modulo boot-sector clashes. Extra support added in boot-i386 and boot-amd64 to make the 2 main arches happily co-exist. * Disc sizing is now much more intelligent - sizes are defined depending on the disk type chosen at the start, and discs are now filled exactly to those sizes while files are added rather than the old up-front guessing method. Equally, the metadata on the disc (Packages, Packages.gz, Sources, Sources.gz, md5sums.txt) is generated as much as possible while this is happening to make the sizing code incredibly accurate. Using this method of disc sizing means that customising discs should be much easier/safer - either add custom contents at the start and debian-cd will fill the remainder of the disc, or afterwards roll back the packages on the disc and add extras later. * Source is now treated as (almost) just another arch, with most of the special casing for source hidden internally. If asking for source-only discs, they will simply be built using all the available sources. If combined with other arches, the sources will automatically be chosen to match the binary packages. Meeting GPL requirements was never so easy! * Removed lots of old cruft to clean up the codebase: + non-US support + woody support + lots of old support scripts that have been made redundant + significantly simpler Makefile, much easier to follow + old boot-$ARCH.calc files for estimating boot-file sizes are now (obviously) obsolete and therefore gone
2006-12-07 22:09:01 -01:00
# From a package name and section, work out the directory where its
# corresponding Packages file should live
sub Packages_dir {
my $file = shift;
my $section = shift;
my ($pdir, $dist);
1999-11-11 16:10:37 -01:00
if ($file =~ /\/main\//) {
$dist = "main";
} elsif ($file =~ /\/contrib\//) {
$dist = "contrib";
} elsif ($file =~ /\/non-free\//) {
$dist = "non-free";
} elsif ($file =~ /\/local\//) {
$dist = "local";
Merge of changes from Steve's development branch to take us to debian-cd version 3.0.0. Highlights: * Support now added for multi-arch CDs/DVDs, including mixed binary/source discs. Multi-arch discs should be bootable on those multiple arches, modulo boot-sector clashes. Extra support added in boot-i386 and boot-amd64 to make the 2 main arches happily co-exist. * Disc sizing is now much more intelligent - sizes are defined depending on the disk type chosen at the start, and discs are now filled exactly to those sizes while files are added rather than the old up-front guessing method. Equally, the metadata on the disc (Packages, Packages.gz, Sources, Sources.gz, md5sums.txt) is generated as much as possible while this is happening to make the sizing code incredibly accurate. Using this method of disc sizing means that customising discs should be much easier/safer - either add custom contents at the start and debian-cd will fill the remainder of the disc, or afterwards roll back the packages on the disc and add extras later. * Source is now treated as (almost) just another arch, with most of the special casing for source hidden internally. If asking for source-only discs, they will simply be built using all the available sources. If combined with other arches, the sources will automatically be chosen to match the binary packages. Meeting GPL requirements was never so easy! * Removed lots of old cruft to clean up the codebase: + non-US support + woody support + lots of old support scripts that have been made redundant + significantly simpler Makefile, much easier to follow + old boot-$ARCH.calc files for estimating boot-file sizes are now (obviously) obsolete and therefore gone
2006-12-07 22:09:01 -01:00
}
Merge of changes from Steve's development branch to take us to debian-cd version 3.0.0. Highlights: * Support now added for multi-arch CDs/DVDs, including mixed binary/source discs. Multi-arch discs should be bootable on those multiple arches, modulo boot-sector clashes. Extra support added in boot-i386 and boot-amd64 to make the 2 main arches happily co-exist. * Disc sizing is now much more intelligent - sizes are defined depending on the disk type chosen at the start, and discs are now filled exactly to those sizes while files are added rather than the old up-front guessing method. Equally, the metadata on the disc (Packages, Packages.gz, Sources, Sources.gz, md5sums.txt) is generated as much as possible while this is happening to make the sizing code incredibly accurate. Using this method of disc sizing means that customising discs should be much easier/safer - either add custom contents at the start and debian-cd will fill the remainder of the disc, or afterwards roll back the packages on the disc and add extras later. * Source is now treated as (almost) just another arch, with most of the special casing for source hidden internally. If asking for source-only discs, they will simply be built using all the available sources. If combined with other arches, the sources will automatically be chosen to match the binary packages. Meeting GPL requirements was never so easy! * Removed lots of old cruft to clean up the codebase: + non-US support + woody support + lots of old support scripts that have been made redundant + significantly simpler Makefile, much easier to follow + old boot-$ARCH.calc files for estimating boot-file sizes are now (obviously) obsolete and therefore gone
2006-12-07 22:09:01 -01:00
$pdir = "$dir/dists/$codename/$dist";
if ($section eq "debian-installer") {
Merge of changes from Steve's development branch to take us to debian-cd version 3.0.0. Highlights: * Support now added for multi-arch CDs/DVDs, including mixed binary/source discs. Multi-arch discs should be bootable on those multiple arches, modulo boot-sector clashes. Extra support added in boot-i386 and boot-amd64 to make the 2 main arches happily co-exist. * Disc sizing is now much more intelligent - sizes are defined depending on the disk type chosen at the start, and discs are now filled exactly to those sizes while files are added rather than the old up-front guessing method. Equally, the metadata on the disc (Packages, Packages.gz, Sources, Sources.gz, md5sums.txt) is generated as much as possible while this is happening to make the sizing code incredibly accurate. Using this method of disc sizing means that customising discs should be much easier/safer - either add custom contents at the start and debian-cd will fill the remainder of the disc, or afterwards roll back the packages on the disc and add extras later. * Source is now treated as (almost) just another arch, with most of the special casing for source hidden internally. If asking for source-only discs, they will simply be built using all the available sources. If combined with other arches, the sources will automatically be chosen to match the binary packages. Meeting GPL requirements was never so easy! * Removed lots of old cruft to clean up the codebase: + non-US support + woody support + lots of old support scripts that have been made redundant + significantly simpler Makefile, much easier to follow + old boot-$ARCH.calc files for estimating boot-file sizes are now (obviously) obsolete and therefore gone
2006-12-07 22:09:01 -01:00
$pdir = "$dir/dists/$codename/$dist/debian-installer";
}
return $pdir;
}
# Dump the apt-cached data into a Packages file; make the parent dir
# for the Packages file if necesssary
sub add_Packages_entry {
my ($p, $file, $section, $pdir, $pkgfile, $gz);
my $arch = shift;
m/^Package: (\S+)/m and $p = $1;
m/^Section: (\S+)/m and $section = $1;
if ($arch eq "source") {
m/^Directory: (\S+)/mi and $file = $1;
$pdir = Packages_dir($file, $section) . "/source";
$pkgfile = "$pdir/Sources";
} else {
m/^Filename: (\S+)/mi and $file = $1;
$pdir = Packages_dir($file, $section) . "/binary-$arch";
$pkgfile = "$pdir/Packages";
}
Merge of changes from Steve's development branch to take us to debian-cd version 3.0.0. Highlights: * Support now added for multi-arch CDs/DVDs, including mixed binary/source discs. Multi-arch discs should be bootable on those multiple arches, modulo boot-sector clashes. Extra support added in boot-i386 and boot-amd64 to make the 2 main arches happily co-exist. * Disc sizing is now much more intelligent - sizes are defined depending on the disk type chosen at the start, and discs are now filled exactly to those sizes while files are added rather than the old up-front guessing method. Equally, the metadata on the disc (Packages, Packages.gz, Sources, Sources.gz, md5sums.txt) is generated as much as possible while this is happening to make the sizing code incredibly accurate. Using this method of disc sizing means that customising discs should be much easier/safer - either add custom contents at the start and debian-cd will fill the remainder of the disc, or afterwards roll back the packages on the disc and add extras later. * Source is now treated as (almost) just another arch, with most of the special casing for source hidden internally. If asking for source-only discs, they will simply be built using all the available sources. If combined with other arches, the sources will automatically be chosen to match the binary packages. Meeting GPL requirements was never so easy! * Removed lots of old cruft to clean up the codebase: + non-US support + woody support + lots of old support scripts that have been made redundant + significantly simpler Makefile, much easier to follow + old boot-$ARCH.calc files for estimating boot-file sizes are now (obviously) obsolete and therefore gone
2006-12-07 22:09:01 -01:00
msg(0, " Adding $p to $pkgfile(.gz)\n");
if (! -d $pdir) {
system("mkdir -p $pdir");
}
open(PFILE, ">>$pkgfile");
print PFILE $_;
close(PFILE);
Merge of changes from Steve's development branch to take us to debian-cd version 3.0.0. Highlights: * Support now added for multi-arch CDs/DVDs, including mixed binary/source discs. Multi-arch discs should be bootable on those multiple arches, modulo boot-sector clashes. Extra support added in boot-i386 and boot-amd64 to make the 2 main arches happily co-exist. * Disc sizing is now much more intelligent - sizes are defined depending on the disk type chosen at the start, and discs are now filled exactly to those sizes while files are added rather than the old up-front guessing method. Equally, the metadata on the disc (Packages, Packages.gz, Sources, Sources.gz, md5sums.txt) is generated as much as possible while this is happening to make the sizing code incredibly accurate. Using this method of disc sizing means that customising discs should be much easier/safer - either add custom contents at the start and debian-cd will fill the remainder of the disc, or afterwards roll back the packages on the disc and add extras later. * Source is now treated as (almost) just another arch, with most of the special casing for source hidden internally. If asking for source-only discs, they will simply be built using all the available sources. If combined with other arches, the sources will automatically be chosen to match the binary packages. Meeting GPL requirements was never so easy! * Removed lots of old cruft to clean up the codebase: + non-US support + woody support + lots of old support scripts that have been made redundant + significantly simpler Makefile, much easier to follow + old boot-$ARCH.calc files for estimating boot-file sizes are now (obviously) obsolete and therefore gone
2006-12-07 22:09:01 -01:00
$gz = gzopen("$pkgfile.gz", "ab9") or die "Failed to open $pkgfile.gz: $gzerrno\n";
$gz->gzwrite($_) or die "Failed to write $pkgfile.gz: $gzerrno\n";
$gz->gzclose();
}
sub add_md5_entry {
my $arch = shift;
my ($pdir, $file, $md5);
my $md5file = "$dir/md5sum.txt";
open(MD5FILE, ">>$md5file");
if ($arch eq "source") {
m/^Directory: (\S+)/mi and $pdir = $1;
m/^ (\S+) (\S+) ((\S+).*dsc)/m and print MD5FILE "$1 ./$pdir/$3\n";
m/^ (\S+) (\S+) ((\S+).*tar.gz)/m and print MD5FILE "$1 ./$pdir/$3\n";
m/^ (\S+) (\S+) ((\S+).*diff.gz)/m and print MD5FILE "$1 ./$pdir/$3\n";
} else {
m/^Filename: (\S+)/m and $file = $1;
m/^MD5sum: (\S+)/m and print MD5FILE "$1 ./$file\n";
1999-11-11 16:10:37 -01:00
}
Merge of changes from Steve's development branch to take us to debian-cd version 3.0.0. Highlights: * Support now added for multi-arch CDs/DVDs, including mixed binary/source discs. Multi-arch discs should be bootable on those multiple arches, modulo boot-sector clashes. Extra support added in boot-i386 and boot-amd64 to make the 2 main arches happily co-exist. * Disc sizing is now much more intelligent - sizes are defined depending on the disk type chosen at the start, and discs are now filled exactly to those sizes while files are added rather than the old up-front guessing method. Equally, the metadata on the disc (Packages, Packages.gz, Sources, Sources.gz, md5sums.txt) is generated as much as possible while this is happening to make the sizing code incredibly accurate. Using this method of disc sizing means that customising discs should be much easier/safer - either add custom contents at the start and debian-cd will fill the remainder of the disc, or afterwards roll back the packages on the disc and add extras later. * Source is now treated as (almost) just another arch, with most of the special casing for source hidden internally. If asking for source-only discs, they will simply be built using all the available sources. If combined with other arches, the sources will automatically be chosen to match the binary packages. Meeting GPL requirements was never so easy! * Removed lots of old cruft to clean up the codebase: + non-US support + woody support + lots of old support scripts that have been made redundant + significantly simpler Makefile, much easier to follow + old boot-$ARCH.calc files for estimating boot-file sizes are now (obviously) obsolete and therefore gone
2006-12-07 22:09:01 -01:00
close(MD5FILE);
1999-11-11 16:10:37 -01:00
}
Merge of changes from Steve's development branch to take us to debian-cd version 3.0.0. Highlights: * Support now added for multi-arch CDs/DVDs, including mixed binary/source discs. Multi-arch discs should be bootable on those multiple arches, modulo boot-sector clashes. Extra support added in boot-i386 and boot-amd64 to make the 2 main arches happily co-exist. * Disc sizing is now much more intelligent - sizes are defined depending on the disk type chosen at the start, and discs are now filled exactly to those sizes while files are added rather than the old up-front guessing method. Equally, the metadata on the disc (Packages, Packages.gz, Sources, Sources.gz, md5sums.txt) is generated as much as possible while this is happening to make the sizing code incredibly accurate. Using this method of disc sizing means that customising discs should be much easier/safer - either add custom contents at the start and debian-cd will fill the remainder of the disc, or afterwards roll back the packages on the disc and add extras later. * Source is now treated as (almost) just another arch, with most of the special casing for source hidden internally. If asking for source-only discs, they will simply be built using all the available sources. If combined with other arches, the sources will automatically be chosen to match the binary packages. Meeting GPL requirements was never so easy! * Removed lots of old cruft to clean up the codebase: + non-US support + woody support + lots of old support scripts that have been made redundant + significantly simpler Makefile, much easier to follow + old boot-$ARCH.calc files for estimating boot-file sizes are now (obviously) obsolete and therefore gone
2006-12-07 22:09:01 -01:00
# Roll back the results of add_Packages_entry()
sub remove_Packages_entry {
my ($p, $file, $section, $pdir, $pkgfile, $tmp_pkgfile, $match, $gz);
my $arch = shift;
m/^Package: (\S+)/m and $p = $1;
m/^Section: (\S+)/m and $section = $1;
if ($arch eq "source") {
m/^Directory: (\S+)/mi and $file = $1;
$pdir = Packages_dir($file, $section) . "/source";
$pkgfile = "$pdir/Sources";
} else {
m/^Filename: (\S+)/mi and $file = $1;
$pdir = Packages_dir($file, $section) . "/binary-$arch";
$pkgfile = "$pdir/Packages";
}
$tmp_pkgfile = "$pkgfile" . ".rollback";
msg(0, " Removing $p from $pkgfile\n");
open(IFILE, "<$pkgfile");
open(OFILE, ">>$tmp_pkgfile");
$gz = gzopen("$pkgfile.gz", "wb9");
while (defined($match = <IFILE>)) {
if (! ($match =~ /^Package: $p$/m)) {
print OFILE $match;
$gz->gzwrite($match) or die "Failed to write $pkgfile.gz: $gzerrno\n";
}
}
$gz->gzclose();
close(IFILE);
close(OFILE);
rename $tmp_pkgfile, $pkgfile;
}
sub remove_md5_entry {
my $arch = shift;
my ($pdir, $file, $md5, $match, $present);
my $md5file = "$dir/md5sum.txt";
my $tmp_md5file = "$dir/md5sum.txt.tmp";
my @fileslist;
$/ = $old_split; # Browse by line again
if ($arch eq "source") {
m/^Directory: (\S+)/mi and $pdir = $1;
m/^ (\S+) (\S+) ((\S+).*dsc)/m and push(@fileslist, "$1 ./$pdir/$3");
m/^ (\S+) (\S+) ((\S+).*diff.gz)/m and push(@fileslist, "$1 ./$pdir/$3");
m/^ (\S+) (\S+) ((\S+).*tar.gz)/m and push(@fileslist, "$1 ./$pdir/$3");
} else {
m/^Filename: (\S+)/m and $file = $1;
m/^MD5Sum: (\S+)/mi and push(@fileslist, "$1 ./$file");
}
open(IFILE, "<$md5file");
open(OFILE, ">>$tmp_md5file");
while (defined($match = <IFILE>)) {
$present = 0;
foreach my $entry (@fileslist) {
if (($match =~ /$entry$/m)) {
$present++;
}
}
if (!$present) {
print OFILE $match;
}
}
close(IFILE);
close(OFILE);
$/ = ''; # Browse by paragraph again
rename $tmp_md5file, $md5file;
}
sub get_file_size {
my $realfile = shift;
my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat($realfile);
$size = 1 + int(($size + $iso_blksize - 1) / $iso_blksize);
return $size;
}
my ($p, @files, $d, $realfile, $source, $section, $name, $pkgfile, $pdir);
foreach my $package (@ARGV) {
$pkgname = $package;
$pkgname =~ s/^.*://;
$arch = $package;
$arch =~ s/:.*$//g;
$ENV{'ARCH'} = $arch;
if ($arch eq "source") {
open (LIST, "$basedir/tools/apt-selection cache showsrc $pkgname |")
|| die "Can't fork : $!\n";
} else {
open (LIST, "$basedir/tools/apt-selection cache show $pkgname |")
|| die "Can't fork : $!\n";
}
while (defined($_ = <LIST>)) {
undef @files;
msg(0, "Looking at $package: arch $arch, package $pkgname\n");
m/^Package: (\S+)/m and $p = $1;
m/^Section: (\S+)/m and $section = $1;
$source = $mirror;
if ($arch eq "source") {
m/^Directory: (\S+)/m and $pdir = $1;
$source=$localdebs if $pdir=~m:local/:;
$source=$security if $pdir=~m:updates/:;
m/^ (\S+) (\S+) ((\S+).*dsc)/m and push(@files, "$pdir/$3");
m/^ (\S+) (\S+) ((\S+).*diff.gz)/m and push(@files, "$pdir/$3");
m/^ (\S+) (\S+) ((\S+).*tar.gz)/m and push(@files, "$pdir/$3");
} else {
m/^Filename: (\S+)/mi and push(@files, $1);
$source=$localdebs if $1=~m:local/:;
$source=$security if $1=~m:updates/:;
}
if ($rollback) {
# Remove the Packages entry/entries for the specified package
remove_Packages_entry($arch, $_);
remove_md5_entry($arch, $_);
foreach my $file (@files) {
# Count how big the file is we're removing, for checking if the disc is full
$realfile = real_file ("$source/$file");
$total_size -= get_file_size($realfile);
# Remove the link
unlink ("$dir/$file") or die "Failed to remove $dir/$file\n";
msg(0, " Rollback: removing $dir/$file\n");
}
} else {
add_Packages_entry($arch, $_);
add_md5_entry($arch, $_);
foreach my $file (@files) {
# And put the file in the CD tree (with a (hard) link)
$realfile = real_file ("$source/$file");
if (! -e "$dir/$file") {
# Count how big the file is, for checking if the disc
# is full. ONLY do this if the file is not already
# linked in - consider binary-all packages on a
# multi-arch disc
$total_size += get_file_size($realfile);
good_link ($realfile, "$dir/$file");
msg(0, " Linked $dir/$file\n");
} else {
msg(0, " $dir/$file already linked in\n");
}
}
}
}
close LIST or die "Something went wrong with apt-cache : $@ ($!)\n";
}
msg(0, " size $total_size\n");
print "$total_size\n";
close LOG
1999-11-11 16:10:37 -01:00