4
# Copyright © 1996 Andy Guy <awpguy@acs.ucalgary.ca>
5
# Copyright © 1998 Martin Schulze <joey@infodrom.north.de>
6
# Copyright © 1999, 2009 Raphaël Hertzog <hertzog@debian.org>
8
# This program has been distributed under the terms of the GNU GPL.
15
use lib '/usr/lib/perl5/Debian';
16
use lib '/usr/share/perl5/Debian';
20
print STDERR "Please install the 'perl' package if you want to use the\n" .
21
"FTP access method of dselect.\n\n";
28
my $vardir = $ARGV[0];
29
my $method = $ARGV[1];
30
my $option = $ARGV[2];
32
if ($option eq "manual") {
33
print "Enter package file names or a blank line to finish\n";
35
print "Enter package file name:";
42
system ("dpkg", "--merge-avail", $fn);
44
print "Could not find $fn, try again\n";
49
#print "vardir: $vardir, method: $method, option: $option\n";
51
my $arch=`dpkg --print-architecture`;
56
# get info from control file
57
read_config("$vardir/methods/ftp/vars");
59
chdir "$vardir/methods/ftp";
61
print "Getting Packages files...(stop with ^C)\n\n";
65
my $packages_modified = 0;
68
foreach (@{$config{'site'}}) {
72
$ftp = do_connect ($_->[0], # Ftp server
77
$config{'use_auth_proxy'},
79
$config{'proxylogname'},
80
$config{'proxypassword'});
82
my @dists = @{$_->[2]};
85
foreach $dist (@dists) {
86
my $dir = "$dist/binary-$arch";
90
# check existing Packages on remote site
91
print "\nChecking for Packages file... ";
92
$newest_pack_date = do_mdtm ($ftp, "$dir/Packages.gz");
93
if (defined $newest_pack_date) {
94
print "$dir/Packages.gz\n";
97
$newest_pack_date = do_mdtm ($ftp, "$dir/Packages.gz");
98
if (defined $newest_pack_date) {
99
print "$dir/Packages.gz\n";
101
print "Couldn't find Packages.gz in $dist/binary-$arch or $dist; ignoring.\n";
102
print "Your setup is probably wrong, check the distributions directories,\n";
103
print "and try with passive mode enabled/disabled (if you use a proxy/firewall)\n";
108
# we now have $dir set to point to an existing Packages.gz file
110
# check if we already have a Packages file (and get its date)
112
my $file = "Packages.$site->[0].$dist";
117
# print "No Packages here; must get it.\n";
120
# else check last modification date
121
my @pack_stat = stat($file);
122
if($newest_pack_date > $pack_stat[9]) {
123
# print "Packages has changed; must get it.\n";
125
} elsif ($newest_pack_date < $pack_stat[9]) {
126
print " Our file is newer than theirs; skipping.\n";
128
print " Already up-to-date; skipping.\n";
133
-f "Packages.gz" and unlink "Packages.gz";
134
-f "Packages" and unlink "Packages";
140
print " Continuing ";
144
print "Packages file from $dir...\n";
146
if ($ftp->get("$dir/Packages.gz", "Packages.gz", $size)) {
147
if (system("gunzip", "Packages.gz")) {
148
print " Couldn't gunzip Packages.gz, stopped";
152
print " Couldn't get Packages.gz from $dir !!! Stopped.";
157
$size = -s "Packages.gz";
162
if (yesno ("y", "Transfer failed at $size: retry at once")) {
163
$ftp = do_connect ($site->[0], # Ftp server
164
$site->[4], # username
165
$site->[5], # password
166
$site->[1], # ftp dir
167
$site->[3], # passive
168
$config{'use_auth_proxy'},
169
$config{'proxyhost'},
170
$config{'proxylogname'},
171
$config{'proxypassword'});
173
if ($newest_pack_date != do_mdtm ($ftp, "$dir/Packages.gz")) {
174
print ("Packages file has changed !\n");
177
next TRY_GET_PACKAGES;
182
last TRY_GET_PACKAGES;
185
if(!rename "Packages", "Packages.$site->[0].$dist") {
186
print " Couldn't rename Packages to Packages.$site->[0].$dist";
189
# set local Packages file to same date as the one it mirrors
190
# to allow comparison to work.
191
utime $newest_pack_date, $newest_pack_date, "Packages.$site->[0].$dist";
192
$packages_modified = 1;
195
push @pkgfiles, "Packages.$site->[0].$dist";
202
local $SIG{INT} = sub {
203
die "Interrupted!\n";
208
$ftp->quit() if (ref($ftp));
209
if($@ =~ /timeout/i) {
210
print "FTP TIMEOUT\n";
212
print "FTP ERROR - $@\n";
219
if ($packages_modified) { # don't clear if nothing changed
222
It is a good idea to clear the available list of old packages.
223
However if you have only downloaded a Package files from non-main
224
distributions you might not want to do this.
227
if (yesno ("y", "Do you want to clear available list")) {
228
print "Clearing...\n";
229
if(system("dpkg", "--clear-avail")) {
230
print "dpkg --clear-avail failed.";
236
if (!$packages_modified) {
237
print "No Packages files was updated.\n";
241
foreach $file (@pkgfiles) {
242
if(system ("dpkg", "--merge-avail", $file)) {
243
print "Dpkg merge available failed on $file";