setup 4.0 KB

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