1 # This program is free software; you can redistribute it and/or modify
2 # it under the terms of the GNU General Public License as published by
3 # the Free Software Foundation; version 2 of the License.
5 # This program is distributed in the hope that it will be useful,
6 # but WITHOUT ANY WARRANTY; without even the implied warranty of
7 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8 # GNU General Public License for more details.
10 # You should have received a copy of the GNU General Public License
11 # along with this program. If not, see <https://www.gnu.org/licenses/>.
18 our $VERSION = '0.02';
33 use Exporter qw(import);
43 return sprintf('%.2fM', $nb / 1024**2);
44 } elsif ($nb > 1024) {
45 return sprintf('%.2fk', $nb / 1024);
47 return sprintf('%.2fb', $nb);
57 open(my $vars_fh, '<', $vars)
58 or die "couldn't open '$vars': $!\n" .
59 "Try to relaunch the 'Access' step in dselect, thanks.\n";
63 my $VAR1; ## no critic (Variables::ProhibitUnusedVariables)
65 die "couldn't eval $vars content: $@\n" if ($@);
66 if (ref($conf) =~ /HASH/) {
67 foreach (keys %{$conf}) {
68 $CONFIG{$_} = $conf->{$_};
71 print "Bad $vars file : removing it.\n";
72 print "Please relaunch the 'Access' step in dselect. Thanks.\n";
81 # Check that config is completed
82 return if not $CONFIG{done};
84 open(my $vars_fh, '>', $vars)
85 or die "couldn't open $vars in write mode: $!\n";
86 print { $vars_fh } Dumper(\%CONFIG);
92 Please see <http://ftp.debian.org/debian/README.mirrors.txt> for a current
93 list of Debian mirror sites.
101 #Get a config for ftp sites
104 print "\n\nList of selected ftp sites :\n";
105 foreach (@{$CONFIG{site}}) {
106 print "$i. ftp://$_->[0]$_->[1] @{$_->[2]}\n";
109 print "\nEnter a command (a=add e=edit d=delete q=quit m=mirror list) \n";
110 print 'eventually followed by a site number : ';
116 splice(@{$CONFIG{site}}, $1 - 1, 1) if ($1 <= @{$CONFIG{site}});
120 edit_site($CONFIG{site}[$1 - 1]) if ($1 <= @{$CONFIG{site}});
122 /m/i && view_mirrors();
126 $CONFIG{use_auth_proxy} = yesno($CONFIG{use_auth_proxy} ? 'y' : 'n',
127 'Go through an authenticated proxy');
129 if ($CONFIG{use_auth_proxy}) {
130 print "\nEnter proxy hostname [$CONFIG{proxyhost}] : ";
132 $CONFIG{proxyhost} = $_ || $CONFIG{proxyhost};
134 print "\nEnter proxy log name [$CONFIG{proxylogname}] : ";
136 $CONFIG{proxylogname} = $_ || $CONFIG{proxylogname};
138 print "\nEnter proxy password [$CONFIG{proxypassword}] : ";
139 chomp ($_ = <STDIN>);
140 $CONFIG{proxypassword} = $_ || $CONFIG{proxypassword};
143 print "\nEnter directory to download binary package files to\n";
144 print "(relative to $methdir)\n";
146 print "[$CONFIG{dldir}] : ";
149 $CONFIG{dldir} = $_ if ($_);
150 last if -d "$methdir/$CONFIG{dldir}";
151 print "$methdir/$CONFIG{dldir} is not a directory !\n";
157 my $user = 'anonymous';
158 my $email = qx(whoami);
160 $email .= '@' . qx(cat /etc/mailname || dnsdomainname);
164 push (@{$CONFIG{site}}, [ '', $dir, [ 'dists/stable/main',
165 'dists/stable/contrib',
166 'dists/stable/non-free' ],
167 $pas, $user, $email ]);
168 edit_site($CONFIG{site}[@{$CONFIG{site}} - 1]);
176 print "\nEnter ftp site [$site->[0]] : ";
178 $site->[0] = $_ || $site->[0];
180 print "\nUse passive mode [" . ($site->[3] ? 'y' : 'n') . '] : ';
182 $site->[3] = (/y/i ? 1 : 0) if ($_);
184 print "\nEnter username [$site->[4]] : ";
186 $site->[4] = $_ || $site->[4];
190 If you're using anonymous ftp to retrieve files, enter your email
191 address for use as a password. Otherwise enter your password,
192 or "?" if you want dselect-ftp to prompt you each time.
196 print "Enter password [$site->[5]] : ";
198 $site->[5] = $_ || $site->[5];
200 print "\nEnter debian directory [$site->[1]] : ";
202 $site->[1] = $_ || $site->[1];
204 print "\nEnter space separated list of distributions to get\n";
205 print "[@{$site->[2]}] : ";
207 $site->[2] = [ split(/\s+/) ] if $_;
217 croak 'incorrect usage of yesno, stopped' if $r == -1;
219 print $msg, " [$d]: ";
221 $res =~ /^[Yy]/ and return 1;
222 $res =~ /^[Nn]/ and return 0;
223 $res =~ /^[ \t]*$/ and return $r;
224 print "Please enter one of the letters 'y' or 'n'\n";
228 ##############################
231 my($ftpsite,$username,$pass,$ftpdir,$passive,
232 $useproxy,$proxyhost,$proxylogname,$proxypassword) = @_;
234 my($rpass,$remotehost,$remoteuser,$ftp);
241 $remotehost = $proxyhost;
242 $remoteuser = $username . '@' . $ftpsite;
244 $remotehost = $ftpsite;
245 $remoteuser = $username;
247 print "Connecting to $ftpsite...\n";
248 $ftp = Net::FTP->new($remotehost, Passive => $passive);
249 if(!$ftp || !$ftp->ok) {
250 print "Failed to connect\n";
256 print "Login on $proxyhost...\n";
257 $ftp->_USER($proxylogname);
258 $ftp->_PASS($proxypassword);
260 print "Login as $username...\n";
262 print 'Enter password for ftp: ';
263 system('stty', '-echo');
267 system('stty', 'echo');
271 if(!$ftp->login($remoteuser, $rpass))
272 { print $ftp->message() . "\n"; $exit=1; }
275 print "Setting transfer mode to binary...\n";
276 if(!$ftp->binary()) { print $ftp->message . "\n"; $exit=1; }
279 print "Cd to '$ftpdir'...\n";
280 if(!$ftp->cwd($ftpdir)) { print $ftp->message . "\n"; $exit=1; }
284 if (yesno ('y', 'Retry connection at once')) {
294 # if(!$ftp->pasv()) { print $ftp->message . "\n"; die 'error'; }
299 ##############################
301 # assume server supports MDTM - will be adjusted if needed
304 my %months = ('Jan', 0,
318 ([^ ]+\ *){5} # Perms, Links, User, Group, Size
320 \ ([A-Z][a-z]{2}) # Month name (abbreviated)
321 \ ([0-9 ][0-9]) # Day of month
322 \ ([0-9 ][0-9][:0-9][0-9]{2}) # Filename
326 my ($ftp, $file) = @_;
330 $time = $ftp->mdtm($file);
331 # my $code = $ftp->code();
332 # my $message = $ftp->message();
333 # print " [ $code: $message ] ";
334 if ($ftp->code() == 502 || # MDTM not implemented
335 $ftp->code() == 500) { # command not understood (SUN firewall)
337 } elsif (!$ftp->ok()) {
345 my @files = $ftp->dir($file);
346 if (($#files == -1) ||
347 ($ftp->code == 550)) { # No such file or directory
351 # my $code = $ftp->code();
352 # my $message = $ftp->message();
353 # print " [ $code: $message ] ";
357 # get the date components from the output of 'ls -l'
358 if ($files[0] =~ $ls_l_re) {
360 my($month_name, $day, $year_or_time, $month, $hours, $minutes,
368 # translate the month name into number
369 $month = $months{$month_name};
371 # recognize time or year, and compute missing one
372 if ($year_or_time =~ /([0-9]{2}):([0-9]{2})/) {
373 $hours = 0 + $1; $minutes = 0 + $2;
374 my @this_date = gmtime(time());
375 my $this_month = $this_date[4];
376 my $this_year = $this_date[5];
377 if ($month > $this_month) {
378 $year = $this_year - 1;
382 } elsif ($year_or_time =~ / [0-9]{4}/) {
383 $hours = 0; $minutes = 0;
384 $year = $year_or_time - 1900;
386 die 'cannot parse year-or-time';
389 # build a system time
390 $time = Time::Local::timegm(0, $minutes, $hours, $day, $month, $year);
392 die 'regex match failed on LIST output';