diff options
author | Thierry Vignaud <tv@mandriva.org> | 2008-11-20 15:39:02 +0000 |
---|---|---|
committer | Thierry Vignaud <tv@mandriva.org> | 2008-11-20 15:39:02 +0000 |
commit | 8e89db36edb0a89d44c2da73b83a18c76af6b29e (patch) | |
tree | a918f38d1ffe7587e72f320f32fe23f5530b98b8 | |
parent | 77522e96a4a4fdf6dbe1dbceb8a2ff096c3488b4 (diff) | |
download | mgaonline-8e89db36edb0a89d44c2da73b83a18c76af6b29e.tar mgaonline-8e89db36edb0a89d44c2da73b83a18c76af6b29e.tar.gz mgaonline-8e89db36edb0a89d44c2da73b83a18c76af6b29e.tar.bz2 mgaonline-8e89db36edb0a89d44c2da73b83a18c76af6b29e.tar.xz mgaonline-8e89db36edb0a89d44c2da73b83a18c76af6b29e.zip |
offer to add the restricted update medium if not available
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | NEWS | 3 | ||||
-rwxr-xr-x | mdkapplet | 45 | ||||
-rwxr-xr-x | mdkapplet-restricted-helper | 127 |
4 files changed, 176 insertions, 1 deletions
@@ -33,6 +33,7 @@ clean: install: all install -d $(PREFIX)/usr/{sbin,bin,share/{mime/packages,$(NAME)/pixmaps,autostart,gnome/autostart,icons/{mini,large}},lib/libDrakX/drakfirsttime} install -m755 mdkapplet-upgrade-helper $(SBINDIR) + install -m755 mdkapplet-restricted-helper $(SBINDIR) install -m755 $(MDKUPDATE) $(SBINDIR) install -m755 $(MDKAPPLET) $(BINDIR) install -d $(SYSCONFDIR) @@ -56,6 +57,7 @@ install: all install -m644 pam.d_urpmi.update $(PREFIX)/etc/pam.d/urpmi.update ln -sf consolehelper $(PREFIX)/usr/bin/urpmi.update ln -sf consolehelper $(PREFIX)/usr/bin/mdkapplet-upgrade-helper + ln -sf consolehelper $(PREFIX)/usr/bin/mdkapplet-restricted-helper cleandist: rm -rf $(PACKAGE)-$(VERSION) ../$(PACKAGE)-$(VERSION).tar.bz2 @@ -1,3 +1,6 @@ +- mdkapplet + o offer to add the restricted update medium if not available + Version 2.67 - 23 October 2008 - mdkapplet @@ -99,6 +99,13 @@ my %state = ( urgency => 'low', tt => [ N("A new version of Mandriva Linux distribution has been released") ] }, + unconfigured_restricted_media => { + colour => [ 'bundle' ], + changes => [ 'okay' ], + menu => [ 'add_restricted_media', 'check' ], + urgency => 'low', + tt => [ N("An additional package medium is available for your distribution.") ] + }, disconnected => { colour => [ 'disconnect' ], changes => [ 'okay', 'busy', 'critical', 'error' ], @@ -179,10 +186,16 @@ my %comm_codes = ( status => 'critical', log => "Failed to open urpmi database\n", }, + unconfigured_restricted_media => { + code => 9, + status => 'unconfigured_restricted_media', + log => "Missing restricted media\n", + }, ); my %actions = ( 'update' => { name => N("Install updates"), launch => sub { installUpdates() } }, + 'add_restricted_media' => { name => N("Add additional package medium"), launch => \&prepare_add_restricted }, 'check' => { name => N("Check Updates"), launch => \&checkUpdates }, 'confNetwork' => { name => N("Configure Network"), launch => sub { configNetwork() } }, 'upgrade_distro' => { name => N("Upgrade the system"), launch => \&upgrade }, @@ -196,6 +209,7 @@ $icon->signal_connect(popup_menu => sub { }); $icon->signal_connect(activate => sub { my %actions = ( + unconfigured_restricted_media => \&prepare_add_restricted, no_update_medium => \&add_media, no_enabled_medium => \&add_media, updates => \&installUpdates, @@ -504,7 +518,13 @@ sub silentCheck() { if ($need_restart || @requested_strict) { # FIXME: log first found pkgs? checker_exit('updates'); } else { - checker_exit('uptodate'); + if (!text2bool($local_config{DO_NOT_ASK_FOR_RESTRICTED})) { + if (is_restricted_media_configured($urpm)) { + checker_exit('uptodate'); + } else { + checker_exit('unconfigured_restricted_media'); + } + } } } else { checker_exit('db_not_open'); @@ -596,6 +616,8 @@ sub setState { } elsif ($state eq 'updates') { unshift @arr, 'upgrade_distro' if $new_distro; $bubble->add_action('clicked', N("Install updates"), \&installUpdates); + } elsif ($state eq 'unconfigured_restricted_media') { + $bubble->add_action('clicked', N("More Information"), \&prepare_add_restricted); } elsif (member($state, qw(no_enabled_medium no_update_medium))) { $bubble->add_action('clicked', N("Add media"), \&add_media); } @@ -662,3 +684,24 @@ sub mainQuit() { Glib::Source->remove($network_timeout) if $network_timeout; Gtk2->main_quit; } + +sub get_enabled_restricted_media { + my ($urpm) = @_; + grep { $_->{name} =~ /restricted/i && !$_->{ignore} } @{$urpm->{media}}; +} + +sub is_restricted_media_configured { + my ($urpm) = @_; + $product_id = common::parse_LDAP_namespace_structure(cat_("$root/etc/product.id")); + return 1 if $product_id->{product} !~ /powerpack/i; + + my @restricted_media = get_enabled_restricted_media($urpm); + my @names = map { $_->{name} } @restricted_media; + # we need both 'Restricted' & 'Restricted Update' media + # those who did online update trough mdkapplet do not have restricted medium, hence the test for 2 medium: + grep { /Restricted Updates/ } @names; +} + +sub prepare_add_restricted() { + run_program::run('mdkapplet-restricted-helper'); +} diff --git a/mdkapplet-restricted-helper b/mdkapplet-restricted-helper new file mode 100755 index 00000000..0a16331b --- /dev/null +++ b/mdkapplet-restricted-helper @@ -0,0 +1,127 @@ +#!/usr/bin/perl +################################################################################ +# Mandriva Online # +# # +# Copyright (C) 2008 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; +use feature 'state'; + +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; + +foreach my $opt (@ARGV) { + if ($opt =~ /--(rpm-root|urpmi-root)=(.*)/) { + $::rpmdrake_options{$1}[0] = $2; + } +} + +prepare_add_restricted(); + +ugtk2::exit(0); + +sub prepare_add_restricted() { + local $mygtk2::left_padding = 0; + my $warn_me = text2bool($local_config{DO_NOT_ASK_FOR_RESTRICTED}); + return if $warn_me; + my $w = new_portable_dialog(N("New medium available")); + my $res = + fill_n_run_portable_dialog( + $w, + [ + get_banner(), + gtknew('Label_Left', text => N("You are using '%s' distribution.", N("Mandriva PowerPack")), @common), + gtknew('Label_Left', text => N("Do you want to add an additional package medium distribution?"), @common), + gtknew('CheckButton', text => N("Do not ask me next time"), active_ref => \$warn_me), + create_okcancel($w, N("Next"), N("Cancel")), + ]); + setVar('DO_NOT_ASK_FOR_RESTRICTED', bool2text($warn_me)); + $local_config{DO_NOT_ASK_FOR_RESTRICTED} = bool2text($warn_me); + $res ? get_restricted_authentication() : 0; +} + +sub get_restricted_authentication() { + local $mygtk2::left_padding = 0; + 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); + $w->{real_window}->signal_connect(destroy => sub { $password = $password_w->get_text }); + my $res = + fill_n_run_portable_dialog( + $w, + [ + get_banner(), + gtknew('Label_Left', text => N("Please fill in your account ID to add an additional package medium"), + @common), + new_link_button('https://my.mandriva.com/info', N("More information on your user account")), + gtknew('Table', children => [ + [ N("Your email"), $email_w = gtknew('Entry') ], + [ N("Your password"), $password_w ], + ]), + new_link_button('https://my.mandriva.com/reset/password/', N("Forgotten password")), + create_okcancel($w, N("Next"), N("Cancel")), + ]); + + $res ? add_restricted_medium($email_w->get_text, $password) : 0; +} + +sub get_from { + my ($link, $header) = @_; + + my $ua = LWP::UserAgent->new; + $ua->agent("mdkapplet (mdkonline-$mdkonlin::version)"); + $ua->env_proxy; + + my $response = $ua->request(POST $link, $header); + $response; +} + +sub add_restricted_medium { + my ($email, $password) = @_; + + my $res = get_from("https://my.mandriva.com/rest/authenticate", [ 'username', $email, 'password', $password ]); + my $ref = XML::Simple->new->XMLin($res->{_content}); + + if ($ref->{code} != 0) { + my $in = interactive->vnew; + $in->ask_warn(N("Error"), N("An error occurred") . "\n" . $ref->{message}); + goto &get_restricted_authentication; + } else { + run_program::raw({ sensitive_arguments => 1 }, 'urpmi.addmedia', 'Restricted Update ' . int(rand(100000)), + "https://" . uri_escape($ref->{data}{email}) . ":$password\@dl.mandriva.com/rpm/comm/2009.0/" . urpm::cfg::get_arch()); + } +} |