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
|
#!/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 my_gtk qw(:helpers :wrappers);
$::isStandalone = 1;
@ARGV or die "usage: ", basename($0), " <[-noupgrade] PACKAGE>...\n";
sub translate {
my ($s) = @_;
$s ? c::dgettext('grpmi', $s) : '';
}
sub _ {
my $s = shift @_; my $t = translate($s);
sprintf $t, @_;
}
sub mexit { my_gtk::exit(undef, @_) }
sub interactive_msg {
my ($title, $contents, $yesno) = @_;
my $d = my_gtk->new($title);
my $lines; $lines++ while $contents =~ /\n/g;
my $l = new Gtk::Label($contents);
gtkadd($d->{window},
gtkpack_(new Gtk::VBox(0,5),
1, $lines > 20 ? gtkset_usize(createScrolledWindow($l), 300, 300) : $l,
0, gtkpack(create_hbox(),
$yesno ? (gtksignal_connect(new Gtk::Button(_("Yes")), clicked => sub { $d->{retval} = 1; Gtk->main_quit }),
gtksignal_connect(new Gtk::Button(_("No")), clicked => sub { $d->{retval} = 0; Gtk->main_quit }))
: gtksignal_connect(new Gtk::Button(_("Ok")), clicked => sub { Gtk->main_quit })
)));
$l->set_justify('left');
$d->main;
return $d->{retval};
}
Gtk->init;
$> 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 = my_gtk->new('grpmi');
my $label = new Gtk::Label(_("Initializing..."));
my $progressbar = gtkset_usize(new Gtk::ProgressBar, 400, 0);
gtkadd($mainw->{window}, gtkpack(gtkadd(create_vbox(), $label, $progressbar)));
$mainw->{rwindow}->set_position('center');
$mainw->sync;
my $exitstatus = -1;
# -=-=-=---=-=-=---=-=-=-- 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;
for (my $i=0; $i<@ARGV; $i++) {
if ($ARGV[$i] =~ m,$url_regexp,) {
$download_progress++;
$label->set(_("Downloading package `%s' (%s/%s)...", basename($ARGV[$i]), $download_progress, $nb_downloads));
select(undef, undef, undef, 0.1); $mainw->flush; #- hackish :-(
my $res = curl_download::download($ARGV[$i], $cache_location, sub { $_[0] and $progressbar->update($_[1]/$_[0]); $mainw->flush });
my $url = $ARGV[$i];
$ARGV[$i] = "$cache_location/" . basename($ARGV[$i]);
if ($res) {
interactive_msg(_("Error during download"),
_("There was an error downloading package:
%s
Error: %s
Do you want to continue (skipping this package)?", $url, $res), 1) or goto cleanup;
$ARGV[$i] = "-skipped&$ARGV[$i]&";
}
}
if ($ARGV[$i] !~ /^-/) {
if (-f $ARGV[$i]) {
$label->set(_("Verifying signature of `%s'...", basename($ARGV[$i]))); $mainw->flush;
my $res = grpmi_rpm::verify_sig("$ARGV[$i]");
$res and (interactive_msg(_("Signature verification error"),
_("The signature of the package `%s' is not correct:
%s
Do you want to install it anyway?",
basename($ARGV[$i]), $res), 1) or $ARGV[$i] = "-skipped&$ARGV[$i]&");
} else {
interactive_msg(_("File error"),
_("The following file is not valid:
%s
Do you want to continue anyway (skipping this package)?",
$ARGV[$i]), 1) or goto cleanup;
$ARGV[$i] = "-skipped&$ARGV[$i]&";
}
}
}
# -=-=-=---=-=-=---=-=-=-- 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
Do you want to force the install anyway?",
join("\n", split(/\|/, $1))), 1) ? 0 : 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->update($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;
$mainw->{rwindow}->hide;
cleanup:
if (!member('noclearcache', @grpmi_config)) {
foreach (@ARGV) {
s/^-skipped&([^&]+)&$/$1/;
/^\Q$cache_location/ and unlink;
}
}
mexit $exitstatus;
|