setup 4.0 KB

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