setup 4.5 KB

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