From e7c430788d49e4c2c37465ca46b9d20dbeca328d Mon Sep 17 00:00:00 2001 From: Daouda Lo Date: Wed, 15 Feb 2006 15:33:15 +0000 Subject: - added code to handle bundle --- mdkupdate | 182 ++++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 107 insertions(+), 75 deletions(-) diff --git a/mdkupdate b/mdkupdate index 9ff97b84..244fe6ad 100755 --- a/mdkupdate +++ b/mdkupdate @@ -24,13 +24,17 @@ use strict; use POSIX; use lib qw(/usr/lib/libDrakX /usr/lib/libDrakX/drakfirsttime); use common; -use mdkonline; use interactive; + +use mdkonline; +use Data::Dumper; use urpm; -BEGIN { unshift @::textdomains, 'mdkupdate' } +use Getopt::Long; + +use SOAP::Lite; -#mdkonline::is_running('mdkupdate') and die "mdkupdate already running\n"; +BEGIN { unshift @::textdomains, 'mdkupdate' } require_root_capability(); @@ -64,90 +68,118 @@ Copyright (C) %s Mandriva. This is free software and may be redistributed under the terms of the GNU GPL. usage: -", $VERSION, $YEARS) . N(" --help - print this help message. -") . N(" --auto - Mandriva Update launched automatically. -") . N(" --applet - launch Mandriva Update. -") . N(" --mnf - launch mnf specific scripts. -") . N(" --noX - text mode version of Mandriva Update. +", $VERSION, $YEARS) . N(" --help - print this help message. +") . N(" --auto - Mandriva Update launched automatically. +") . N(" --applet - launch Mandriva Update. +") . N(" --mnf - launch mnf specific scripts. +") . N(" --noX - text mode version of Mandriva Update. +") . N(" --bundle file.bundle - parse and install package from .bundle metainfo file. "); exit(0); } -my ($opt) = @ARGV; -@ARGV == 1 && member($opt, qw(--auto --applet --mnf --noX)) or usage(); +my ($auto, $applet, $mnf, $noX, $bundle); +my %options = ( + 'auto' => \$auto, + 'a|applet' => \$applet, + 'mnf' => \$mnf, + 'noX' => \$noX, + 'b|bundle=s' => \$bundle + ); --s $conffile or die N("No %s file found. Run mdkonline wizard first", $conffile); +GetOptions(%options); +-s $conffile || $bundle or die N("No %s file found. Run mdkonline wizard first", $conffile); my %o = getVarsFromSh($conffile); -if ($o{LOGIN} && $o{PASS} && $o{LOGIN} !~ /\s+/ && $o{PASS} !~ /\s+/) { - my $u; - my $MandrakeUpdateURL = $url->{online3_RemoteAction} . '?action=ScheduledRPM' . '&log=' . $o{LOGIN} . '&pass=' . $o{PASS} . '&host=' . $o{MACHINE} . '&key=' . $o{CURRENTKEY}; - my $resp = mdkonline::get_from_URL($MandrakeUpdateURL, 'MdkUpdateAgent'); - my $contents = $resp->content; - print "CONTENTS = $contents \n"; - -e $logfile and system "/bin/rm", $logfile; - if ($resp->is_success) { - if ($contents =~ /TRUE/) { $u = 10 } elsif ($contents =~ m/(\d+)/) { $u = sprintf("%d", $1) } else { $u = 83 } - my $action = { - 10 => sub { - my $c2h = split_contents($contents); - #printf("\nCONTENTS = $contents \n torf = %s\n OLDKEY = %s = %s \n NEWKEY = %s \n FTP = %s\n", $c2h->{torf}, $c2h->{OLDKEY}, $o{CURRENTKEY}, $c2h->{NEWKEY}, $c2h->{FTP} ); - if ($c2h->{torf} eq "TRUE" && $c2h->{OLDKEY} && $c2h->{NEWKEY}) { update_conf($c2h->{OLDKEY}, $c2h->{NEWKEY}) } - if ($c2h->{FTP}) { - # for debugging purpose - printf("FTP = %s\n", $c2h->{FTP}); - #$c2h->{FTP} = 'ftp://ftp.lip6.fr/pub/linux/distributions/mandrake/updates'; - add_media($c2h->{FTP}); - } - $scheduled = join(',', @{$c2h->{sched}}); - $noscheduled = join(',', @{$c2h->{nosched}}); $noscheduled =~ s/\.rpm//g; - #printf "SCHEDULED = $scheduled\nNOSCHEDULED = $noscheduled\n"; - -f $currentrpm or rpm_qa($currentrpm); - my ($release) = mdkonline::get_release(); - if ($opt eq '--applet') { - my $rpm_exec_name = $release >= 2006.0 ? "/usr/bin/MandrivaUpdate" : "/usr/bin/MandrakeUpdate"; - my $is_no_media_update = $release <= 10.1 ? '' : "--no-media-update"; - system $rpm_exec_name, "--no-confirmation", $is_no_media_update, "--media=update_source"; - } elsif ($opt eq '--noX') { - my $in = interactive->vnew; - my $pkgs = ask_pkgs($in); - install_pkgs($in, $pkgs) if $pkgs; - $in->exit(0); - } elsif ($opt eq '--auto') { - $o{AUTO} eq 'TRUE' and auto_install_rpms($c2h->{sched}); - } - rpm_qa($afterrpm); - my %new = getVarsFromSh($conffile); - my $need_upload = get_rpm_diff(); - if ($need_upload || member($opt, qw(--auto --mnf))) { - #- send configuration and get back key to use... - my $r; - ($r, $new{CURRENTKEY}) = send_conf_update($new{LOGIN}, $new{PASS}, $new{MACHINE}); - $new{FTP} = if_($opt eq '--mnf', $c2h->{FTP}); - if ($r eq 'TRUE') { delete $new{OLDKEY}; setVarsInSh($conffile, \%new) } + +if (!$bundle) { + if ($o{LOGIN} && $o{PASS} && $o{LOGIN} !~ /\s+/ && $o{PASS} !~ /\s+/) { + my $u; + my $MandrakeUpdateURL = $url->{online3_RemoteAction} . '?action=ScheduledRPM' . '&log=' . $o{LOGIN} . '&pass=' . $o{PASS} . '&host=' . $o{MACHINE} . '&key=' . $o{CURRENTKEY}; + my $resp = mdkonline::get_from_URL($MandrakeUpdateURL, 'MdkUpdateAgent'); + my $contents = $resp->content; + # print "CONTENTS = $contents \n"; + -e $logfile and system "/bin/rm", $logfile; + if ($resp->is_success) { + if ($contents =~ /TRUE/) { $u = 10 } elsif ($contents =~ m/(\d+)/) { $u = sprintf("%d", $1) } else { $u = 83 } + my $action = { + 10 => sub { + my $c2h = split_contents($contents); + #printf("\nCONTENTS = $contents \n torf = %s\n OLDKEY = %s = %s \n NEWKEY = %s \n FTP = %s\n", $c2h->{torf}, $c2h->{OLDKEY}, $o{CURRENTKEY}, $c2h->{NEWKEY}, $c2h->{FTP} ); + if ($c2h->{torf} eq "TRUE" && $c2h->{OLDKEY} && $c2h->{NEWKEY}) { update_conf($c2h->{OLDKEY}, $c2h->{NEWKEY}) } + if ($c2h->{FTP}) { + # for debugging purpose + printf("FTP = %s\n", $c2h->{FTP}); + #$c2h->{FTP} = 'ftp://ftp.lip6.fr/pub/linux/distributions/mandrake/updates'; + add_media($c2h->{FTP}); + } + $scheduled = join(',', @{$c2h->{sched}}); + $noscheduled = join(',', @{$c2h->{nosched}}); $noscheduled =~ s/\.rpm//g; + #printf "SCHEDULED = $scheduled\nNOSCHEDULED = $noscheduled\n"; + -f $currentrpm or rpm_qa($currentrpm); + my ($release) = mdkonline::get_release(); + if ($applet) { + my $rpm_exec_name = $release >= 2006.0 ? "/usr/bin/MandrivaUpdate" : "/usr/bin/MandrakeUpdate"; + my $is_no_media_update = $release <= 10.1 ? '' : "--no-media-update"; + system $rpm_exec_name, "--no-confirmation", $is_no_media_update, "--media=update_source"; + } elsif ($noX) { + my $in = interactive->vnew; + my $pkgs = ask_pkgs($in); + install_pkgs($in, $pkgs) if $pkgs; + $in->exit(0); + } elsif ($auto) { + $o{AUTO} eq 'TRUE' and auto_install_rpms($c2h->{sched}); + } + rpm_qa($afterrpm); + my %new = getVarsFromSh($conffile); + my $need_upload = get_rpm_diff(); + if ($need_upload || $auto || $mnf) { + #- send configuration and get back key to use... + my $r; + ($r, $new{CURRENTKEY}) = send_conf_update($new{LOGIN}, $new{PASS}, $new{MACHINE}); + $new{FTP} = $mnf ? $c2h->{FTP} : ''; + if ($r eq 'TRUE') { delete $new{OLDKEY}; setVarsInSh($conffile, \%new) } + } + clean_dir(); + }, + 80 => sub { + output_p($logfile, "[mdkupdate] Error 80: Client password does not match in database"); + }, + 81 => sub { + output_p($logfile, "[mdkupdate] Error 81: Bad Authentification key. Please rerun mdkonline wizard"); + }, + 82 => sub { + output_p($logfile, "[mdkupdate] Error 82: No active Online service found for this host."); + }, + 83 => sub { + output_p($logfile, "[mdkupdate] Error 83: Unknown problem, better relaunch mdkonline wizard or check connexion"); } - clean_dir(); - }, - 80 => sub { - output_p($logfile, "[mdkupdate] Error 80: Client password does not match in database"); - }, - 81 => sub { - output_p($logfile, "[mdkupdate] Error 81: Bad Authentification key. Please rerun mdkonline wizard"); - }, - 82 => sub { - output_p($logfile, "[mdkupdate] Error 82: No active Online service found for this host."); - }, - 83 => sub { - output_p($logfile, "[mdkupdate] Error 83: Unknown problem, better relaunch mdkonline wizard or check connexion"); - } - }; - $action->{$u}->(); + }; + $action->{$u}->(); + } else { + output_p($logfile, N("Connection problem") . "\n" . N("Mandriva Update could not contact the site, we will try again.")); + } } else { - output_p($logfile, N("Connection problem") . "\n" . N("Mandriva Update could not contact the site, we will try again.")); + my $ret = -1; } } else { - my $ret = -1; + my $data; + my $namespace = 'http://online3.mandriva.com/o/soap/'; + my $serviceProxy = $namespace; + my %bundle_vars = getVarsFromSh($bundle); + $o{LOGIN} or system("/usr/sbin/mdkonline"); + $o{LOGIN} or die("Configuration not uploaded to Mandriva Online"); + my $s = SOAP::Lite + ->proxy($serviceProxy) + ->uri($namespace); + my $hostname = chomp_(`hostname`); + $data = $s->authenticateUser( $o{LOGIN}, $o{PASS} )->result(); + $data = $s->registerHost( $o{LOGIN}, $o{PASS}, $hostname, "plop" )->result(); + my $id = $data->{data}->{host_id}; + my $key = $data->{data}->{host_key}; + $data = $s->query( $id, $key, 'Software::get_bundle', $bundle_vars{BUNDLE} )->result(); } + sub ask_pkgs { my ($in) = @_; my $pkgs = get_updatable_pkgs(); -- cgit v1.2.1