setup 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. #!/usr/bin/perl -w
  2. # -*-perl-*-
  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>
  6. #
  7. # This program has been distributed under the terms of the GNU GPL.
  8. use strict;
  9. use vars qw(%config);
  10. #use diagnostics;
  11. use lib '/usr/lib/perl5/Debian';
  12. use lib '/usr/share/perl5/Debian';
  13. eval 'use Net::FTP;';
  14. if ($@) {
  15. print STDERR "Please install the 'perl' package if you want to use the\n" .
  16. "FTP access method of dselect.\n\n";
  17. exit 1;
  18. }
  19. use Dselect::Ftp;
  20. # deal with arguments
  21. my $vardir = $ARGV[0];
  22. my $method = $ARGV[1];
  23. my $option = $ARGV[2];
  24. if ($option eq "manual") {
  25. print "Manual package installation.\n";
  26. exit 0;
  27. }
  28. #print "vardir: $vardir, method: $method, option: $option\n";
  29. #Defaults
  30. my $arch=`dpkg --print-architecture`;
  31. $arch='i386' if $?;
  32. chomp $arch;
  33. my $logname = `whoami`;
  34. chomp $logname;
  35. my $host = `cat /etc/mailname || dnsdomainname`;
  36. chomp $host;
  37. $config{'dldir'} = "debian";
  38. $config{'use_auth_proxy'} = 0;
  39. $config{'proxyhost'} = "";
  40. $config{'proxylogname'} = $logname;
  41. $config{'proxypassword'} = "";
  42. my $methdir = "$vardir/methods/ftp";
  43. my $exit = 0;
  44. my $problem = 0;
  45. if (-f "$methdir/vars") {
  46. read_config("$methdir/vars");
  47. }
  48. chdir "$methdir";
  49. if (! -d "debian") {
  50. mkdir "debian", 0755;
  51. }
  52. # get info from user
  53. $| = 1;
  54. print <<EOM;
  55. You must supply an ftp site, use of passive mode, username, password,
  56. path to the debian directory,list of distributions you are interested
  57. in and place to download the binary package files to (relative to
  58. /var/lib/dpkg/methods/ftp). You can add as much sites as you like. Later
  59. entries will always override older ones.
  60. Supply "?" as a password to be asked each time you connect.
  61. Eg: ftp site: ftp.debian.org
  62. passive: y
  63. username: anonymous
  64. password: $logname\@$host
  65. ftp dir: /debian
  66. distributions: dists/stable/main dists/stable/contrib
  67. download dir: debian
  68. If you want to install package from non-US consider adding a second ftp site
  69. with "debian-non-US" as debian directory and "dists/stable/non-US" as
  70. distribution.
  71. You may have to use an authenticated FTP proxy in order to reach the
  72. FTP site:
  73. Eg: use auth proxy: y
  74. proxy: proxy.isp.com
  75. proxy account: $config{'proxylogname'}
  76. proxy password: ?
  77. EOM
  78. if (! $config{'done'}) {
  79. view_mirrors() if (yesno("y", "Would you like to see a list of ftp mirrors"));
  80. add_site();
  81. }
  82. edit_config($methdir);
  83. my $ftp;
  84. sub download() {
  85. foreach (@{$config{'site'}}) {
  86. $ftp = do_connect ($_->[0], # Ftp server
  87. $_->[4], # username
  88. $_->[5], # password
  89. $_->[1], # ftp dir
  90. $_->[3], # passive
  91. $config{'use_auth_proxy'},
  92. $config{'proxyhost'},
  93. $config{'proxylogname'},
  94. $config{'proxypassword'});
  95. my @dists = @{$_->[2]};
  96. my $dist;
  97. foreach $dist (@dists) {
  98. my $dir = "$dist/binary-$arch";
  99. print "Checking $dir...\n";
  100. # if(!$ftp->pasv()) { print $ftp->message . "\n"; die "error"; }
  101. my @dirlst = $ftp->ls("$dir/");
  102. my $got_pkgfile = 0;
  103. my $line = "";
  104. foreach $line (@dirlst) {
  105. if($line =~ /Packages/) {
  106. $got_pkgfile=1;
  107. }
  108. }
  109. if( !$got_pkgfile) {
  110. print "Warning: Could not find a Packages file in $dir\n",
  111. "This may not be a problem if the directory is a symbolic link\n";
  112. $problem=1;
  113. }
  114. }
  115. print "Closing ftp connection...\n";
  116. $ftp->quit();
  117. }
  118. }
  119. # download stuff (protect from ^C)
  120. print "\nUsing FTP to check directories...(stop with ^C)\n\n";
  121. eval {
  122. local $SIG{INT} = sub {
  123. die "Interrupted!\n";
  124. };
  125. download();
  126. };
  127. if($@) {
  128. $ftp->quit();
  129. print "FTP ERROR - ";
  130. if ($@ eq "connect") {
  131. print "config was untested\n";
  132. } else {
  133. print "$@\n";
  134. }
  135. $exit = 1;
  136. };
  137. # output new vars file
  138. $config{'done'} = 1;
  139. store_config("$methdir/vars");
  140. chmod 0600, "$methdir/vars";
  141. if($exit || $problem) {
  142. print "Press return to continue\n";
  143. <STDIN>;
  144. }
  145. exit $exit;