From 5c59aff6bd4ec774070568a3c23bc4f467643eb7 Mon Sep 17 00:00:00 2001 From: Martin Whitaker Date: Sat, 19 Nov 2022 09:26:09 +0000 Subject: Move ask_mirror() from install::any to any. This makes it available for use by draklive-install. --- perl-install/any.pm | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) (limited to 'perl-install/any.pm') diff --git a/perl-install/any.pm b/perl-install/any.pm index 2c496e39b..16102a5ee 100644 --- a/perl-install/any.pm +++ b/perl-install/any.pm @@ -1843,4 +1843,73 @@ sub enable_x_screensaver() { run_program::run("xset", "s", "reset"); } +=item ask_url($in, $o_url) + +Asks URL of the mirror + +=cut + +sub ask_url { + my ($in, $o_url) = @_; + + my $url = $o_url; + $in->ask_from_({ messages => N("URL of the mirror?"), focus_first => 1 }, [ + { val => \$url, + validate => sub { + if ($url =~ m!^(http|ftp)://!) { + 1; + } else { + $in->ask_warn('', N("URL must start with ftp:// or http://")); + 0; + } + } } ]) && $url; +} + +=item ask_mirror($in, $type, $o_url) + +Retrieves list of mirrors and offers to pick one + +=cut + +sub ask_mirror { + my ($in, $type, $o_url) = @_; + + require mirror; + + my $mirrors = eval { + my $_w = $in->wait_message('', N("Contacting %s web site to get the list of available mirrors...", N("Mageia"))); + mirror::list($in->{product_id}, $type); + }; + my $err = $@; + if (!$mirrors) { + $in->ask_warn('', N("Failed contacting %s web site to get the list of available mirrors", N("Mageia")) . "\n$err"); + return ask_url($in, $o_url); + } + + my $give_url = { country => '-', host => 'URL' }; + + my $mirror = $o_url ? (find { $_->{url} eq $o_url } @$mirrors) || $give_url + #- use current time zone to select best mirror + : mirror::nearest($in->{timezone}{timezone}, $mirrors); + + $in->ask_from_({ messages => N("Choose a mirror from which to get the packages"), + cancel => N("Cancel"), + }, [ { separator => '|', + format => \&mirror::mirror2text, + list => [ @$mirrors, $give_url ], + val => \$mirror, + }, + ]) or return; + + my $url; + if ($mirror eq $give_url) { + $url = ask_url($in, $o_url) or goto &ask_mirror; + } else { + $url = $mirror->{url}; + } + $url =~ s!/main/?$!!; + log::l("chosen mirror: $url"); + $url; +} + 1; -- cgit v1.2.1