#!/usr/bin/perl # # do-merge-packages: merge current Packages and Sources files into wanna-build # database # # Copyright (C) 1998-2000 Roman Hodek # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as # published by the Free Software Foundation; either version 2 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # # $Id$ # package conf; # defaults $basedir = "/var/state/debbuild"; $dbbase = "build-db"; require "/etc/wanna-build.conf"; die "$conf::basedir is not a directory\n" if ! -d $conf::basedir; die "dbbase is empty\n" if ! $dbbase; die "\@conf::sections is not defined\n" if ! @conf::sections; die "\$conf::pkgs_source is not defined\n" if ! $conf::pkgs_source; package main; use strict; use vars qw($HOME $tmpdir $arch @dists $locked); $HOME = $ENV{'HOME'} or die "HOME not defined in environment!\n"; @dists = qw(stable frozen unstable); open( STDOUT, ">>$HOME/lib/merge.log" ); open( STDERR, ">&STDOUT" ); $| = 1; select(STDERR); $| = 1; select(STDOUT); chomp( my $date = `date` ); print "-------------- merge-packages $date --------------\n"; $tmpdir = "/tmp/merge-packages.$$"; chomp( $arch = `dpkg --print-installation-architecture` ); # make backups of databases my $d; foreach $d (@dists) { my $db = "$conf::basedir/$conf::dbbase-$d"; system "cp", "-p", $db, "$db.bak" if -d $db; } mkdir( $tmpdir, 0755 ) or die "mkdir $tmpdir: $!\n"; chdir( $tmpdir ) or die "chdir $tmpdir: $!\n"; foreach (qw(HUP INT QUIT PIPE TERM __DIE__)) { $SIG{$_} = \&cleanup; } system "wanna-build", "--create-maintenance-lock" and die "wanna-build --create-maintenance-lock error status $?\n"; $locked = 1; # fetch Packages files and run wanna-build my ($dist, $sect); foreach $dist ("proposed-updates", @dists) { my @sects = ($dist eq "proposed-updates") ? ("") : @conf::sections; my $bindir = ($dist eq "proposed-updates") ? "" : "binary-$arch"; my $sect; foreach $sect (@sects) { unlink( "Packages", "Packages.gz" ); my $f = "$conf::pkgs_source/dists/$dist/$sect/$bindir/Packages.gz"; if ($f =~ m,^/,) { if (system "gunzip -dc '$f' >Packages") { warn "gunzip Packages.gz error status $?\n"; unlink( "Packages" ); next; } } else { system "wget", "-q", $f and next; if (system "gunzip", "Packages.gz") { warn "gunzip Packages.gz error status $?\n"; unlink( "Packages", "Packages.gz" ); next; } } print "Got $f\n"; if (! -s "Packages") { warn "$0: Packages file for $dist/$sect is zero length; skipping\n"; unlink( "Packages" ); next; } my $d = ($dist eq "proposed-updates") ? "stable" : $dist; next if ! -f "$conf::basedir/$conf::dbbase-$d"; print "--> $dist/$sect\n"; system "wanna-build", "--merge-packages", "-v", "--dist=$d", "Packages" and warn "wanna-build --merge-packages error status $?\n"; unlink( "Packages" ); } } # make Sources files foreach $dist (@dists) { foreach $sect (@conf::sections) { unlink( "Sources", "Sources.gz" ); my $f = "$conf::pkgs_source/dists/$dist/$sect/sources/Sources.gz"; if ($f =~ m,^/,) { if (system "gunzip -dc '$f' >Sources") { warn "gunzip Sources.gz error status $?\n"; unlink( "Sources" ); next; } } else { system "wget", "-q", $f and next; if (system "gunzip", "Sources.gz") { warn "gunzip Sources.gz error status $?\n"; unlink( "Sources", "Sources.gz" ); next; } } print "Got $f\n"; if (! -s "Sources") { warn "$0: Sources file for $dist/$sect is zero length; skipping\n"; unlink( "Sources" ); next; } next if ! -f "$conf::basedir/$conf::dbbase-$dist"; print "--> $dist/$sect (src)\n"; system "wanna-build", "--merge-sources", "-v", "--dist=$dist","Sources" and warn "wanna-build --merge-sources error status $?\n"; unlink( "Sources" ); } } system "wanna-build", "--remove-maintenance-lock" and die "wanna-build --remove-maintenance-lock error status $?\n"; $locked = 0; chdir( "/" ) or die "chdir /: $!\n"; system "rm", "-rf", $tmpdir and die "rm -rf $tmpdir error status $?"; system "buildd-addpkg", "--clean" if -x "/usr/bin/buildd-addpkg"; exit( 0 ); sub cleanup { system "wanna-build", "--remove-maintenance-lock" if $locked; system "rm -rf $tmpdir" if $tmpdir; }