setup 4.4 KB

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