setup 4.4 KB

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