setup 4.4 KB

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