/
PackageSystem.ycp
610 lines (505 loc) · 16.2 KB
/
PackageSystem.ycp
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
/****************************************************************************
Copyright (c) 2002 - 2012 Novell, Inc.
All Rights Reserved.
This program is free software; you can redistribute it and/or
modify it under the terms of version 2 of the GNU General Public License 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, contact Novell, Inc.
To contact Novell about this file by physical or electronic mail,
you may find current contact information at www.novell.com
****************************************************************************/
/**
* File: modules/PackageSystem.ycp
* Package: yast2
* Summary: Packages manipulation (system)
* Authors: Martin Vidner <mvidner@suse.cz>
* Michal Svec <msvec@suse.cz>
* Flags: Stable
*
* $Id$
*
* The documentation is maintained at
* <a href="../index.html">.../docs/index.html</a>.
*/
{
module "PackageSystem";
textdomain "base";
import "Kernel";
import "Mode";
import "PackageCallbacks";
import "PackageLock";
import "Report";
import "Stage";
import "CommandLine";
/**
* Was last operation canceled?
*
* Used to enhance the exit status to distinguish between package
* installation fail and installation canceled by user, as in the second
* case doesn't make much sense to display any error
* Is set to true when user canceled package installation, from
* PackageSystem::* functions
*/
boolean last_op_canceled = false;
/**
* Has Pkg::TargetInit run?
*/
boolean target_initialized = false;
/**
* Has Pkg::SourceStartCache run?
*/
boolean source_initialized = false;
include "packages/common.ycp";
/**
* Ensure that Pkg:: calls work.
* This may become superfluous.
*/
global void EnsureTargetInit() {
// do not initialize the target system in the first installation stage when
// running in instsys, there is no RPM DB in the RAM disk image (bnc#742420)
if (Stage::initial() && !Mode::live_installation())
{
y2milestone("Skipping target initialization in first stage installation");
return;
}
PackageLock::Check ();
// always initizalize target, it should be cheap according to #45356
target_initialized = Pkg::TargetInit ("/", false);
}
/**
* Ensure that Pkg:: calls working with the installation sources work
*/
global void EnsureSourceInit() {
PackageLock::Check ();
if(source_initialized)
{
// this way, if somebody closed the cache outside of Package
// (typically in installation), we will reinitialize
// it's cheap if cache is already initialized
Pkg::SourceStartCache (true);
return;
}
if(! target_initialized)
{
// make sure we have the RPM keys imported
EnsureTargetInit();
}
list sources = Pkg::SourceStartCache (true);
if (size (sources) > 0)
{
source_initialized = true;
}
else
{
// all repositories are disabled or no repository defined
y2warning("No package repository available");
}
}
global boolean DoInstall(list<string> packages) {
return DoInstallAndRemove(packages, []);
}
global boolean DoRemove(list<string> packages) {
return DoInstallAndRemove([], packages);
}
boolean SelectPackages(list<string> toinstall, list<string> toremove)
{
boolean ok = true;
foreach (string p, toinstall, {
if(ok == true)
if(Pkg::PkgInstall(p) != true) {
y2error("Package %1 install failed: %2", p, Pkg::LastError());
ok = false;
}
});
if(ok != true) return false;
foreach (string p, toremove, {
if(ok == true)
if(Pkg::PkgDelete(p) != true) {
y2error("Package %1 delete failed: %2", p, Pkg::LastError());
ok = false;
}
});
return ok;
}
boolean DoInstallAndRemoveInt(list<string> toinstall, list<string> toremove) {
y2debug ("toinstall: %1, toremove: %2", toinstall, toremove);
if (!PackageLock::Check ())
{
return false;
}
EnsureSourceInit ();
EnsureTargetInit ();
boolean ok = true;
import "Label";
import "Popup";
import "PackagesUI";
// licenses: #35250
map<string, string> licenses = Pkg::PkgGetLicensesToConfirm (toinstall);
if (size (licenses) > 0)
{
list<string> rt_licenses_l = maplist ( string p, string l, licenses, {
return Mode::commandline()
? sformat ("%1\n%2", p, l)
: sformat ("<p><b>%1</b></p>\n%2", p, l);
});
boolean accepted = false;
if (Mode::commandline())
{
// print the licenses
CommandLine::Print(mergestring (rt_licenses_l, "\n"));
// print the question
CommandLine::Print(_("Do you accept this license agreement?",
"Do you accept these license agreements?",
size (licenses)));
accepted = !CommandLine::YesNo();
}
else
{
accepted = !Popup::AnyQuestionRichText (
// popup heading, with rich text widget and Yes/No buttons
_("Do you accept this license agreement?",
"Do you accept these license agreements?",
size (licenses)),
mergestring (rt_licenses_l, "\n"),
70, 20,
Label::YesButton (), Label::NoButton (),
`focus_none);
}
y2milestone("Licenses accepted: %1", accepted);
if (!accepted)
{
y2milestone("License not accepted: %1", toinstall);
last_op_canceled = true;
return false;
}
// mark licenses as confirmed
foreach (string p, string l, licenses, {
Pkg::PkgMarkLicenseConfirmed (p);
});
last_op_canceled = false;
}
// check if the database is consistent before packages are added
boolean packages_consistent = Pkg::PkgSolveCheckTargetOnly();
boolean transact = Pkg::IsAnyResolvable(`any, `to_install) || Pkg::IsAnyResolvable(`any, `to_remove);
y2internal("Target solved: %1, something to transact: %2", packages_consistent, transact);
if (!SelectPackages(toinstall, toremove))
{
return false;
}
boolean packager_displayed = false;
// display an error message and advice to manually fix the system
if (!packages_consistent || transact)
{
y2warning("The current system is not consistent");
string message = _("The current system is not consistent,
some packages have unresolved dependencies.");
if (!packages_consistent)
{
message = message + "\n\n" + _("Automatic resolving failed, manual dependency resolving is needed.");
}
if (transact)
{
message = message + "\n\n" + _("Yast has automatically added or removed some packages,
check the changes scheduled to fix the system
in the software manager.");
}
message = message + "\n\n" + _("Start the software manager and fix the problems
or skip fixing and install the already confirmed packages only?");
symbol fixsystem = Popup::AnyQuestion3(Label::WarningMsg(), message, Label::ContinueButton(),
Label::SkipButton(), Label::AbortButton(), `focus_yes);
y2milestone("Fixsystem answer: %1", fixsystem);
// the 3rd button ("Abort" label in this case)
if (fixsystem == `retry)
{
y2milestone("Aborting package installation");
// do not install anything, abort
return false;
}
else if (fixsystem == `yes)
{
// disable repomanagement during installation
boolean repomgmt = !Mode::installation();
// start the package selector
symbol ret = PackagesUI::RunPackageSelector($[ "enable_repo_mgr" : repomgmt, "mode" : `summaryMode ]);
y2internal("Package selector returned: %1", ret);
// do not install anything
if (ret == `cancel || ret == `close)
{
y2milestone("Aborting package installation");
return false;
}
packager_displayed = true;
}
// `no = do not fix the system, install the required packages only
// and ignore the inconsistencies
else if (fixsystem == `no)
{
y2milestone("Resetting the preselected packages");
// reset the solver - disable the fixsystem solver mode (bnc#439373)
Pkg::SetSolverFlags($["reset":true]);
// reset the preselected transactions to fix the problems
Pkg::PkgApplReset();
// reselect the packages again after the reset
if (!SelectPackages(toinstall, toremove))
{
return false;
}
}
else
{
y2internal("Unknown result %1, aborting", fixsystem);
return false;
}
}
boolean solved = Pkg::PkgSolve(false);
if(solved != true)
{
y2error("Package solve failed: %1", Pkg::LastError());
// error message, after pressing [OK] the package manager is displayed
Report::Error(_("There are unresolved dependencies which need
to be solved manually in the software manager."));
// disable repomanagement during installation
boolean repomgmt = !Mode::installation();
// start the package selector
symbol ret = PackagesUI::RunPackageSelector($[ "enable_repo_mgr" : repomgmt, "mode" : `summaryMode ]);
y2internal("Package selector returned: %1", ret);
// do not fix the system
if (ret == `cancel || ret == `close)
{
return false;
}
packager_displayed = true;
}
// is a package or a patch selected for installation?
boolean any_to_install = Pkg::IsAnyResolvable(`package, `to_install) || Pkg::IsAnyResolvable(`patch, `to_install);
//[int successful, list failed, list remaining, list srcremaining]
list result = Pkg::PkgCommit (0);
y2debug ("PkgCommit: %1", result);
if(result == nil || result[1]:[] != []) {
y2error("Package commit failed: %1", result[1]:[]);
return false;
}
foreach (string remaining, (list<string>) (result[2]:[]), {
if(ok == true)
if(contains(toinstall, remaining)) {
y2error("Package remain: %1", remaining);
ok = false;
}
});
if(ok != true) return false;
// Show popup when new kernel was installed
// But omit it during installation, one is run at its end.
// #25071
if (!Stage::initial () && !Stage::cont ())
{
Kernel::InformAboutKernelChange ();
}
// a package or a patch was installed, may be that there is a new yast agent
if (any_to_install)
{
// register the new agents
SCR::RegisterNewAgents();
}
// check if the required packages have been installed
// (user could deselect or uninstall them in the packager widget)
if (packager_displayed && !InstalledAll(toinstall))
{
y2error("Required packages have not been installed");
return false;
}
return true;
}
global boolean DoInstallAndRemove(list<string> toinstall, list<string> toremove)
{
// remember the current solver flags
map<string,any> solver_flags = Pkg::GetSolverFlags();
// do not install recommended packages for already installed packages (bnc#445476)
Pkg::SetSolverFlags($["ignoreAlreadyRecommended":true]);
boolean ret = DoInstallAndRemoveInt(toinstall, toremove);
// restore the original flags
Pkg::SetSolverFlags(solver_flags);
return ret;
}
/**
* Is a package available?
* @return true if yes (nil = no package source available)
*/
global boolean Available(string package) {
EnsureSourceInit();
if (!source_initialized)
{
// error no source initialized
return nil;
}
return Pkg::IsAvailable(package);
}
boolean _rpm_query_binary_initialized = false;
string _rpm_query_binary = "rpm";
void InitRPMQueryBinary () {
if (_rpm_query_binary_initialized) return;
// rpmqpack is a way faster
if (SCR::Read (.target.size, "/usr/bin/rpmqpack") > -1) {
_rpm_query_binary = "/usr/bin/rpmqpack ";
// than rpm itself
} else if (SCR::Read (.target.size, "/bin/rpm") > -1) {
_rpm_query_binary = "/bin/rpm -q ";
}
_rpm_query_binary_initialized = true;
}
/**
* Is a package provided in the system? Is there any installed package providing 'package'?
* @return true if yes
*/
global boolean Installed(string package) {
// This is a most commonly called function and so it's
// important that it's fast, especially in the common
// case, where all dependencies are satisfied.
// Unfortunately, initializing Pkg reads the RPM database...
// so we must avoid it.
// added --whatprovides due to bug #76181
return 0 == (integer) SCR::Execute(.target.bash, "rpm -q --whatprovides " + package);
// return Pkg::IsProvided (package);
}
/**
* Is a package installed? Checks only the package name in contrast to Installed() function.
* @return true if yes
*/
global boolean PackageInstalled(string package) {
InitRPMQueryBinary();
// This is commonly called function and so it's
// important that it's fast, especially in the common
// case, where all dependencies are satisfied.
return 0 == (integer) SCR::Execute (.target.bash, _rpm_query_binary + package);
}
/**
* Is a package available? Checks only package name, not list of provides.
* @return true if yes (nil = no package source available)
*/
global boolean PackageAvailable(string package) {
EnsureSourceInit();
if (!source_initialized)
{
// error no source initialized
return nil;
}
return Pkg::PkgAvailable(package);
}
/**
* @short Check if packages are installed
* @descr Install them if they are not and user approves installation
*
* @param a list of packages to check (and install)
* @return boolean true if installation succeeded or packages were installed,
* false otherwise
*/
global boolean CheckAndInstallPackages (list<string> packages) {
if (Mode::config ())
return true;
if (InstalledAll (packages))
return true;
return InstallAll (packages);
}
/**
* @short Check if packages are installed
*
* @descr Install them if they are not and user approves installation
* If installation fails (or wasn't allowed), ask user if he wants to continue
*
* @param packages a list of packages to check (and install)
* @return boolean true if installation succeeded, packages were installed
* before or user decided to continue, false otherwise
*/
global boolean CheckAndInstallPackagesInteractive (list<string> packages) {
boolean success = CheckAndInstallPackages (packages);
if (! success)
{
if (! LastOperationCanceled ())
{
if (Mode::commandline ())
{
// error report
Report::Error (_("Installing required packages failed."));
}
else
{
success = Popup::ContinueCancel (
// continue/cancel popup
_("Installing required packages failed. If you continue
without installing required packages,
YaST may not work properly.
"));
}
}
else
{
if (Mode::commandline ())
{
Report::Error (
// error report
_("Cannot continue without installing required packages."));
}
else
{
success = Popup::ContinueCancel (
// continue/cancel popup
_("If you continue without installing required
packages, YaST may not work properly.
"));
}
}
}
return success;
}
global boolean InstallKernel (list<string> kernel_modules) {
// this function may be responsible for the horrible startup time
y2milestone ("want: %1", kernel_modules);
if (kernel_modules == [])
{
return true; // nothing to do
}
// check whether tag "kernel" is provided
// do not initialize the package manager if it's not necessary
string rpm_command = "/bin/rpm -q --whatprovides kernel";
y2milestone("Starting RPM query: %1", rpm_command);
map output = (map)SCR::Execute(.target.bash_output, rpm_command);
y2debug("result of the query: %1", output);
if (output["exit"]:-1 == 0)
{
list<string> packages = splitstring(output["stdout"]:"", "\n");
packages = filter(string pkg, packages, {return pkg != "";});
y2milestone("Packages providing tag 'kernel': %1", packages);
if (size(packages) > 0)
{
return true;
}
y2milestone("Huh? Kernel is not installed??");
}
else
{
y2warning("RPM query failed, quering the package manager...");
}
EnsureTargetInit ();
list <list> provides = Pkg::PkgQueryProvides ("kernel");
y2milestone ("provides: %1", provides);
list <list> kernels = filter (list l, provides, {
return l[1]:`NONE == `BOTH || l[1]:`NONE == l[2]:`NONE;
});
if (size (kernels) != 1)
y2error ("not exactly one package provides tag kernel");
string kernel = kernels[0,0]:"none";
list<string> packs = [kernel];
if (! Pkg::IsProvided(kernel))
{
EnsureSourceInit ();
}
// TODO: for 9.2, we always install all packages, but
// we could only install those really needed (#44394)
return InstallAll ( packs );
}
/* EOF */
}