3 # Copyright © 1996 Andy Guy <awpguy@acs.ucalgary.ca>
4 # Copyright © 1998 Martin Schulze <joey@infodrom.north.de>
5 # Copyright © 1999, 2009 Raphaël Hertzog <hertzog@debian.org>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; version 2 of the License.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <https://www.gnu.org/licenses/>.
23 pop @INC if $INC[-1] eq '.';
27 warn "Please install the 'perl' package if you want to use the\n" .
28 "FTP access method of dselect.\n\n";
35 my $vardir = $ARGV[0];
36 my $method = $ARGV[1];
37 my $option = $ARGV[2];
39 if ($option eq 'manual') {
40 print "Enter package file names or a blank line to finish\n";
42 print 'Enter package file name:';
49 system('dpkg', '--merge-avail', $fn);
51 print "Could not find $fn, try again\n";
56 #print "vardir: $vardir, method: $method, option: $option\n";
58 my $arch = qx(dpkg --print-architecture);
63 # get info from control file
64 read_config("$vardir/methods/ftp/vars");
66 chdir "$vardir/methods/ftp";
68 print "Getting Packages files...(stop with ^C)\n\n";
72 my $packages_modified = 0;
75 foreach (@{$CONFIG{site}}) {
79 $ftp = do_connect ($_->[0], # Ftp server
84 $CONFIG{use_auth_proxy},
86 $CONFIG{proxylogname},
87 $CONFIG{proxypassword});
89 my @dists = @{$_->[2]};
91 foreach my $dist (@dists) {
92 my $dir = "$dist/binary-$arch";
96 # check existing Packages on remote site
97 print "\nChecking for Packages file... ";
98 $newest_pack_date = do_mdtm ($ftp, "$dir/Packages.gz");
99 if (defined $newest_pack_date) {
100 print "$dir/Packages.gz\n";
103 $newest_pack_date = do_mdtm ($ftp, "$dir/Packages.gz");
104 if (defined $newest_pack_date) {
105 print "$dir/Packages.gz\n";
107 print "Couldn't find Packages.gz in $dist/binary-$arch or $dist; ignoring.\n";
108 print "Your setup is probably wrong, check the distributions directories,\n";
109 print "and try with passive mode enabled/disabled (if you use a proxy/firewall)\n";
114 # we now have $dir set to point to an existing Packages.gz file
116 # check if we already have a Packages file (and get its date)
118 my $file = "Packages.$site->[0].$dist";
123 # print "No Packages here; must get it.\n";
126 # else check last modification date
127 my @pack_stat = stat($file);
128 if($newest_pack_date > $pack_stat[9]) {
129 # print "Packages has changed; must get it.\n";
131 } elsif ($newest_pack_date < $pack_stat[9]) {
132 print " Our file is newer than theirs; skipping.\n";
134 print " Already up-to-date; skipping.\n";
139 -f 'Packages.gz' and unlink 'Packages.gz';
140 -f 'Packages' and unlink 'Packages';
146 print ' Continuing ';
150 print "Packages file from $dir...\n";
152 if ($ftp->get("$dir/Packages.gz", 'Packages.gz', $size)) {
153 if (system('gunzip', 'Packages.gz')) {
154 print " Couldn't gunzip Packages.gz, stopped";
158 print " Couldn't get Packages.gz from $dir !!! Stopped.";
163 $size = -s 'Packages.gz';
168 if (yesno ('y', "Transfer failed at $size: retry at once")) {
169 $ftp = do_connect ($site->[0], # Ftp server
170 $site->[4], # username
171 $site->[5], # password
172 $site->[1], # ftp dir
173 $site->[3], # passive
174 $CONFIG{use_auth_proxy},
176 $CONFIG{proxylogname},
177 $CONFIG{proxypassword});
179 if ($newest_pack_date != do_mdtm ($ftp, "$dir/Packages.gz")) {
180 print ("Packages file has changed !\n");
183 next TRY_GET_PACKAGES;
188 last TRY_GET_PACKAGES;
191 if (!rename 'Packages', "Packages.$site->[0].$dist") {
192 print " Couldn't rename Packages to Packages.$site->[0].$dist";
195 # set local Packages file to same date as the one it mirrors
196 # to allow comparison to work.
197 utime $newest_pack_date, $newest_pack_date, "Packages.$site->[0].$dist";
198 $packages_modified = 1;
201 push @pkgfiles, "Packages.$site->[0].$dist";
208 local $SIG{INT} = sub {
209 die "interrupted!\n";
214 $ftp->quit() if (ref($ftp));
215 if($@ =~ /timeout/i) {
216 print "FTP TIMEOUT\n";
218 print "FTP ERROR - $@\n";
223 # Don't clear if nothing changed.
224 if ($packages_modified) {
227 It is a good idea to clear the available list of old packages.
228 However if you have only downloaded a Package files from non-main
229 distributions you might not want to do this.
232 if (yesno ('y', 'Do you want to clear available list')) {
233 print "Clearing...\n";
234 if (system('dpkg', '--clear-avail')) {
235 print 'dpkg --clear-avail failed.';
241 if (!$packages_modified) {
242 print "No Packages files was updated.\n";
244 foreach my $file (@pkgfiles) {
245 if (system('dpkg', '--merge-avail', $file)) {
246 print "Dpkg merge available failed on $file";