summaryrefslogtreecommitdiffstats
path: root/perl-install/any.pm
diff options
context:
space:
mode:
authorMartin Whitaker <mageia@martin-whitaker.me.uk>2022-11-19 09:26:09 +0000
committerMartin Whitaker <mageia@martin-whitaker.me.uk>2022-11-19 13:14:33 +0000
commit5c59aff6bd4ec774070568a3c23bc4f467643eb7 (patch)
treeba9182080ac7f69a2c2fa3dd044652b5d7bab9e2 /perl-install/any.pm
parent39111de7fbaa830a225714066b3d9a0ae12b1996 (diff)
downloaddrakx-5c59aff6bd4ec774070568a3c23bc4f467643eb7.tar
drakx-5c59aff6bd4ec774070568a3c23bc4f467643eb7.tar.gz
drakx-5c59aff6bd4ec774070568a3c23bc4f467643eb7.tar.bz2
drakx-5c59aff6bd4ec774070568a3c23bc4f467643eb7.tar.xz
drakx-5c59aff6bd4ec774070568a3c23bc4f467643eb7.zip
Move ask_mirror() from install::any to any.
This makes it available for use by draklive-install.
Diffstat (limited to 'perl-install/any.pm')
-rw-r--r--perl-install/any.pm69
1 files changed, 69 insertions, 0 deletions
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;