[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Downloading deb's



On Mon, 2002-02-18 at 19:59, Oki DZ wrote:
> On 18 Feb 2002, Alex Malinovich wrote:
> > I have one which I wrote for personal use. I'd be happy to send it to
> > you, but make sure you're comfortable with looking at Perl. (It's
> > actually really simple overall.)
> 
> I think it would be great if you don't mind to post it here (so that many
> people can just use it).
> 
> Thanks in advance,
> Oki
> 

Here's the script. I just added support for non-US archives yesterday,
and chances are VERY VERY VERY good that I've broken something in the
meantime. (I'm running it right now to test.) Any and all
comments/suggestions are welcome. At the moment, it's not VERY fault
tolerant (some rudimentary error checking, but no lockfiles yet, etc.)
so don't use it if you HAVE to have those debs and you HAVE to have them
now.

------------------- BEGIN sidmirror.pl -----------------------

#!/usr/bin/perl

# sidmirror.pl - Sid mirroring script
# (c) 2002 Alex Malinovich (demonbane@the-love-shack.net)
# Released under the GPL
# See www.fsf.org for a full copy of the GPL.
#
# $server - Server to sync main, contrib, and non-free with.
#
# $nonus - Server to sync debian-non-US with. Note that most servers
# will use the path debian-non-US/ as their base path, but not all.
# The default server here uses debian/non-US/. Until I get around to
# tossing in some variables for this, you'll have to edit the rsync
# lines by hand if you want to use a server that uses debian-non-US.
#
# $rootdir - root directory for main, contrib, and non-free. This will
# become identical to $server::debian/ after the first rsync.
#
# $rootnonus - root directory for non-US packages. This will become
# identical to $nonus::debian/non-US or $nonus::debian-non-US/ depending
# on the server.

if ($ARGV[0]) {
  $server = $ARGV[0];
}else {
  $server = "ftp.eecs.umich.edu";
}

if ($ARGV[1]) {
  $nonus = $ARGV[1];
}else {
  $nonus = "debian.teleglobe.net"
}

$rootdir = "/smb/apt/debian";
$rootnonus = "/smb/apt/debian-non-US";

################################################
## Download the newest Packages.gz from $server
################################################
do {
  print "Retrieving newest Packages.gz from $server...\n";
  $errcode = system(
		    "rsync -P --recursive --times --verbose --compress --delete --include \"/main/binary-i386/Packages.gz\" --include \"/contrib/binary-i386/Packages.gz\" --include \"/non-free/binary-i386/Packages.gz\" --include \"*/\" --exclude \"*\" $server\:\:debian/dists/sid/ $rootdir/dists/sid/ 2> Package.error"
		   );
  $errcode /= 256;
  $retry = "false";
  if ($errcode > 0) {
    print "\nError! Rsync failed with an exit code of $errcode! Check Package.error for details.\n<A>bort, <R>etry, or <C>ontinue? [A/r/c] ";
    $proceed = <STDIN>;
    $proceed = uc($proceed);
    chomp $proceed;
    if ($proceed eq "C") {
      $retry = "false";
    }elsif ($proceed eq "R") {
      $retry = "true";
    }else {
      exit 1;
    }
  }else {
    print "\nDone!\n\n";
  }
}while ($retry eq "true");

###############################################
## Download the newest Packages.gz from $nonus
###############################################
do {
  print "Retrieving newest Packages.gz from $nonus...\n";
  $errcode = system(
		    "rsync -P --recursive --times --verbose --compress --delete --include \"/main/binary-i386/Packages.gz\" --include \"/contrib/binary-i386/Packages.gz\" --include \"/non-free/binary-i386/Packages.gz\" --include \"*/\" --exclude \"*\" $nonus\:\:debian/non-US/dists/sid/non-US/ $rootnonus/dists/sid/non-US/ 2> Package.error"
		   );
  $errcode /= 256;
  $retry = "false";
  if ($errcode > 0) {
    print "\nError! Rsync failed with an exit code of $errcode! Check Package.error for details.\n<A>bort, <R>etry, or <C>ontinue? [A/r/c] ";
    $proceed = <STDIN>;
    $proceed = uc($proceed);
    chomp $proceed;
    if ($proceed eq "C") {
      $retry = "false";
    }elsif ($proceed eq "R") {
      $retry = "true";
    }else {
      exit 1;
    }
  }else {
    print "\nDone!\n\n";
  }
}while ($retry eq "true");

# TODO: Either make this more failsafe esp. in regards to non-US or
# get rid of it and use a user-defined array.
opendir (DISTDIR, "$rootdir/dists/sid/");
@dirlist = grep {!/^\./ && -d "$rootdir/dists/sid/$_"} readdir (DISTDIR);
closedir DISTDIR;

foreach (@dirlist) {
  print "Reading records from $_ Packages.gz...\n";
  $oldcount = $#packfile;
  push (@packfile, `gunzip --to-stdout $rootdir/dists/sid/$_/binary-i386/Packages.gz`);
  print ((++$#packfile - $oldcount), " records read from $_\n\n");
}

foreach (@packfile) {
  if ($_ =~ /^Filename\: /) {
    push (@filenames, substr($_, 10));
  }
}
print "Done!\n\n";

# TODO: _POSSIBLY_ have the script compare the files already present to
# the names and sizes listed in Packages.gz and exclude ones that match.
# This should speed things up quite a bit when there's a small number of
# packages to be updated. I'll have to think about this one.

# Generate a list of files we need from the standard distrib
print "Generating includefile...\n";
open (INCLUDEFILE, ">includefile");
print INCLUDEFILE @filenames;
close INCLUDEFILE;
print ++$#filenames, " records written\n\n";

undef @packfile;
undef @filenames;

foreach (@dirlist) {
  print "Reading records from non-US/$_ Packages.gz...\n";
  $oldcount = $#packfile;
  push (@packfile, `gunzip --to-stdout $rootnonus/dists/sid/non-US/$_/binary-i386/Packages.gz`);
  print ((++$#packfile - $oldcount), " records read from non-US/$_\n\n");
}

foreach (@packfile) {
  if ($_ =~ /^Filename\: /) {
    push (@filenames, substr($_, 10));
  }
}
print "Done!\n\n";

# Generate a list of files we need from the non-US distrib
print "Generating non-US includefile...\n";
open (INCLUDEFILE, ">includefile-non-US");
print INCLUDEFILE @filenames;
close INCLUDEFILE;
print ++$#filenames, " records written\n\n";

print "Starting rsync with $server...\n";
`echo Starting rsync with $server... > rsync.log`;
$retcode = system ("rsync --recursive --links --hard-links --times --verbose --compress --delete --include \"*/\" --include-from=includefile --exclude \"*\" $server\:\:debian/ $rootdir/ >> rsync.log 2>&1");
$retcode /= 256;
`echo End rsync with $server... exit value = $retcode >> rsync.log`;

if ($retcode > 0) {
  print "An error was encountered while performing the rsync operation! The exit code reported was $retcode. Please check rsync.log.0 for details.\n\n";
}else {
  print "rsync completed successfully!\n\n";
}

`savelog rsync.log`;

print "Starting non-US rsync with $nonus...\n";
`echo Starting non-US rsync with $nonus... > rsync-non-US.log`;
$nonuscode = system ("rsync --recursive --links --hard-links --times --verbose --compress --delete --include \"*/\" --include-from=includefile-non-US --exclude \"*\" $nonus\:\:debian/non-US/ $rootnonus/ >> rsync-non-US.log 2>&1");
$nonuscode /= 256;
`echo End rsync with $server... exit value = $nonuscode >> rsync-non-US.log`;

`savelog rsync-non-US.log`;

if ($nonuscode > 0) {
  print "An error was encountered while performing the non-US rsync operation! The exit code reported was $nonuscode. Please check rsync-non-US.log.0 for details.\n\n";
}else {
  print "non-US rsync completed successfully!\n\n";
}

if ($retcode == 0 && $errcode == 0 && $nonuscode == 0) {
  print "All operations completed successfully!\n\n";
}else {
  print "Errors encountered during operation! Please check Package.error and rsync.log.0 for details!\n\n";
}

Attachment: signature.asc
Description: This is a digitally signed message part


Reply to: