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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
|
#!/usr/bin/perl
#*****************************************************************************
#
# Copyright (c) 2002 Guillaume Cottenceau (gc at mandrakesoft 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 MDK::Common;
use curl_download;
use grpmi_rpm;
use lib qw(/usr/lib/libDrakX);
use ugtk2 qw(:all);
$::isStandalone = 1;
@ARGV or die "usage: ", basename($0), " [--no-verify-rpm] <[-noupgrade] PACKAGE>...\n";
c::bind_textdomain_codeset('grpmi', 'UTF8');
sub translate {
my ($s) = @_;
my $r = $s ? c::dgettext('grpmi', $s) : '';
c::set_tagged_utf8($r);
$r;
}
sub sprintf_fixutf8 {
my $need_upgrade;
$need_upgrade |= to_bool(c::is_tagged_utf8($_)) + 1 foreach @_;
if ($need_upgrade == 3) { c::upgrade_utf8($_) foreach @_ };
sprintf shift, @_;
}
sub _ {
my $s = shift @_; my $t = translate($s);
sprintf_fixutf8 $t, @_;
}
sub mexit { ugtk2::exit(undef, @_) }
sub interactive_msg {
my ($title, $contents, $yesno) = @_;
my $d = ugtk2->new($title);
my $lines; $lines++ while $contents =~ /\n/g;
my $l = Gtk2::Label->new($contents);
gtkadd($d->{window},
gtkpack_(Gtk2::VBox->new(0,5),
1, $lines > 20 ? gtkset_size_request(create_scrolled_window($l), 300, 300) : $l,
0, gtkpack(create_hbox(),
ref($yesno) eq 'ARRAY' ? map {
my $label = $_;
gtksignal_connect(Gtk2::Button->new($label), clicked => sub { $d->{retval} = $label; Gtk2->main_quit })
} @$yesno
: $yesno ? (gtksignal_connect(Gtk2::Button->new(_("Yes")), clicked => sub { $d->{retval} = 1; Gtk2->main_quit }),
gtksignal_connect(Gtk2::Button->new(_("No")), clicked => sub { $d->{retval} = 0; Gtk2->main_quit }))
: gtksignal_connect(Gtk2::Button->new(_("Ok")), clicked => sub { Gtk2->main_quit })
)));
$l->set_justify('left');
$d->main;
return $d->{retval};
}
$> and interactive_msg(_("Error..."),
_("You need to be root to install packages, sorry.")), mexit -1;
grpmi_rpm::init_rcstuff() and interactive_msg(_("RPM initialization error"),
_("The initialization of config files of RPM was not possible, sorry.")), mexit -1;
$ENV{HOME} ||= '/root';
my @grpmi_config = map { chomp_($_) } cat_("$ENV{HOME}/.grpmi");
my $mainw = ugtk2->new('grpmi');
my $label = Gtk2::Label->new(_("Initializing..."));
my $progressbar = gtkset_size_request(Gtk2::ProgressBar->new, 400, 0);
gtkadd($mainw->{window}, gtkpack(gtkadd(create_vbox(), $label, $progressbar)));
$mainw->{rwindow}->set_position('center');
$mainw->sync;
my $exitstatus = -1;
my $forced_exitstatus;
# -=-=-=---=-=-=---=-=-=-- download potential URL's, and verify signatures -=-=-=---=-=-=--
my $cache_location = '/var/cache/urpmi/rpms';
my $url_regexp = '^http://|^https://|^ftp://';
my $nb_downloads = int(grep { m,$url_regexp, } @ARGV);
my $download_progress;
foreach my $arg (@ARGV) {
if ($arg =~ m,$url_regexp,) {
$download_progress++;
my $url = $arg;
$arg = "$cache_location/" . basename($url);
retry_download:
$label->set(_("Downloading package `%s' (%s/%s)...", basename($url), $download_progress, $nb_downloads));
select(undef, undef, undef, 0.1); $mainw->flush; #- hackish :-(
my $res = curl_download::download($url, $cache_location,
sub { $_[0] and $progressbar->set_fraction($_[1]/$_[0]); $mainw->flush });
if ($res) {
my $results = interactive_msg(_("Error during download"),
_("There was an error downloading package:
%s
Error: %s
Do you want to continue (skipping this package)?", $url, $res),
[ _("Yes"), _("No"), _("Retry download") ]);
$results eq _("No") and goto cleanup;
$results eq _("Retry download") and goto retry_download;
$arg = "-skipped&$arg&";
}
}
}
# -=-=-=---=-=-=---=-=-=-- verify signatures -=-=-=---=-=-=--
if (!member('--no-verify-rpm', @ARGV)) {
my $yes_to_all;
foreach my $arg (@ARGV) {
if ($arg !~ /^-/) {
if (-f $arg) {
$yes_to_all and next;
$label->set(_("Verifying signature of `%s'...", basename($arg))); $mainw->flush;
if (my $res = grpmi_rpm::verify_sig($arg)) {
my $results = interactive_msg(_("Signature verification error"),
_("The signature of the package `%s' is not correct:
%s
Do you want to install it anyway?",
basename($arg), $res),
[ _("Yes"), _("Yes to all"), _("No") ]);
$results eq _("No") and $arg = "-skipped&$arg&";
$results eq _("Yes to all") and $yes_to_all = 1;
}
} else {
interactive_msg(_("File error"),
_("The following file is not valid:
%s
Do you want to continue anyway (skipping this package)?",
$arg), 1) or goto cleanup;
$arg = "-skipped&$arg&";
}
}
}
}
# -=-=-=---=-=-=---=-=-=-- install packages -=-=-=---=-=-=---=-=-=-
if (grep { /^[^-]/ } @ARGV) {
$label->set(_("Preparing packages for installation...")); $mainw->flush;
my $nb_installs = int(grep { /^[^-]/ } @ARGV);
my $install_progress;
sub install_packages_callback {
my ($msg) = @_;
my $retval;
my %actions = ( 'conflicts' => sub {
interactive_msg(_("Conflicts detected"),
_("Conflicts were detected:
%s
Install aborted.",
join("\n", split(/\|/, $1))));
$forced_exitstatus = -1;
return 1;
},
'inst-start' => sub { $install_progress++;
$label->set(_("Installing package `%s' (%s/%s)...", $1, $install_progress, $nb_installs));
$mainw->flush },
'inst-progress' => sub {
$1 =~ /(\d+) (\d+)/;
$progressbar->set_fraction($1/$2); $mainw->flush
},
);
$msg =~ /^$_ (.*)/ and return &{$actions{$_}} foreach keys %actions;
print STDERR "unknown msg:<$msg>\n";
return 0;
}
my $res = chomp_(grpmi_rpm::install_packages(\&install_packages_callback, @ARGV));
if ($res) {
interactive_msg(_("Problems occurred during installation"), _("There was an error during packages installation:\n\n%s", $res));
goto cleanup;
}
}
# -=-=-=---=-=-=---=-=-=-- cleanup -=-=-=---=-=-=--
$exitstatus = 0;
cleanup:
if (!member('noclearcache', @grpmi_config)) {
my @toclean = map { s/^-skipped&([^&]+)&$/$1/; if_(/^\Q$cache_location/, $_) } @ARGV;
if ($forced_exitstatus || $exitstatus) {
interactive_msg(_("Cleanup"),
_("Cleanup question: there was an error during installation, do you want to
remove the %d downloaded package(s)?
(they are located in %s)", scalar(@toclean), $cache_location), 1) or goto exiting;
}
unlink @toclean;
}
exiting:
mexit($forced_exitstatus || $exitstatus);
|