summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xmdkapplet-add-media-helper80
-rwxr-xr-xmdkapplet-extended-maintenance-helper215
-rw-r--r--mdkonline.pm14
3 files changed, 92 insertions, 217 deletions
diff --git a/mdkapplet-add-media-helper b/mdkapplet-add-media-helper
index ee346a67..6afbba2b 100755
--- a/mdkapplet-add-media-helper
+++ b/mdkapplet-add-media-helper
@@ -59,6 +59,21 @@ my %product = (
media_name => 'Update',
add_medium => \&mdkonline::add_medium_enterprise
},
+ extended => {
+ info_url => 'https://my.mandriva.com/',
+ has_rights => sub {
+ my ($profile, $version) = @_;
+ return ! ref $profile->{data}{groups}{'ext-maint-' . $version};
+ },
+ media_name => 'Extended Maintenance',
+ add_medium => \&mdkonline::add_medium_extended,
+ success_callback => sub {
+ mdkonline::read_sys_config();
+ $mdkonline::config{EXTENDED_SUPPORT} = bool2yesno(1);
+ mdkonline::setVarsInSh($mdkonline::config_file,
+ \%mdkonline::config);
+ }
+ }
);
# Distribution upgrade version and product
@@ -68,6 +83,7 @@ my $up_product;
# Dialogs title and banner text
my $title = N("Adding an additional package medium");
+my $current_apimdv_distro;
# ######################################################################
# Main Program
@@ -115,14 +131,56 @@ my $title = N("Adding an additional package medium");
}
run_authentication_dialog();
+ ugtk2::exit(0);
}
sub run_authentication_dialog {
my $description = N("Please fill in your account ID to add an additional package medium");
+ my $extra_info = undef; # extra widgets for the dialog
+
+ if ($up_product eq 'extended') {
+
+ # Setup extra_info widgets for extended product...
+ my ($url, $extmaint_end, $desktop_update_end, $basic_update_end)
+ = get_extended_maintenance_data();
+ if (my $err = $@) {
+ interactive->vnew->ask_warn(
+ N("Error"),
+ N("Failure while retrieving distributions list:") . "\n$err"
+ );
+ return;
+ }
+ $extra_info
+ = [ gtknew('Label_Left',
+ text_markup =>
+ join("\n\n",
+ #-PO: Here '%s' will be a localized date (eg:
+ # "2009/11/28" in english but "28/11/2009"
+ # for brazil or "28 Nov. "2009" for
+ # french:
+ N("Mandriva provides 12 months of desktop updates (until %s) and 18 months of base updates (up to the %s) for distributions.",
+ mdkapplet_gui::iso8601_date_to_locale(
+ $desktop_update_end),
+ mdkapplet_gui::iso8601_date_to_locale(
+ $basic_update_end)
+ ),
+ N("Extended maintenance is now available to get 18 months of additional updates (until %s).",
+ mdkapplet_gui::iso8601_date_to_locale(
+ $extmaint_end)),
+ N("You can subscribe <b>right now</b> to get extended maintenance:"),
+ ),
+ @common),
+ new_link_button('http://www2.mandriva.com/support/lifecycle/',
+ N("Lifetime policy")),
+ new_link_button($url, N("Online subscription"))
+ ];
+ }
+
mdkapplet_gui::run_ask_credentials_dialog($title,
$description,
- \&authenticate_callback);
- ugtk2::exit(0);
+ \&authenticate_callback,
+ top_extra => $extra_info);
+ return;
}
sub authenticate_callback {
@@ -154,10 +212,14 @@ sub add_medium_for_product {
my $error = 0;
my $current_arch = urpm::cfg::get_arch();
+ # FIXME: This is not enough if we ever support more 64 archs
+ # (sparc64, ppc64 and the like):
my @archs = ($current_arch, if_($current_arch eq 'x86_64', 'i586'));
foreach my $arch (@archs) {
unless ($product->{add_medium}->($email, $passwd, $up_version, $arch)) {
+ # FIXME: Backup original media setup so on error previous
+ # added media in this loop can be removed?
$error = 1;
interactive->vnew->ask_warn(
N("Error"),
@@ -168,6 +230,7 @@ sub add_medium_for_product {
}
unless ($error) {
+ $product->{success_callback} and $product->{success_callback}->();
my $w = ugtk2->new(N("Successfully added media!"),
grab => 1);
$w->_ask_okcancel(N("Successfully added media %s.",
@@ -177,3 +240,16 @@ sub add_medium_for_product {
ugtk2::main($w);
}
}
+
+sub get_extended_maintenance_data() {
+ if (not $current_apimdv_distro) {
+ require Rpmdrake::open_db;
+ my @distros = mdkonline::get_distro_list();
+ return if !@distros;
+ $current_apimdv_distro = mdkonline::find_current_distro(@distros);
+ }
+ return @$current_apimdv_distro{ qw(extended-maintenance
+ extended-maintenance-end
+ desktop-update-end
+ basic-update-end) };
+}
diff --git a/mdkapplet-extended-maintenance-helper b/mdkapplet-extended-maintenance-helper
deleted file mode 100755
index a5543ee3..00000000
--- a/mdkapplet-extended-maintenance-helper
+++ /dev/null
@@ -1,215 +0,0 @@
-#!/usr/bin/perl
-################################################################################
-# Mandriva Online #
-# #
-# Copyright (C) 2010 Mandriva #
-# #
-# Thierry Vignaud <tvignaud at mandriva dot com> #
-# #
-# This program is free software; you can redistribute it and/or modify #
-# it under the terms of the GNU General Public License Version 2 as #
-# published by the Free Software Foundation. #
-# #
-# This program is distributed in the hope that it will be useful, #
-# but WITHOUT ANY WARRANTY; without even the implied warranty of #
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
-# GNU General Public License for more details. #
-# #
-# You should have received a copy of the GNU General Public License #
-# along with this program; if not, write to the Free Software #
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #
-################################################################################
-
-use strict;
-use lib qw(/usr/lib/libDrakX /usr/lib/libDrakX/drakfirsttime);
-use standalone; # for explanations
-use common;
-use run_program;
-
-BEGIN { unshift @::textdomains, 'mdkonline' }
-
-use mygtk2 qw(gtknew); #- do not import gtkadd which conflicts with ugtk2 version
-use ugtk2 qw(:all);
-use urpm::cfg;
-use mdkonline;
-use mdkapplet_gui;
-use interactive;
-
-use XML::Simple;
-use URI::Escape;
-use LWP::UserAgent;
-use HTTP::Request::Common;
-use HTTP::Request;
-use interactive::gtk;
-
-foreach my $opt (@ARGV) {
- if ($opt =~ /--(rpm-root|urpmi-root)=(.*)/) {
- $::rpmdrake_options{$1}[0] = $2;
- undef $opt;
- }
-}
-my ($version) = @ARGV;
-my $email;
-
-$version or die "usage: $0 <distrib_version>\n";
-
-# make it work on 2008.X:
-eval { interactive::gtk::add_padding(Gtk2::Label->new) };
-if ($@) {
- *interactive::gtk::add_padding = sub { $_[0] };
-}
-
-read_sys_config();
-get_extmaint_authentication();
-
-ugtk2::exit(0);
-
-sub get_extended_maintenance_data() {
- require Rpmdrake::open_db;
- get_product_id();
- my @distros = get_distro_list();
- return if !@distros;
- my $current_apimdv_distro = find_current_distro(@distros);
- @$current_apimdv_distro{qw(extended-maintenance extended-maintenance-end desktop-update-end basic-update-end)};
-}
-
-sub get_extmaint_authentication() {
- my $w = ugtk2->new(N("Adding an additional package medium"), width => $width + 20);
- my ($password_w, $email_w, $password);
-
- $password_w = gtknew('Entry');
- $password_w->set_visibility(0);
-
- my ($url, $extended_maintenance_end, $desktop_update_end, $basic_update_end) =
- eval { get_extended_maintenance_data() };
- if (my $err = $@) {
- interactive->vnew->ask_warn(N("Error"), N("Failure while retrieving distributions list:")
- . "\n$err");
- return;
- }
-
- $w->{ok_clicked} = sub {
- $password = $password_w->get_text;
- Gtk2->main_quit;
- };
-
- my @widgets = (
- if_(!$::isEmbedded,
- get_banner(N("Extended Maintenance")),
- ),
- gtknew('Label_Left',
- text_markup =>
- join("\n\n",
- #-PO: Here '%s' will be a localized date (eg: "2009/11/28" in english but "28/11/2009" for brazil or "28 Nov. "2009" for french:
- N("Mandriva provides 12 months of desktop updates (until %s) and 18 months of base updates (up to the %s) for distributions.",
- iso8601_date_to_locale($desktop_update_end),
- iso8601_date_to_locale($basic_update_end)),
- N("Extended maintenance is now available to get 18 months of additional updates (until %s).",
- iso8601_date_to_locale($extended_maintenance_end)),
- N("You can subscribe <b>right now</b> to get extended maintenance:"),
- ),
- @common),
- new_link_button('http://www2.mandriva.com/support/lifecycle/', N("Lifetime policy")),
- new_link_button($url, N("Online subscription")),
- gtknew('HSeparator'),
- gtknew('Label_Left', text => N("Please fill in your account ID to add an additional package medium once you have subscribed online"),
- @common),
- gtknew('HButtonBox', layout => 'start', children_tight => [
- interactive::gtk::add_padding(
- new_link_button('https://my.mandriva.com/info', N("More information on your user account")))
- ]),
- gtknew('Table', col_spacings => 5, row_spacings => 5, children => [
- [ N("Your email"), $email_w = gtknew('Entry', text => $email) ],
- [ N("Your password"), $password_w ],
- ]),
- gtknew('HButtonBox', layout => 'start', children_tight => [
- interactive::gtk::add_padding(
- new_link_button('https://my.mandriva.com/reset/password/', N("Forgotten password")))
- ]),
- create_okcancel($w, N("Next"), N("Cancel")),
- );
-
- fill_n_run_portable_dialog($w, \@widgets);
-
- $email = $email_w->get_text;
-
- # means OK handler got run:
- if ($password) {
- if ($email && $password) {
- add_extmaint_medium($email, $password);
- } else {
- interactive->vnew->ask_warn(N("Error"), N("Password and email cannot be empty."));
- goto &get_extmaint_authentication;
- }
- } else {
- ugtk2::exit(0);
- }
-}
-
-my $error;
-sub add_extmaint_medium {
- my ($email, $password) = @_;
-
- my $res = get_from("https://my.mandriva.com/rest/authenticate",
- [ 'username', $email, 'password', $password,
- 'return', 'userdata' ]);
- my $ref = xml2perl($res);
-
- if ($ref->{code} != 0) {
- my $in = interactive->vnew;
- $in->ask_warn(N("Error"), N("An error occurred") . "\n" . $ref->{message});
- goto &get_extmaint_authentication;
- } elsif (!ref($ref->{data}{groups}{'ext-maint-' . $version})) {
- no_rights_dialog();
- } else {
- $error = 0;
- my $arch = urpm::cfg::get_arch();
- actually_add_extmaint_medium($ref, $password, $arch)
- or adding_media_failed();
- # FIXME: is not enough if we ever support sparc64, ppc64 and the like:
- if ($arch eq 'x86_64') {
- actually_add_extmaint_medium($ref, $password, 'i586')
- or adding_media_failed();
- }
- if (!$error) {
- $config{EXTENDED_SUPPORT} = bool2yesno(1);
- setVarsInSh($config_file, \%config);
- #interactive->vnew->ask_okcancel(N("Error"), N("An error occurred while adding medium"));
- my $w = ugtk2->new(N("Successfully added media %s.", 'Extended Maintenance'), grab => 1);
- $w->_ask_okcancel(N("Successfully added media %s.", 'Extended Maintenance'), N("Ok"), undef);
- ugtk2::main($w);
- }
- }
-}
-
-sub no_rights_dialog() {
- my $w = ugtk2->new(N("Adding an additional package medium"), width => $width + 20);
-
- fill_n_run_portable_dialog(
- $w,
- [
- if_(!$::isEmbedded, get_banner(N("Extended Maintenance"))),
- gtknew('Label_Left', text => N("Your Mandriva account does not have Extended Maintenance subscription enabled."),
- @common),
- gtknew('HButtonBox', layout => 'start', children_tight => [
- interactive::gtk::add_padding(
- new_link_button('https://my.mandriva.com/', N("More Information")))
- ]),
- create_okcancel($w, N("Close"), undef),
- ]);
-}
-
-sub adding_media_failed {
- $error = 1;
- interactive->vnew->ask_warn(N("Error"), N("An error occurred while adding medium"));
- goto &get_extmaint_authentication;
-}
-
-sub actually_add_extmaint_medium {
- my ($ref, $password, $arch) = @_;
- $password = uri_escape($password);
- my @options = (get_urpmi_options(), '--update');
- my $email = uri_escape($ref->{data}{email});
- my $uri = "https://$email:$password\@dl.mandriva.com/extended/$version/$arch";
- run_program::raw(@options, "Extended Maintenance $arch " . int(rand(100000)), ${uri});
-}
diff --git a/mdkonline.pm b/mdkonline.pm
index a23eb26a..d3889ed8 100644
--- a/mdkonline.pm
+++ b/mdkonline.pm
@@ -61,6 +61,7 @@ our @EXPORT_OK = qw(
get_my_mdv_profile
add_medium_powerpack
add_medium_enterprise
+ add_medium_extended
);
our (%config, $product_id, $root);
@@ -246,6 +247,19 @@ sub add_medium_powerpack {
"${uri}updates/$arch");
}
+sub add_medium_extended {
+ my ($email, $password, $version, $arch) = @_;
+ my $uri = sprintf("https://%s:%s\@dl.mandriva.com/extended/%s/%s",
+ uri_escape($email),
+ uri_escape($password),
+ $version,
+ $arch);
+ my @options = (get_urpmi_options(), '--update');
+ run_program::raw(@options,
+ "Extended Maintenance $arch " . int(rand(100000)),
+ ${uri});
+}
+
sub is_running {
my ($name) = @_;
my $found;