update 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. #!/usr/bin/perl -w
  2. # -*-perl-*-
  3. # Copyright (C) 1996 Andy Guy <awpguy@acs.ucalgary.ca>
  4. # 1998 Martin Schulze <joey@infodrom.north.de>
  5. # 1999,2009 Raphaël Hertzog <hertzog@debian.org>
  6. #
  7. # This program has been distributed under the terms of the GNU GPL.
  8. use strict;
  9. #use diagnostics;
  10. use lib '/usr/lib/perl5/Debian';
  11. use lib '/usr/share/perl5/Debian';
  12. eval 'use Net::FTP;';
  13. if ($@) {
  14. print STDERR "Please install the 'perl' package if you want to use the\n" .
  15. "FTP access method of dselect.\n\n";
  16. exit 1;
  17. }
  18. use Dselect::Ftp;
  19. # deal with arguments
  20. my $vardir = $ARGV[0];
  21. my $method = $ARGV[1];
  22. my $option = $ARGV[2];
  23. if ($option eq "manual") {
  24. print "Enter package file names or a blank line to finish\n";
  25. while(1) {
  26. print "Enter package file name:";
  27. my $fn = <STDIN>;
  28. chomp $fn;
  29. if ( $fn == "") {
  30. exit 0;
  31. }
  32. if ( -f $fn ) {
  33. system ("dpkg", "--merge-avail", $fn);
  34. } else {
  35. print "Could not find $fn, try again\n";
  36. }
  37. };
  38. };
  39. #print "vardir: $vardir, method: $method, option: $option\n";
  40. my $arch=`dpkg --print-architecture`;
  41. $arch='i386' if $?;
  42. chomp $arch;
  43. my $exit = 0;
  44. # get info from control file
  45. read_config("$vardir/methods/ftp/vars");
  46. chdir "$vardir/methods/ftp";
  47. print "Getting Packages files...(stop with ^C)\n\n";
  48. my @pkgfiles;
  49. my $ftp;
  50. my $packages_modified = 0;
  51. sub download {
  52. foreach (@{$config{'site'}}) {
  53. my $site = $_;
  54. $ftp = do_connect ($_->[0], # Ftp server
  55. $_->[4], # username
  56. $_->[5], # password
  57. $_->[1], # ftp dir
  58. $_->[3], # passive
  59. $config{'use_auth_proxy'},
  60. $config{'proxyhost'},
  61. $config{'proxylogname'},
  62. $config{'proxypassword'});
  63. my @dists = @{$_->[2]};
  64. my $dist;
  65. PACKAGE:
  66. foreach $dist (@dists) {
  67. my $dir = "$dist/binary-$arch";
  68. my $must_get = 0;
  69. my $newest_pack_date;
  70. # check existing Packages on remote site
  71. print "\nChecking for Packages file... ";
  72. $newest_pack_date = do_mdtm ($ftp, "$dir/Packages.gz");
  73. if (defined $newest_pack_date) {
  74. print "$dir/Packages.gz\n";
  75. } else {
  76. $dir = "$dist";
  77. $newest_pack_date = do_mdtm ($ftp, "$dir/Packages.gz");
  78. if (defined $newest_pack_date) {
  79. print "$dir/Packages.gz\n";
  80. } else {
  81. print "Couldn't find Packages.gz in $dist/binary-$arch or $dist; ignoring.\n";
  82. print "Your setup is probably wrong, check the distributions directories,\n";
  83. print "and try with passive mode enabled/disabled (if you use a proxy/firewall)\n";
  84. next PACKAGE;
  85. }
  86. }
  87. # we now have $dir set to point to an existing Packages.gz file
  88. # check if we already have a Packages file (and get its date)
  89. $dist =~ tr/\//_/;
  90. my $file = "Packages.$site->[0].$dist";
  91. # if not
  92. if (! -f $file) {
  93. # must get one
  94. # print "No Packages here; must get it.\n";
  95. $must_get = 1;
  96. } else {
  97. # else check last modification date
  98. my @pack_stat = stat($file);
  99. if($newest_pack_date > $pack_stat[9]) {
  100. # print "Packages has changed; must get it.\n";
  101. $must_get = 1;
  102. } elsif ($newest_pack_date < $pack_stat[9]) {
  103. print " Our file is newer than theirs; skipping.\n";
  104. } else {
  105. print " Already up-to-date; skipping.\n";
  106. }
  107. }
  108. if ($must_get) {
  109. -f "Packages.gz" and unlink "Packages.gz";
  110. -f "Packages" and unlink "Packages";
  111. my $size = 0;
  112. TRY_GET_PACKAGES:
  113. while (1) {
  114. if ($size) {
  115. print " Continuing ";
  116. } else {
  117. print " Getting ";
  118. }
  119. print "Packages file from $dir...\n";
  120. eval {
  121. if ($ftp->get("$dir/Packages.gz", "Packages.gz", $size)) {
  122. if (system("gunzip", "Packages.gz")) {
  123. print " Couldn't gunzip Packages.gz, stopped";
  124. die "error";
  125. }
  126. } else {
  127. print " Couldn't get Packages.gz from $dir !!! Stopped.";
  128. die "error";
  129. }
  130. };
  131. if ($@) {
  132. $size = -s "Packages.gz";
  133. if (ref($ftp)) {
  134. $ftp->abort();
  135. $ftp->quit();
  136. };
  137. if (yesno ("y", "Transfer failed at $size: retry at once")) {
  138. $ftp = do_connect ($site->[0], # Ftp server
  139. $site->[4], # username
  140. $site->[5], # password
  141. $site->[1], # ftp dir
  142. $site->[3], # passive
  143. $config{'use_auth_proxy'},
  144. $config{'proxyhost'},
  145. $config{'proxylogname'},
  146. $config{'proxypassword'});
  147. if ($newest_pack_date != do_mdtm ($ftp, "$dir/Packages.gz")) {
  148. print ("Packages file has changed !\n");
  149. $size = 0;
  150. }
  151. next TRY_GET_PACKAGES;
  152. } else {
  153. die "error";
  154. }
  155. }
  156. last TRY_GET_PACKAGES;
  157. }
  158. if(!rename "Packages", "Packages.$site->[0].$dist") {
  159. print " Couldn't rename Packages to Packages.$site->[0].$dist";
  160. die "error";
  161. } else {
  162. # set local Packages file to same date as the one it mirrors
  163. # to allow comparison to work.
  164. utime $newest_pack_date, $newest_pack_date, "Packages.$site->[0].$dist";
  165. $packages_modified = 1;
  166. }
  167. }
  168. push @pkgfiles, "Packages.$site->[0].$dist";
  169. }
  170. $ftp->quit();
  171. }
  172. }
  173. eval {
  174. local $SIG{INT} = sub {
  175. die "Interrupted!\n";
  176. };
  177. download();
  178. };
  179. if($@) {
  180. $ftp->quit() if (ref($ftp));
  181. if($@ =~ /timeout/i) {
  182. print "FTP TIMEOUT\n";
  183. } else {
  184. print "FTP ERROR - $@\n";
  185. }
  186. $exit = 1;
  187. };
  188. my $ans;
  189. if ($packages_modified) { # don't clear if nothing changed
  190. print <<EOM;
  191. It is a good idea to clear the available list of old packages.
  192. However if you have only downloaded a Package files from non-main
  193. distributions you might not want to do this.
  194. EOM
  195. if (yesno ("y", "Do you want to clear available list")) {
  196. print "Clearing...\n";
  197. if(system("dpkg", "--clear-avail")) {
  198. print "dpkg --clear-avail failed.";
  199. die "error";
  200. }
  201. }
  202. }
  203. if (!$packages_modified) {
  204. print "No Packages files was updated.\n";
  205. } else {
  206. my $file;
  207. foreach $file (@pkgfiles) {
  208. if(system ("dpkg", "--merge-avail", $file)) {
  209. print "Dpkg merge available failed on $file";
  210. $exit = 1;
  211. }
  212. }
  213. }
  214. exit $exit;