summaryrefslogtreecommitdiffstats
path: root/mdkapplet
blob: abe995437bff9e95ae62a245d9f92c60e2dcfcc2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
Diffstat (limited to 'perl-install')
-rw-r--r--perl-install/network/adsl.pm1
-rw-r--r--perl-install/network/ethernet.pm72
-rw-r--r--perl-install/network/netconnect.pm107
-rw-r--r--perl-install/network/tools.pm2
-rwxr-xr-xperl-install/standalone/draknet2
5 files changed, 80 insertions, 104 deletions
diff --git a/perl-install/network/adsl.pm b/perl-install/network/adsl.pm
index 53b4a440c..2583cbd29 100644
--- a/perl-install/network/adsl.pm
+++ b/perl-install/network/adsl.pm
@@ -11,6 +11,7 @@ use vars qw(@ISA @EXPORT);
@EXPORT = qw(adsl_ask_info adsl_detect adsl_conf adsl_conf_backend);
sub configure{
+ my ($netcnx, $netc, $intf, $first_time) = @_;
$::isInstall and $in->set_help('configureNetworkADSL');
conf_adsl_step1:
my $type = $in->ask_from_list_(_("Connect to the Internet"),
diff --git a/perl-install/network/ethernet.pm b/perl-install/network/ethernet.pm
index c03d64e9a..5417520b8 100644
--- a/perl-install/network/ethernet.pm
+++ b/perl-install/network/ethernet.pm
@@ -10,6 +10,78 @@ use vars qw(@ISA @EXPORT);
@ISA = qw(Exporter);
@EXPORT = qw(conf_network_card conf_network_card_backend go_ethernet);
+sub configure_cable {
+ my ($netcnx, $netc, $intf, $first_time) = @_;
+ $::isInstall and $in->set_help('configureNetworkCable');
+ $netcnx->{type}='cable';
+ # $netcnx->{cable}={};
+ # $in->ask_from_entries_ref(_("Cable connection"),
+ # _("Please enter your host name if you know it.
+ # Some DHCP servers require the hostname to work.
+ # Your host name should be a fully-qualified host name,
+ # such as ``mybox.mylab.myco.com''."),
+ # [_("Host name:")], [ \$netcnx->{cable}{hostname} ]);
+ if ($::expert) {
+ my @m=(
+ { description => "dhcpcd",
+ c => 1},
+ { description => "dhcpxd",
+ c => 3},
+ { description => "dhcp-client",
+ c => 4},
+ );
+ if (my $f = $in->ask_from_listf(_("Connect to the Internet"),
+ _("Which dhcp client do you want to use?
+Default is dhcpcd"),
+ sub { $_[0]{description} },
+ \@m )) {
+ $f->{c}==1 and $netcnx->{dhcp_client}="dhcpcd" and $install->(qw(dhcpcd));
+ $f->{c}==3 and $netcnx->{dhcp_client}="dhcpxd" and $install->(qw(dhcpxd));
+ $f->{c}==4 and $netcnx->{dhcp_client}="dhcp-client" and $install->(qw(dhcp-client));
+ }
+ } else {
+ $install->(qw(dhcpcd));
+ }
+ go_ethernet($netc, $intf, 'dhcp', '', '', $first_time);
+}
+
+sub configure_lan {
+ my ($netcnx, $netc, $intf, $first_time) = @_;
+ $::isInstall and $in->set_help('configureNetworkIP');
+ require Data::Dumper;
+ print "plop :" . Data::Dumper->Dump([\$in], ['$in']) . "\n";
+ network::configureNetwork($prefix, $netc, $in, $intf, $first_time) or return;
+ network::configureNetwork2($in, $prefix, $netc, $intf, $install);
+ if ($::isStandalone and $in->ask_yesorno(_("Network configuration"),
+ _("Do you want to restart the network"), 1)) {
+ run_program::rooted($prefix, "/etc/rc.d/init.d/network stop");
+ if (!run_program::rooted($prefix, "/etc/rc.d/init.d/network start")) {
+ $in->ask_okcancel(_("Network Configuration"), _("A problem occured while restarting the network: \n\n%s", `/etc/rc.d/init.d/network start`), 0) or return;
+ }
+ }
+ $netc->{NETWORKING} = "yes";
+ if ($netc->{GATEWAY}) {
+ $netcnx->{type}='lan';
+ $netcnx->{NET_DEVICE} = $netc->{NET_DEVICE} = '';
+ $netcnx->{NET_INTERFACE} = 'lan'; #$netc->{NET_INTERFACE};
+ }
+ output "$prefix$connect_file",
+ qq(
+#!/bin/bash
+/etc/rc.d/init.d/network restart
+);
+ output "$prefix$disconnect_file",
+ qq(
+#!/bin/bash
+/etc/rc.d/init.d/network stop
+/sbin/ifup lo
+);
+ chmod 0755, "$prefix$disconnect_file";
+ chmod 0755, "$prefix$connect_file";
+ $::isStandalone and modules::write_conf($prefix);
+ 1;
+}
+
sub conf_network_card {
my ($netc, $intf, $type, $ipadr, $netadr) = @_;
#-type =static or dhcp
diff --git a/perl-install/network/netconnect.pm b/perl-install/network/netconnect.pm
index 8447df8d8..ae1d2abcf 100644
--- a/perl-install/network/netconnect.pm
+++ b/perl-install/network/netconnect.pm
@@ -88,98 +88,10 @@ sub main {
($prefix, my $netcnx, my $netc, my $mouse, $in, my $intf, $install, my $first_time, my $direct_fr) = @_;
$netc->{minus_one}=0; #When one configure an eth in dhcp without gateway
$::isInstall and $in->set_help('configureNetwork');
- my $continue = !(!$::expert && values %$intf > 0 && $first_time);
$::isStandalone and read_net_conf($netcnx, $netc); # REDONDANCE with intro. FIXME
$netc->{NET_DEVICE}=$netcnx->{NET_DEVICE} if $netcnx->{NET_DEVICE}; # REDONDANCE with read_conf. FIXME
$netc->{NET_INTERFACE}=$netcnx->{NET_INTERFACE} if $netcnx->{NET_INTERFACE}; # REDONDANCE with read_conf. FIXME
network::read_all_conf($prefix, $netc ||= {}, $intf ||= {});
-# $in->set_help('') unless $::isStandalone;
-
-#use network::adsl;
-#use network::ethernet;
-#use network::isdn;
-#use network::modem;
-
- my $configure_modem = sub {
- require network::modem;
- network::modem::configure($netcnx, $mouse, $netc);
- };
-
- my $configure_isdn = sub {
- require network::isdn;
- network::isdn::configure($netcnx, $netc);
- };
- my $configure_adsl = sub {
- require network::adsl;
- network::adsl::configure($netcnx, $netc);
- };
- my $configure_cable = sub {
- $::isInstall and $in->set_help('configureNetworkCable');
- $netcnx->{type}='cable';
- # $netcnx->{cable}={};
- # $in->ask_from_entries_ref(_("Cable connection"),
- # _("Please enter your host name if you know it.
- # Some DHCP servers require the hostname to work.
- # Your host name should be a fully-qualified host name,
- # such as ``mybox.mylab.myco.com''."),
- # [_("Host name:")], [ \$netcnx->{cable}{hostname} ]);
- if ($::expert) {
- #- dhcpcd, etc are program names; no need to translate them.
- my @m=(
- { description => "dhcpcd",
- c => 1},
- { description => "dhcpxd",
- c => 3},
- { description => "dhcp-client",
- c => 4},
- );
- if (my $f = $in->ask_from_listf(_("Connect to the Internet"),
- _("Which dhcp client do you want to use?
-Default is dhcpcd"),
- sub { $_[0]{description} },
- \@m )) {
- $f->{c}==1 and $netcnx->{dhcp_client}="dhcpcd" and $install->(qw(dhcpcd));
- $f->{c}==3 and $netcnx->{dhcp_client}="dhcpxd" and $install->(qw(dhcpxd));
- $f->{c}==4 and $netcnx->{dhcp_client}="dhcp-client" and $install->(qw(dhcp-client));
- }
- } else {
- $install->(qw(dhcpcd));
- }
- go_ethernet($netc, $intf, 'dhcp', '', '', $first_time);
- };
- my $configure_lan = sub {
- $::isInstall and $in->set_help('configureNetworkIP');
- network::configureNetwork($prefix, $netc, $in, $intf, $first_time) or return;
- network::configureNetwork2($in, $prefix, $netc, $intf, $install);
- if ($::isStandalone and $in->ask_yesorno(_("Network configuration"),
- _("Do you want to restart the network"), 1)) {
- run_program::rooted($prefix, "/etc/rc.d/init.d/network stop");
- if (!run_program::rooted($prefix, "/etc/rc.d/init.d/network start")) {
- $in->ask_okcancel(_("Network Configuration"), _("A problem occured while restarting the network: \n\n%s", `/etc/rc.d/init.d/network start`), 0) or return;
- }
- }
- $netc->{NETWORKING} = "yes";
- if ($netc->{GATEWAY}) {
- $netcnx->{type}='lan';
- $netcnx->{NET_DEVICE} = $netc->{NET_DEVICE} = '';
- $netcnx->{NET_INTERFACE} = 'lan';#$netc->{NET_INTERFACE};
- }
- output "$prefix$connect_file",
- qq(
-#!/bin/bash
-/etc/rc.d/init.d/network restart
-);
- output "$prefix$disconnect_file",
- qq(
-#!/bin/bash
-/etc/rc.d/init.d/network stop
-/sbin/ifup lo
-);
- chmod 0755, "$prefix$disconnect_file";
- chmod 0755, "$prefix$connect_file";
- $::isStandalone and modules::write_conf($prefix);
- 1;
- };
modules::mergein_conf("$prefix/etc/modules.conf");
@@ -239,15 +151,6 @@ ifdown eth0
my $i=0;
map { defined $set_default or do { $_->[1] and $set_default=$i; }; $i++; } @l;
foreach (keys %{$netc->{autodetect}}) { print "plop $_\n" };
-# my $e = $in->ask_from_listf(_("Network Configuration Wizard"),
-# _("How do you want to connect to the Internet?"), sub { translate($_[0][0]) . if_($_[0][1], " - " . _ ($_[0][2], $_[0][1])) }, \@l , $l[$set_default]
-# ) or goto step_1;
-
-# my @l2 = map {
-#{
-# label => $_[0][0] . if_($_[0][1], " - " . _ ($_[0][2], $_[0][1])),
-# val => $_[0][3], type => 'bool'}
-# } @l;
my $e = $in->ask_from_entries_refH(_("Network Configuration Wizard"),
_("Choose"),
[
@@ -259,11 +162,11 @@ ifdown eth0
# load_conf ($netcnx, $netc, $intf);
- $conf{modem} and do { $configure_modem->() or goto step_2 };
- $conf{isdn} and do { $configure_isdn->() or goto step_2 };
- $conf{adsl} and do { $configure_adsl->() or goto step_2 };
- $conf{cable} and do { $configure_cable->() or goto step_2 };
- $conf{lan} and do { $configure_lan->() or goto step_2 };
+ $conf{modem} and do { require network::modem; network::modem::configure($netcnx, $mouse, $netc) or goto step_2 };
+ $conf{isdn} and do { require network::isdn; network::isdn::configure($netcnx, $netc) or goto step_2 };
+ $conf{adsl} and do { require network::adsl; network::adsl::configure($netcnx, $netc, $intf, $first_time) or goto step_2 };
+ $conf{cable} and do { require network::ethernet; network::ethernet::configure_cable($netcnx, $netc, $intf, $first_time) or goto step_2 };
+ $conf{lan} and do { require network::ethernet; network::ethernet::configure_lan($netcnx, $netc, $intf, $first_time) or goto step_2 };
step_3:
diff --git a/perl-install/network/tools.pm b/perl-install/network/tools.pm
index 5f064ee73..8234c8143 100644
--- a/perl-install/network/tools.pm
+++ b/perl-install/network/tools.pm
@@ -1,6 +1,6 @@
package network::tools;
-use common qw(:common :file)
+use common qw(:common :file);
use run_program;
use vars qw(@ISA @EXPORT);
diff --git a/perl-install/standalone/draknet b/perl-install/standalone/draknet
index c2671dde4..374a0e423 100755
--- a/perl-install/standalone/draknet
+++ b/perl-install/standalone/draknet
@@ -333,7 +333,7 @@ Gtk->main;
Gtk->exit(0);
dd:
-netconnect::intro('', $netcnx, $in, sub { $in->standalone::pkgs_install(@_) });
+network::netconnect::intro('', $netcnx, $in, sub { $in->standalone::pkgs_install(@_) });
$in->exit(0);
le => 1, tt => [ N_("Please wait, finding available packages...") ] }, updates => { colour => [ 'error' ], changes => [ 'okay' ], menu => [ 'update', 'check' ], tt => [ N_("New updates are available for your system") ] }, new_distribution => { colour => [ 'bundle' ], changes => [ 'okay' ], menu => [ 'upgrade_distro', 'check' ], tt => [ N("A new stable distribution has been released") . "\n\n" . N("Do you want to upgrade?") ] }, disconnected => { colour => [ 'disconnect' ], changes => [ 'okay', 'busy', 'critical', 'error' ], menu => [ 'confNetwork' ], tt => [ N_("Network is down. Please configure your network") ] }, disabled => { colour => [ 'disabled' ], changes => [ 'okay', 'busy', 'critical', 'error' ], menu => [], tt => [ N_("Service is not activated. Please click on \"Online Website\"") ] }, locked => { colour => [ 'noconf' ], changes => [ 'okay', 'busy', 'critical', 'disconnected' ], menu => [ 'check' ], tt => [ N_("urpmi database locked") ], do_not_use_bubble => 1, }, notsupported => { colour => [ 'disabled' ], changes => [ 'okay', 'busy', 'critical', 'error' ], menu => [], tt => [ N_("Release not supported (too old release, or development release)") ] }, no_update_medium => { colour => [ 'noconf' ], changes => [ 'okay', 'busy', 'critical', 'disconnected' ], menu => [ 'check' ], tt => [ N_("No medium found. You must add some media through 'Software Media Manager'.") ], }, no_enabled_medium => { colour => [ 'noconf' ], changes => [ 'okay', 'busy', 'critical', 'disconnected' ], menu => [ 'check' ], tt => [ N("You already have at least one update medium configured, but all of them are currently disabled. You should run the Software Media Manager to enable at least one (check it in the \"%s\" column). Then, restart \"%s\".", N("Enabled"), 'mdkapplet') ], }, ); my %comm_codes = ( locked => { code => 2, status => 'locked', log => "urpmi database locked, skipping updating urpmi database", }, error_updating => { code => 3, status => 'critical', log => N_("Error updating media"), }, no_update_medium => { code => 4, status => 'no_update_medium', log => "no update media configured", }, no_enabled_medium => { code => 5, status => 'no_enabled_medium', log => "all update media are disabled", }, updates => { code => 6, status => 'updates', log => "Checking... Updates are available\n\n", }, uptodate => { code => 7, status => 'okay', log => "Packages are up to date\n", }, db_not_open => { code => 8, status => 'critical', log => "Failed to open urpmi database\n", }, ); my %actions = ( 'update' => { name => N("Install updates"), launch => sub { installUpdates() } }, 'check' => { name => N("Check Updates"), launch => \&checkUpdates }, 'confNetwork' => { name => N("Configure Network"), launch => sub { configNetwork() } }, 'upgrade_distro' => { name => N("Upgrade the system"), launch => \&upgrade }, ); my $icon = Gtk2::StatusIcon->new; #$icon->shape_combine_mask($img, 0, 0); $icon->signal_connect(popup_menu => sub { my ($_icon, $button, $time) = @_; $menu and $menu->popup(undef, undef, undef, undef, $button, $time); }); $icon->signal_connect(activate => sub { my %actions = ( no_update_medium => \&add_media, no_enabled_medium => \&add_media, updates => \&installUpdates, new_distribution => \&upgrade, ); my $action = $state_global; # default to updates rather than distro upgrade: if ($action eq 'new_distribution' && $sub_state eq 'updates') { $action = 'updates'; } $actions{$action}->() if ref $actions{$action}; }); foreach my $opt (@ARGV) { if ($opt eq '--force' || $opt eq '-f') { setAutoStart('TRUE') } if ($opt =~ /--(rpm-root|urpmi-root)=(.*)/) { $::rpmdrake_options{$1}[0] = $2; } } my $root = Rpmdrake::open_db::fast_open_urpmi_db()->{root}; my $new_distro; my $product_id; shouldStart() or die "$localfile should be set to TRUE: please use --force or -f option to launch applet\n"; go2State('delayed'); Glib::Timeout->add($config{FIRST_CHECK_DELAY}, sub { # schedule future checks: setup_cyclic_check(); # perform a test after initial delay: checkNetwork(); checkUpdates(); 0; }); $SIG{USR1} = 'IGNORE'; $SIG{USR2} = 'IGNORE'; $SIG{CHLD} = \&harvester; run_program::raw({ detach => 1 }, 'ionice', '-p', $$, '-n7'); Gtk2->main; ugtk2::exit(0); sub is_there_a_new_distributions() { $product_id = common::parse_LDAP_namespace_structure(cat_("$root/etc/product.id")); return if $product_id->{product} =~ /Flash/; #- contact the following URL to retrieve the list of released distributions. my $type = lc($product_id->{type}); $type =~ s/\s//g; my $extra_path = $::testing || uc($config{TEST_DISTRO_UPGRADE}) eq 'YES' ? 'testing-' : ''; my $list = "http://api.mandriva.com/distributions/$extra_path$type.$product_id->{arch}.list?product=$product_id->{product}"; log::explanations("trying distributions list from $list"); my @lines = eval { my $urpm = Rpmdrake::open_db::fast_open_urpmi_db(); # prevent SIGCHILD handler's waitpid to interfere with urpmi waiting # for curl exit code, which broke downloads: local $SIG{CHLD} = 'DEFAULT'; if (member($product_id->{version}, qw(2007.1 2008.0 2008.1))) { require mdkapplet_urpm; mdkapplet_urpm::ensure_valid_cachedir($urpm); mdkapplet_urpm::get_content($urpm, $list); } else { urpm::ensure_valid_cachedir($urpm); urpm::download::get_content($urpm, $list); } }; if (my $err = $@) { log::explanations("failed to download distribution list:\n$err"); return; # not a fatal error } if (!@lines) { log::explanations("empty distribution list"); return; } my @distros = map { common::parse_LDAP_namespace_structure(chomp_($_)) } @lines; # only compare first distro: if it's not the same as the currently installed one, # then it's the most recent release: my $new_distribution = $distros[0]; return if !member($product_id->{version}, map { $_->{version} } @distros); if ($new_distribution && $new_distribution->{version} ne $product_id->{version}) { $new_distro = $new_distribution; log::explanations(sprintf("new '%s' distribution was released on %s", $new_distro->{version}, $new_distro->{release_date})); return 1; } } my ($mdv_update_pid, $checker_pid, $media_manager_pid); # Signal management sub harvester { my ($_signame, $_clean) = @_; my ($childpid, @pids); my $mdvupdate_returned; do { $childpid = waitpid(-1, &WNOHANG); my $status = $? >> 8; if ($mdv_update_pid && $mdv_update_pid == $childpid) { undef $mdv_update_pid; $mdvupdate_returned = 1; } elsif ($checker_pid && $checker_pid == $childpid) { undef $checker_pid; my ($state) = grep { $_->{code} eq $status } values %comm_codes; if ($state) { log::explanations($state->{log}); $sub_state = $state->{status}; go2State($new_distro && $config{DO_NOT_ASK_FOR_DISTRO_UPGRADE} !~ /^true$/i && $local_config{DO_NOT_ASK_FOR_DISTRO_UPGRADE} !~ /^true$/i ? 'new_distribution' : $sub_state); } } elsif ($media_manager_pid && $media_manager_pid == $childpid) { undef $media_manager_pid; } push @pids, $childpid; } while $childpid > 0; Glib::Timeout->add(200, sub { silentCheck(); 0 }) if $mdvupdate_returned; return @pids; } sub configNetwork() { log::explanations(N_("Launching drakconnect\n")); fork_exec("/usr/sbin/drakconnect") } sub confirm_upgrade() { local $mygtk2::left_padding = 0; my $width = 500; my $w = ugtk2->new(N("A new stable distribution has been released")); my $warn_me = text2bool($local_config{DO_NOT_ASK_FOR_DISTRO_UPGRADE}); gtkadd($w->{window}, gtknew('VBox', children_tight => [ get_banner(), gtknew('Label_Left', text => N("A new stable distribution has been released."), # workaround infamous 6 years old gnome bug #101968: width => $width - 50), gtknew('HButtonBox', layout => 'start', children_tight => [ my $link = Gtk2::LinkButton->new($new_distro->{url}, N("More info about this new version")), ]), gtknew('Label_Left', text => N("Do you want to upgrade to the '\%s' distribution?", $new_distro->{name} || $new_distro->{version}), # workaround infamous 6 years old gnome bug #101968: width => $width - 50), gtknew('CheckButton', text => N("Do not ask me next time"), active_ref => \$warn_me), create_okcancel($w, N("Yes"), N("No")), ]), ); $link->set_uri_hook(sub { my (undef, $url) = @_; run_program::raw({ detach => 1, setuid => get_parent_uid() }, 'www-browser', $url); }); $w->{ok}->grab_focus; my $res = $w->main; setVar('DO_NOT_ASK_FOR_DISTRO_UPGRADE', bool2text($warn_me)); $local_config{DO_NOT_ASK_FOR_DISTRO_UPGRADE} = bool2text($warn_me); $res; } my $already_in_upgrade; sub upgrade() { return if $already_in_upgrade; $already_in_upgrade = 1; my $_a = before_leaving { undef $already_in_upgrade }; return if !confirm_upgrade(); $mdv_update_pid = fork_exec('mdkapplet-upgrade-helper', "--new_distro_version=$new_distro->{version}", if_($root, "--urpmi-root=$root")); } sub add_media() { return if $media_manager_pid; log::explanations("Launching 'Software Media Manager'"); $media_manager_pid = fork_exec('/usr/sbin/edit-urpm-sources.pl', '--no-splash', if_($root, "--urpmi-root=$root")); silentCheck(); gtkflush(); } sub installUpdates() { return if $mdv_update_pid; log::explanations(N_("Launching MandrivaUpdate\n")); $mdv_update_pid = fork_exec('MandrivaUpdate', '--no-media-update', '--no-confirmation', '--no-splash', if_($root, "--urpmi-root=$root")); silentCheck(); gtkflush(); } sub silentCheck() { state $check_time; my $new_time = time(); undef $new_distro; if (!$check_time || $new_time - $check_time > $config{DISTRO_CHECK_DELAY}) { $check_time = $new_time; is_there_a_new_distributions(); } return if $mdv_update_pid || $checker_pid; log::explanations(N_("Computing new updates...\n")); log::explanations("Connecting to ...\n"); # i18n bug to fix in cooker my $w = $::main_window ? $::main_window->window : undef; gtkset_mousecursor_wait($w); go2State('busy'); gtkset_mousecursor_normal($w); # are there any updates ? $checker_pid = fork(); if (defined $checker_pid) { return if $checker_pid; # parent # immediate exit, else forked gtk+ object destructors will badly catch up parent applet my $_safe = before_leaving { POSIX::_exit(0) }; # be nice with other processes: setpriority(0, $$, 7); # 0 is PRIO_PROCESS my $exit = sub { my ($state) = @_; POSIX::_exit($comm_codes{$state}{code}); }; my $will_not_update_media; require urpm; require urpm::lock; # so that get_inactive_backport_media() doesn't vivify $urpm->{media}: my $urpm = Rpmdrake::open_db::fast_open_urpmi_db(); { local $urpm->{fatal} = sub { print "Fatal: @_\n"; $will_not_update_media = 1; }; local $urpm->{error} = $urpm->{fatal}; urpm::lock::urpmi_db($urpm, 'exclusive', 1); } $exit->('locked') if $will_not_update_media; if (!run_program::raw({ sensitive_arguments => 1 }, 'urpmi.update', '--update', if_($root, "--urpmi-root=$root"))) { $exit->('error_updating') if $will_not_update_media; } # update inactive backport media: my @inactive_backport_media = Rpmdrake::open_db::get_inactive_backport_media($urpm); log::explanations("updating inactive backport media " . join(', ', @inactive_backport_media)) if @inactive_backport_media; run_program::run('urpmi.update', if_($root, "--urpmi-root=$root"), $_) foreach @inactive_backport_media; require urpm::select; require urpm::media; urpm::media::configure($urpm, update => 1); my @update_medias = grep { $_->{update} } @{$urpm->{media}}; if (!@update_medias) { $exit->('no_update_medium'); } elsif (!any { ! $_->{ignore} } @update_medias) { $exit->('no_enabled_medium'); } if (my $_db = urpm::db_open_or_die($urpm)) { my $requested = {}; my $state = {}; my $need_restart = urpm::select::resolve_dependencies( $urpm, $state, $requested, callback_choices => sub { 0 }, priority_upgrade => $urpm->{options}{'priority-upgrade'}, auto_select => 1, ); my @requested_strict = map { scalar $_->fullname } @{$urpm->{depslist}}[keys %{$state->{selected}}]; if ($need_restart || @requested_strict) { # FIXME: log first found pkgs? $exit->('updates'); } else { $exit->('uptodate'); } } else { $exit->('db_not_open'); } $exit->('updates'); } else { log::explanations("cannot fork: %s", "update checker ($!)"); go2State('critical'); } } sub okState() { log::explanations(N_("System is up-to-date\n")); go2State('okay') } sub setup_cyclic_check() { $network_timeout = Glib::Timeout->add(2000, sub { checkNetwork(); 1 }); $timeout = Glib::Timeout->add($config{UPDATE_FREQUENCY}*1000, sub { checkUpdates(); 1; }); } sub getTime() { my $d = localtime(); $d =~ s/\s+/_/g; $d; } sub setLastTime() { my $date = getTime(); setVar('LASTCHECK', $date); } sub checkNetwork() { return if $checker_pid; require network::tools; if (!network::tools::has_network_connection()) { # do not notify if already done: return if member($state_global, qw(disconnected)); log::explanations(N_("Checking Network: seems disabled\n")); go2State('disconnected'); } elsif (member($state_global, qw(disconnected))) { silentCheck(); #- state has changed, update } } sub checkUpdates() { member($state_global, qw(disconnected)) or silentCheck(); } sub go2State { my $state = shift; $menu->destroy if $menu; $menu = setState($state); $state_global = $state; gtkflush(); } sub shouldStart() { to_bool($local_config{AUTOSTART} ne 'FALSE'); } sub setState { my ($state) = @_; my $checkme; state $previous_state; my @arr = @{$state{$state}{menu}}; my $tmp = eval { gtkcreate_pixbuf($state{$state}{colour}[0]) }; $icon->set_from_pixbuf($tmp) if $tmp; $icon->set_tooltip(formatAlaTeX(translate($state{$state}{tt}[0]))); my @invisible_states = qw(delayed okay disconnected locked); $icon->set_visible(!member($state, @invisible_states)); # do not show icon while checking if previously hidden: $icon->set_visible(0) if $state eq 'busy' && member($previous_state, @invisible_states); $previous_state = $state; gtkflush(); # so that bubbles are displayed on right icon if ($state{$state}{tt}[0] && $icon->isa('Gtk2::StatusIcon') && !$state{$state}{do_not_use_bubble}) { my $bubble = Gtk2::Notify->new_with_status_icon(N("Warning"), formatAlaTeX(translate($state{$state}{tt}[0])) . "\n", '/usr/share/icons/mdkonline.png', $icon); if ($state eq 'new_distribution') { $bubble->add_action('clicked', N("Upgrade the system"), \&upgrade); if ($sub_state eq 'updates') { push @arr, 'update'; } } elsif ($state eq 'updates') { unshift @arr, 'upgrade_distro' if $new_distro; $bubble->add_action('clicked', N("Install updates"), \&installUpdates); } elsif (member($state, qw(no_enabled_medium no_update_medium))) { $bubble->add_action('clicked', N("Add media"), \&add_media); } $bubble->set_timeout(5000); eval { $bubble->show }; } my $menu = Gtk2::Menu->new; foreach (@arr) { $menu->append(gtksignal_connect(gtkshow(Gtk2::MenuItem->new_with_label($actions{$_}{name})), activate => $actions{$_}{launch})); } $menu->append(gtkshow(Gtk2::SeparatorMenuItem->new)); $menu->append(gtksignal_connect(gtkshow(Gtk2::MenuItem->new_with_label(N("About..."))), activate => sub { my $ver = 1; # automatically set from spec file my $url = $online_site; $url =~ s/^https:/http:/; my $w = gtknew('AboutDialog', name => N("Mandriva Online %s", $ver), copyright => N("Copyright (C) %s by Mandriva", '2001-2008'), license => join('', cat_('/usr/share/common-licenses/GPL')), icon => '/usr/share/icons/mini/mdkonline.png', comments => N("Mandriva Online gives access to Mandriva web services."), website => $url, website_label => N("Online WebSite"), authors => 'Thierry Vignaud <vignaud@mandriva.com>', artists => 'Hélène Durosini', translator_credits => #-PO: put here name(s) and email(s) of translator(s) (eg: "John Smith <jsmith@nowhere.com>") N("_: Translator(s) name(s) & email(s)\n"), transient_for => $::main_window, modal => 1, position_policy => 'center-on-parent', ); $w->show_all; $w->run; return 1; })); $menu->append(gtksignal_connect(gtkset_active($checkme = Gtk2::CheckMenuItem->new_with_label(N("Always launch on startup")), shouldStart()), toggled => sub { setAutoStart(uc(bool2text($checkme->get_active))) })); $checkme->show; $menu->append(gtksignal_connect(gtkshow(Gtk2::MenuItem->new_with_label(N("Quit"))), activate => sub { mainQuit() })); $menu; } sub setVar { my ($var, $st) = @_; my %s = getVarsFromSh($localfile); $s{$var} = $st; setVarsInSh($localfile, \%s); } sub setAutoStart { my $state = shift; my $date = getTime(); if (-f $localfile) { setVar('AUTOSTART', $state); } else { output_p($localfile, qq(AUTOSTART=$state LASTCHECK=$date )); } } sub mainQuit() { # setAutoStart('FALSE'); Glib::Source->remove($timeout) if $timeout; Glib::Source->remove($network_timeout) if $network_timeout; Gtk2->main_quit; }