setup.pl 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 <https://www.gnu.org/licenses/>.
  18. use strict;
  19. use warnings;
  20. eval q{
  21. pop @INC if $INC[-1] eq '.';
  22. use Net::FTP;
  23. };
  24. if ($@) {
  25. warn "Please install the 'perl' package if you want to use the\n" .
  26. "FTP access method of dselect.\n\n";
  27. exit 1;
  28. }
  29. use Dselect::Ftp;
  30. # deal with arguments
  31. my $vardir = $ARGV[0];
  32. my $method = $ARGV[1];
  33. my $option = $ARGV[2];
  34. if ($option eq 'manual') {
  35. print "Manual package installation.\n";
  36. exit 0;
  37. }
  38. #print "vardir: $vardir, method: $method, option: $option\n";
  39. #Defaults
  40. my $arch = qx(dpkg --print-architecture);
  41. $arch='i386' if $?;
  42. chomp $arch;
  43. my $logname = qx(whoami);
  44. chomp $logname;
  45. my $host = qx(cat /etc/mailname || dnsdomainname);
  46. chomp $host;
  47. $CONFIG{dldir} = 'debian';
  48. $CONFIG{use_auth_proxy} = 0;
  49. $CONFIG{proxyhost} = '';
  50. $CONFIG{proxylogname} = $logname;
  51. $CONFIG{proxypassword} = '';
  52. my $methdir = "$vardir/methods/ftp";
  53. my $exit = 0;
  54. my $problem = 0;
  55. if (-f "$methdir/vars") {
  56. read_config("$methdir/vars");
  57. }
  58. chdir "$methdir";
  59. if (! -d 'debian') {
  60. mkdir 'debian', 0755;
  61. }
  62. # get info from user
  63. $| = 1;
  64. print <<"EOM";
  65. You must supply an ftp site, use of passive mode, username, password,
  66. path to the debian directory,list of distributions you are interested
  67. in and place to download the binary package files to (relative to
  68. /var/lib/dpkg/methods/ftp). You can add as much sites as you like. Later
  69. entries will always override older ones.
  70. Supply "?" as a password to be asked each time you connect.
  71. Eg: ftp site: ftp.debian.org
  72. passive: y
  73. username: anonymous
  74. password: $logname\@$host
  75. ftp dir: /debian
  76. distributions: dists/stable/main dists/stable/contrib
  77. download dir: debian
  78. If you want to install package from non-US consider adding a second ftp site
  79. with "debian-non-US" as debian directory and "dists/stable/non-US" as
  80. distribution.
  81. You may have to use an authenticated FTP proxy in order to reach the
  82. FTP site:
  83. Eg: use auth proxy: y
  84. proxy: proxy.isp.com
  85. proxy account: $CONFIG{proxylogname}
  86. proxy password: ?
  87. EOM
  88. if (! $CONFIG{done}) {
  89. view_mirrors() if (yesno('y', 'Would you like to see a list of ftp mirrors'));
  90. add_site();
  91. }
  92. edit_config($methdir);
  93. my $ftp;
  94. sub download() {
  95. foreach (@{$CONFIG{site}}) {
  96. $ftp = do_connect ($_->[0], # Ftp server
  97. $_->[4], # username
  98. $_->[5], # password
  99. $_->[1], # ftp dir
  100. $_->[3], # passive
  101. $CONFIG{use_auth_proxy},
  102. $CONFIG{proxyhost},
  103. $CONFIG{proxylogname},
  104. $CONFIG{proxypassword});
  105. my @dists = @{$_->[2]};
  106. foreach my $dist (@dists) {
  107. my $dir = "$dist/binary-$arch";
  108. print "Checking $dir...\n";
  109. # if (!$ftp->pasv()) { print $ftp->message . "\n"; die 'error'; }
  110. my @dirlst = $ftp->ls("$dir/");
  111. my $got_pkgfile = 0;
  112. foreach my $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 <enter> to continue\n";
  151. <STDIN>;
  152. }
  153. exit $exit;