/
Wagon.ycp
1067 lines (877 loc) · 34.4 KB
/
Wagon.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
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* File: modules/Wagon.ycp
* Package: WAGON
* Summary: Functions and handlers for WAGON
* Authors: Lukas Ocilka <locilka@suse.cz>
* Internal
*
* $Id$
*
* Module for handling WAGON.
*
*/
{
module "Wagon";
textdomain "wagon";
import "Installation";
import "PackageCallbacks";
import "CommandLine";
import "Mode";
import "Stage";
import "Directory";
import "XML";
import "ProductControl";
import "Popup";
import "Label";
import "Report";
import "ProductFeatures";
import "Update";
import "FileUtils";
import "String";
import "Packages";
import "PackageInstallation";
import "RegistrationStatus";
include "wagon/wagon_helpers.ycp";
boolean running_by_applet = false;
string update_workflow_type = "manual";
// Products installed for the time of the migration
global list <string> migration_products = [];
// Products installed before the migration
global list <map <string, string> > products_before_migration = [];
// Repositories that were disabled by wagon during migration
// List of aliases (unique identification)
// BNC #573092
global list <string> disabled_repositories = [];
global list <string> repositories_to_disable = [];
// When aborting before the real migration starts, we can still
// revert to the old products
global boolean abort_can_revert_products = true;
// Registration can be skipped, this variable tells whether some repos were already
// added by registration
global boolean repos_already_registered = false;
// Script suse_register changes the repositories automatically.
// Additionally, Wagon also disables some repositories. This option provides
// the possibility to check what was changed and how and/or add/remove some more.
// BNC #579905
global boolean check_repositories_manually = false;
string check_repos_module = "wagon_check_repositories";
const string hook_dir = "/var/lib/YaST2/wagon/hooks/";
global void SetUpdateWorkflow (string new_update_workflow_type) {
// FIXME: check
y2milestone ("New workflow type: %1", new_update_workflow_type);
update_workflow_type = new_update_workflow_type;
}
global string GetUpdateWorkflow () {
return update_workflow_type;
}
const string download_mode_link = "wagon-download_in_advance";
global define string GetDownloadModeLink()
{
return download_mode_link;
}
string migration_method = nil;
global string migration_method_file = sformat ("%1/wagon_migration_method", Directory::vardir);
global boolean SetMigrationMethod (string m_method) {
y2milestone ("Setting migration method: %1", m_method);
if (m_method == "suse_register" || m_method == "custom") {
migration_method = m_method;
} else {
y2error ("Unknown migration method: %1", m_method);
Report::Error (sformat(_("Error switching migration method.
Unknown migration method: %1"), m_method));
return false;
}
return true;
}
global string GetMigrationMethod () {
return migration_method;
}
// do the distribution upgrade from selected repositories
list<integer> dup_repos = [];
global list<integer> DupRepos()
{
return dup_repos;
}
global void SetDupRepos(list<integer> repos)
{
dup_repos = repos;
}
boolean manual_repo_selection = false;
// manual or automatic DUP repo selection?
global boolean ManualRepoSelection()
{
return manual_repo_selection;
}
global void SetManualRepoSelection(boolean manual)
{
y2milestone("Manual DUP repo selection: %1", manual);
manual_repo_selection = manual;
}
// list of repositories (aliases) added by suse_register
list<string> new_registration_repos = [];
// returns list of repositories (aliases) added by suse_register
global list<string> RegistrationRepos()
{
return new_registration_repos;
}
// set list of repositories (aliases) added by suse_register
global void SetRegistrationRepos(list<string> repos)
{
y2milestone("Repositories added by registration: %1", new_registration_repos);
new_registration_repos = repos;
}
// migration type, one of `minimal, `full, `custom
symbol migration_type = `minimal;
// get the current migration type
global symbol MigrationType()
{
return migration_type;
}
// set the migration type
// @param type Type of migration (`minimal, `full, `custom)
// @return boolean true on success
global boolean SetMigrationType(symbol type)
{
if (contains([`minimal, `full, `custom], type))
{
migration_type = type;
y2milestone("Setting migration type: %1", type);
return true;
}
else
{
y2error("Invalid migration type: %1", type);
y2warning("Keeping the current type: %1", migration_type);
return false;
}
}
void ResetWorkflowSteps () {
ProductControl::UnDisableAllModulesAndProposals (Mode::mode(), Stage::stage());
}
/**
* Replaces the current workflow steps with a new one.
*/
global boolean SetWizardSteps () {
// Adjusting the steps this way:
// * Disable all steps
// * Enable only the requierd ones
ResetWorkflowSteps();
ProductControl::DisableAllModulesAndProposals (Mode::mode(), Stage::stage());
list <map <string, any> > subworkflows =
(list <map <string, any> >) ProductFeatures::GetFeature ("globals", "subworkflows");
boolean found = false;
foreach (map <string, any> one_subworkflow, subworkflows, {
if (one_subworkflow["name"]:"" == update_workflow_type) {
list <string> modules = (list <string>) one_subworkflow["modules"]:[];
y2milestone ("Modules to enable: %1", modules);
if (modules != nil && modules != []) {
foreach (string one_module, modules, {
ProductControl::EnableModule (one_module);
});
}
list <string> proposals = (list <string>) one_subworkflow["proposals"]:[];
y2milestone ("Proposals to enable: %1", proposals);
if (proposals != nil && proposals != []) {
foreach (string one_proposal, proposals, {
ProductControl::EnableProposal (one_proposal);
});
}
found = true;
break;
}
});
if (found != true) {
y2error ("Unknown workflow: %1", update_workflow_type);
y2milestone ("Known workflows: %1", subworkflows);
// TRANSLATORS: error message
Report::Error (_("No workflow defined."));
return false;
}
return true;
}
/**
* Handles the optional workflow steps according to the current settigns.
*/
global void AdjustVariableSteps () {
y2milestone ("Adjusting variable steps to '%1' migration method", migration_method);
// BNC #587506: enable/disable steps according to selected method
//
// User will not have to enter migration repositories manually
// registration takes care about it
if (migration_method == "suse_register") {
ProductControl::DisableModule ("wagon_manual_url_repositories");
ProductControl::EnableModule ("suse_register_workflow");
// BNC #579905: Check modified repositories manually.
if (check_repositories_manually != false) {
y2milestone ("Enabling module %1", check_repos_module);
ProductControl::EnableModule (check_repos_module);
} else {
y2milestone ("Disabling module %1", check_repos_module);
ProductControl::DisableModule (check_repos_module);
}
// User has chosen to enter all migration repositories manually
} else if (migration_method == "custom") {
ProductControl::DisableModule ("wagon_check_repositories");
ProductControl::DisableModule ("suse_register_workflow");
ProductControl::EnableModule ("wagon_manual_url_repositories");
}
}
/**
* Redraws the wizard steps according to current workflow settings.
*/
global void RedrawWizardSteps () {
list<map> stage_mode = [
$[
"stage" : Stage::stage(),
"mode" : Mode::mode()
]
];
y2milestone ("Updating wizard steps: %1, Disabled modules: %2, Disabled proposals: %3",
stage_mode, ProductControl::GetDisabledModules(), ProductControl::GetDisabledProposals());
ProductControl::UpdateWizardSteps (stage_mode);
}
/**
* Sets wizard steps and redraws the UI.
*/
global boolean AdjustWizardSteps () {
if (SetWizardSteps() != true) {
return false;
}
RedrawWizardSteps();
return true;
}
/**
* Initializes internal variables used later
*
* @param map <string, any> commands as got from CommandLine::Parse()
* @see CommandLine module
*/
global void Init (map <string, any> commands) {
if (haskey (commands, "command")) {
if (commands["command"]:"" == "cd_update") {
// Backward compatibility
commands["command"] = "PatchCD";
}
y2milestone ("Starting workflow defined: %1", commands["command"]:"");
SetUpdateWorkflow (commands["command"]:"");
} else {
string default_subworkflow = ProductFeatures::GetStringFeature ("globals", "default_subworkflow");
if (default_subworkflow == nil || default_subworkflow == "") default_subworkflow = "manual";
y2milestone ("Using default workflow: %1", default_subworkflow);
}
AdjustWizardSteps();
}
/**
* Initializes the package manager
*/
global boolean InitPkg () {
if (Pkg::TargetInitialize (Installation::destdir) != true) {
y2error ("Cannot initialize target");
return false;
}
if (Pkg::TargetLoad() != true) {
y2error ("Cannot load target");
return false;
}
if (Pkg::SourceStartManager (true) != true) {
y2error ("Cannot initialize sources");
return false;
}
// FIXME: what's missing here?
return true;
}
/**
* Processes the command-line parameters and prints
* an appropriate command-line output.
*
* @param map <string, any> commands as got from CommandLine::Parse()
* @see CommandLine module
*/
global void ProcessCommandLine (map <string, any> commands) {
Mode::SetUI ("commandline");
if (commands["command"]:"" == "help" || commands["command"]:"" == "longhelp") {
CommandLine::Print(_("
This module does not support command-line interface.
To do so, please, use zypper instead.
"));
} else if (commands["command"]:"" == "xmlhelp") {
if (! haskey (commands["options"]:$[], "xmlfile")) {
CommandLine::Print(_("Target file name ('xmlfile' option) is missing. Use xmlfile=<target_XML_file> command line option."));
} else {
map doc = $[];
doc["listEntries"] = $[
"commands": "command",
"options": "option",
"examples": "example",
];
doc["systemID"] = Directory::schemadir + "/commandline.dtd";
doc["typeNamespace"] = "http://www.suse.com/1.0/configns";
doc["rootElement"] = "commandline";
XML::xmlCreateDoc(`xmlhelp, doc);
map exportmap = $[
"module" : "wagon",
];
XML::YCPToXMLFile(`xmlhelp, exportmap, commands["options", "xmlfile"]:"");
y2milestone("exported XML map: %1", exportmap);
}
}
}
/**
* Goes through all selected packages one by one a check licenses to confirm.
* These licenses are requested to be accepted by user. If user declines any
* of them, a respective package is set to 'Taboo' and new solver run is
* required.
*
* @return boolean whether all licenses have been accepted
*/
global boolean AcceptLicenses () {
boolean accepted = true;
foreach (string p, Pkg::GetPackages (`selected, true), {
string license = Pkg::PkgGetLicenseToConfirm (p);
if (license != nil && license != "") {
if (license != nil && license != "") {
string rt_license = sformat ("<p><b>%1</b></p>\n%2", p, license);
if (! Popup::AnyQuestionRichText (
// popup heading, with rich text widget and Yes/No buttons
_("Do you accept this license agreement?"),
rt_license,
70, 20,
Label::YesButton (), Label::NoButton (),
`focus_none
)) {
y2milestone("License not accepted: %1", p);
Pkg::PkgTaboo (p);
accepted = false;
} else {
Pkg::PkgMarkLicenseConfirmed (p);
}
}
}
});
return accepted;
}
map <string, any> GetUpdateConf () {
map <string, boolean> ret = $[];
boolean sdp = Update::SilentlyDowngradePackages();
if (sdp != nil) {
ret["silent_downgrades"] = sdp;
}
y2milestone ("Using update configuration: %1", ret);
return ret;
}
boolean already_proposed = false;
global void ResetDUPProposal () {
already_proposed = false;
}
global boolean ProposeDUP () {
if (already_proposed == true) {
y2milestone ("DUP already proposed");
return true;
}
// reset upgrade repo config
y2milestone("Resetting upgrade repos config");
list<integer> repos = Pkg::GetUpgradeRepos();
foreach(integer repo, repos, {Pkg::RemoveUpgradeRepo(repo);});
// reset solver flags
Pkg::SetSolverFlags($["reset" : true]);
// add upgrade repositories
y2milestone("Adding upgrade repos: %1", dup_repos);
foreach(integer repo, dup_repos, {Pkg::AddUpgradeRepo(repo);});
// be compatible with "zypper dup --from"
Pkg::SetSolverFlags($["ignoreAlreadyRecommended" : true]);
// ensure the migration products are removed
foreach(string migration_product, migration_products,
{
y2milestone("Removing migration product: %1", migration_product);
Pkg::ResolvableRemove(migration_product, `product);
}
);
if (MigrationType() == `full)
{
// run the solver to evaluate applicable patches
Pkg::PkgSolve(false);
// preselect all applicable patches (except optional ones)
integer patches = Pkg::ResolvablePreselectPatches(`all);
y2milestone("Preselected patches: %1", patches);
}
// set the solve error flag for packages proposal
Update::solve_errors = Pkg::PkgSolve(true) ? 0 : Pkg::PkgSolveErrors();
if (!AcceptLicenses())
{
// rerun the solver after rejecting a package license
// (setting the package to taboo state)
Update::solve_errors = Pkg::PkgSolve(true) ? 0 : Pkg::PkgSolveErrors();
}
Pkg::CreateSolverTestCase("/var/log/YaST2/wagon_test_case");
already_proposed = true;
return true;
}
map<string, any> CheckDownloadSpace()
{
// display a warning if estimated free size after migration is below 100MB
integer min_free_space = 100 << 20;
map<string, list> du = Pkg::TargetGetDU();
list<string> mounts = maplist(string dir, list info, du, {return dir;});
map<string,any> zconfig = Pkg::ZConfig();
string pkg_path = zconfig["repo_packages_path"]:"";
string packages_mount = String::FindMountPoint(pkg_path, mounts);
y2milestone("Packages will we downloaded to %1 (mountpoint %2)", pkg_path, packages_mount);
// download size in bytes
integer download_size = Packages::CountSizeToBeDownloaded();
y2milestone("Size of packages to download: %1MB", download_size >> 20);
// du contains maps: $[ "dir" : [ total, used, pkgusage, readonly ], .... ]
integer after_install = du[packages_mount, 2]:0;
integer total = du[packages_mount, 0]:0;
y2milestone("Size after installation: %1MB (of %2MB)", after_install >> 20, total >> 20);
symbol result = `ok;
string message = "";
if (after_install + download_size < total)
{
result = `error;
message = sformat(_("There is not enough free space to migrate the system using download in advance mode. Partition %1 needs at least %2MB more free disk space. (The needed size is estimated, it is recommended to add slightly more free space.) Add more disk space or disable download in advance mode."),
packages_mount, (after_install + download_size - total) >> 20);
y2error("Not enough free space for download in advance upgrade: "
+ "estimated size after installation: %1MB, download size: %2MB, "
+ "total size: %3MB, estimated free space: %4MB", after_install >> 20,
download_size >> 20, total >> 20, (total - after_install - download_size) >> 20);
}
else if (after_install + download_size + min_free_space < total)
{
result = `warning;
message = sformat(_("There might not be enough free space for download in advance mode migration. The estimated free space after migration is %2MB, it is recommended to increase the free space in case the estimation is inaccurate to avoid installation errors."),
(total - after_install - download_size) >> 20);
y2warning("Low free space: estimated size after installation: %1MB, "
+ "download size: %2MB, total size: %3MB, estimated free space: %4MB",
after_install >> 20, download_size >> 20, total >> 20, (total - after_install - download_size) >> 20);
}
return $[ "result" : result, "message" : message ];
}
global void ProposeDownloadMode()
{
if (PackageInstallation::DownloadInAdvance() == nil)
{
map<string, any> dwspace = CheckDownloadSpace();
PackageInstallation::SetDownloadInAdvance(dwspace["result"]:nil == `ok);
y2milestone("Proposed download in advance mode: %1", PackageInstallation::DownloadInAdvance());
}
}
global map <string,any> MinimizeProductMap (map <string,any> product) {
if (haskey (product, "license")) product["license"] = "...";
if (haskey (product, "description")) product["description"] = "...";
return product;
}
string GetDisplayName (string display_name, string name) {
if (display_name == name)
return display_name;
// 'Product Long Name (product-libzypp-name)'
return sformat (_("%1 (%2)"), display_name, name);
}
global map <string, any> ProposalSummary () {
string ret = "";
string warning = "";
list <map <string,any> > products = sort (
map <string,any> x, map <string,any> y, Pkg::ResolvableProperties ("", `product, ""),
``(x["display_name"]:x["short_name"]:x["name"]:"a" < y["display_name"]:x["short_name"]:x["name"]:"b")
);
// migration_products contains list of temporary products for migration process
y2milestone ("All known migration products: %1", migration_products);
string display_name = nil;
string name = nil;
symbol transact_by = nil;
// list of all products that will be installed (are selected)
list <string> products_to_be_installed = [];
foreach (map <string,any> product, products, {
if (product["status"]:`unknown != `selected) return;
name = product["name"]:_("No short name defined");
products_to_be_installed = add (products_to_be_installed, name);
});
// list of all products that will be upgraded
list <string> products_to_be_upgraded = [];
integer products_removed_by_solver = 0;
// Products that are going to be removed
foreach (map <string,any> product, products, {
if (product["status"]:`unknown != `removed) return;
product = MinimizeProductMap (product);
display_name = product["display_name"]:product["short_name"]:product["name"]:_("No name defined");
name = product["name"]:_("No short name defined");
transact_by = product["transact_by"]:`unknown;
// Removing product and installing the same one (name) means -> upgrade
// Hack: SLES-for-VMware migration changes the product from "SUSE_SLES" to "SLES-for-VMware", check this upgrade
if (contains(products_to_be_installed, name) ||
( name == "SUSE_SLES" && contains(products_to_be_installed, "SLES-for-VMware") && contains(migration_products, "SLES-for-VMware-SP2-migration"))) {
products_to_be_upgraded = add (products_to_be_upgraded, name);
y2milestone ("Product to be upgraded: %1 (this is the removed one)", product);
// Do not list this product as 'to removed', list it as 'to upgrade'
return;
}
// Removing a migration product is fine
if (contains (migration_products, product["name"]:"")) {
y2milestone ("Migration product will be removed: %1", product);
ret = ret + "<li>" + sformat (
_("Temporary migration product <b>%1</b> will be removed"),
GetDisplayName (display_name, name)
) + "</li>\n";
// Removing another product might be an issue
// (nevertheless selected by user or directly by YaST)
} else if (transact_by == `user || transact_by == `app_high) {
y2warning ("Product will be removed: %1 (%2)", product, transact_by);
ret = ret + "<li>" + sformat (
_("<font color='red'><b>Warning:</b> Product <b>%1</b> will be removed</font>"),
GetDisplayName (display_name, name)
) + "</li>\n";
// Not selected by user
// @see BNC #575117
} else {
y2warning ("Product will be removed: %1 (%2)", product, transact_by);
ret = ret + "<li>" + sformat (
_("<font color='red'><b>Error:</b> Product <b>%1</b> will be automatically removed</font>"),
GetDisplayName (display_name, name)
) + "</li>\n";
products_removed_by_solver = products_removed_by_solver + 1;
}
});
// Products that are going to be installed (new ones) or upgraded
foreach (map <string,any> product, products, {
if (product["status"]:`unknown != `selected) return;
product = MinimizeProductMap (product);
display_name = product["display_name"]:product["short_name"]:product["name"]:_("No name defined");
name = product["name"]:_("No short name defined");
// Hack: SLES-for-VMware migration changes the product from "SUSE_SLES" to "SLES-for-VMware", check this upgrade
boolean sles_for_vmware_upgrade = (name == "SLES-for-VMware" && contains(products_to_be_upgraded, "SUSE_SLES") && contains(migration_products, "SLES-for-VMware-SP2-migration"));
// Product is going to be upgraded (removed + installed new version)
if (contains (products_to_be_upgraded, name) || sles_for_vmware_upgrade) {
map <string,any> old_product = find(map<string,any> p, products, {return p["name"]:"" == (sles_for_vmware_upgrade ? "SUSE_SLES" : name) && p["status"]:`unknown == `removed;});
string old_product_name = old_product["name"]:_("No name defined");
string old_display_name = old_product["display_name"]:old_product["short_name"]:old_product["name"]:_("No name defined");
y2milestone ("Detected product upgrade from: '%1' to: '%2'", old_display_name, display_name);
y2milestone ("Product will be upgraded to: %1 (this is the new one)", product);
// FIXME: disabled to not break translations:
// if (old_display_name == display_name)
if (true)
{
ret = ret + "<li>" + sformat (
_("Product <b>%1</b> will be upgraded"),
GetDisplayName(old_display_name, old_product_name)
) + "</li>\n";
}
else
{
ret = ret + "<li>" + sformat (
_("Product <b>%1</b> will be upgraded to <b>%2</b>"),
GetDisplayName(old_display_name, old_product_name), GetDisplayName(display_name, name)
) + "</li>\n";
}
// Newly installed product
} else {
y2milestone ("New product will be installed: %1", product);
ret = ret + "<li>" + sformat (
_("New product <b>%1</b> will be installed"),
GetDisplayName (display_name, name)
) + "</li>\n";
}
});
// Products that will keep installed (unchanged)
foreach (map <string,any> product, products, {
if (product["status"]:`unknown != `installed) return;
product = MinimizeProductMap (product);
display_name = product["display_name"]:product["short_name"]:product["name"]:_("No name defined");
name = product["name"]:_("No short name defined");
y2milestone ("Product will keep: %1", product);
ret = ret + "<li>" + sformat (
_("Product <b>%1</b> will keep installed"),
GetDisplayName (display_name, name)
) + "</li>\n";
});
ret = "<ul>\n" + ret + "</ul>\n";
ret = ret + "<ul><li>\n" + _("Download all packages before upgrade: ") +
sformat("<a href=\"%1\">%2</a>", download_mode_link, (PackageInstallation::DownloadInAdvance() ? _("Enabled") : _("Disabled")))
+ "</li></ul>\n";
map <string, any> summary = $[
"preformatted_proposal" : ret,
"links" : [ download_mode_link ],
// help text, TODO FIXME: replace the inner <p> by <b>
"help" : _("<p>To change the update settings, go to <p>Packages Proposal</p> section.</p>"),
];
// Product removal MUST be confirmed by user, otherwise migration will not continue.
if (products_removed_by_solver > 0) {
summary["warning_level"] = `blocker;
summary["warning"] = "<ul>" + (
products_removed_by_solver > 1 ?
sformat(_("<li><b>%1 products are going to be removed.
Go to packages proposal and solve the issue manually.<br>
It it also safe to abort the migration now.</b></li>"), products_removed_by_solver)
:
_("<li><b>One product is going to be removed.
Go to packages proposal and solve the issue manually.<br>
It it also safe to abort the migration now.</b></li>")
) + "</ul>";
}
return summary;
}
global list <map <string, string> > ReadProductsBeforeMigration () {
list <map <string, any> > products = Pkg::ResolvableProperties ("", `product, "");
y2milestone ("All known products: %1", products);
foreach (map<string, any> p, products, {
if (p["status"]:`unknown != `installed)
return;
// Remember the 'old' product just for the case of reverting
products_before_migration = add (
products_before_migration,
$["name" : p["name"]:"", "version" : p["version"]:""]
);
});
return products_before_migration;
}
// YaST can be restarted but some data have to be kept
string migration_products_store_file = sformat ("%1/wagon_products_before_migration", Directory::vardir);
global boolean StoreProductsBeforeMigration () {
return (boolean) SCR::Write (.target.ycp, migration_products_store_file, products_before_migration);
}
global boolean RestoreProductsBeforeMigration () {
products_before_migration = (list <map <string, string> >) SCR::Read (.target.ycp, migration_products_store_file);
if (products_before_migration == nil) {
products_before_migration = [];
Report::Error (_("Error restoring the list of previously installed products."));
return false;
}
return true;
}
global string GetFileOwner (string file) {
if (file == nil || file == "") {
y2error ("File not provided");
return nil;
}
if (! FileUtils::Exists (file)) {
y2error ("File %1 doesn't exist", file);
return nil;
}
string command = sformat ("rpm -qf '%1'", String::Quote (file)) + " --queryformat \"%{NAME}\"";
map <string, any> cmd = (map <string, any>) SCR::Execute (.target.bash_output, command);
if (cmd["exit"]:-1 != 0) {
y2error ("Cannot get file owner %1: %2", command, cmd);
return nil;
}
return (string) splitstring (cmd["stdout"]:"", "\n")[0]:nil;
}
global void LogAllRepos () {
// We assume all repositories are already loaded
y2milestone ("------ All repositories ------");
foreach (integer one_repo, Pkg::SourceGetCurrent (false /* not only enabled ones */), {
y2milestone ("REPO %1: GeneralData: %2 ProductData: %3",
one_repo,
Pkg::SourceGeneralData (one_repo),
MinimizeProductMap (Pkg::SourceProductData (one_repo))
);
});
y2milestone ("------ All repositories ------");
}
global boolean RunHook (string script_name) {
if (script_name == nil || script_name == "") {
y2error ("Script name '%1' is not supported", script_name);
}
script_name = sformat ("/usr/lib/YaST2/bin/wagon_hook_%1", script_name);
if (! FileUtils::Exists (script_name)) {
y2milestone ("Hook script %1 doesn't exist, nothing to run", script_name);
return false;
}
y2milestone ("Running hook %1", script_name);
map cmd = (map) WFM::Execute (.local.bash_output, String::Quote (script_name));
if (cmd["exit"]:-1 != 0) {
y2error ("Hook script returned: %1", cmd);
Report::Error (sformat(_("Error running hook script %1."), script_name));
return false;
}
y2milestone ("Hook script returned: %1", cmd);
return true;
}
// <seq>_<prefix>_<name>_<stage>_<step>
// sequence number 00 -> 99 (it's important to keep the beginning zeros for correct sorting!)
// prefix - should be unique to avoid conflicts, use package name (if it is part of a package)
// or your vendor name, internet domain name, etc... basicaly anything which can be considered
// enough unique
// name - any name (just to differ the scripts), some descriptive name is recommended
// stage - can be 'before', 'after'
// step is the YCP client name, or 'abort' which is called when aborting migration
// (it can be used for cleaning up after previously called scripts)
//
// the script should return exit value 0, if it fails (non-zero exit value) it displays an error
// 000_my_script_test_after_selfupdate
global boolean RunHooks(string step, string stage) {
y2milestone("Running '%1' hooks for step: %2", stage, step);
// get all hooks
list<string> all_scripts = (list<string>)SCR::Read(.target.dir, hook_dir);
if (all_scripts == nil || all_scripts == [])
{
y2milestone("No hook scripts found");
return true;
}
// get the list of scripts for this step/stage
list<string> scripts = filter(string script, all_scripts, {
return regexpmatch(script, "$");
});
// run the scripts
foreach(string script, scripts, {
y2milestone("Starting hook script: %1", script);
integer ret = (integer)SCR::Execute(.target.bash, script);
if (ret != 0)
{
}
});
return true;
}
/**
* Check whether NCC or SMT is used for registration
*/
define boolean NCCUsed()
{
// check /etc/suseRegister.conf content
string conf = (string)SCR::Read(.target.string, "/etc/suseRegister.conf");
if (conf == nil)
{
y2error("Cannot read /etc/suseRegister.conf");
return nil;
}
list<string> lines = splitstring(conf, "\n");
boolean found_url = false;
boolean found_ncc = false;
foreach(string line, lines, {
if (regexpmatch(line, "^[ \t]*url[ \t]*=[ \t]*"))
{
found_url = true;
y2milestone("Found registration URL option: %1", line);
if (regexpmatch(line, "^[ \t]*url[ \t]*=[ \t]*https://secure-www.novell.com/center/regsvc/*[ \t]*(#*.*)*"))
{
found_ncc = true;
y2milestone("NCC URL found");
}
}
});
if (!found_url)
{
y2error("No url option found in /etc/suseRegister.conf");
return nil;
}
y2milestone("Found NCC registration server: %1", found_ncc);
return found_ncc;
}
/*
* Read registration status and sort products according their status
* @param file Read this registration status file
* @return map<string,any> result: $[
*
"registered_system" : (boolean) - true registration was run, false registration has never run or there is no product to register (e.g. openSUSE installation) or the registration completely failed
"timestamp" : (integer) - time when the status was saved (unix time), -1 in an unregistered system
"registered" : (list<string>) - registered products
"provisional" : (list<string>) - products with provisional subscription (registered, but no updates available)
"rma" : (list<string>) - refunded subscriptions, not active anymore
"expired" : (list<string>) - expired subscriptions
"no_subscription" : (list<string>) - products which do not need a subscription (e.g. SLES-SDK)
"failed" : (list<string>) - registration failed (e.g. invalid registration code)
* ]
*/
global define map<string,any> RegistrationStatusFromFile(string file)
{
boolean registered_system = true;
integer timestamp = -1;
list<string> failed = [];
list<string> no_subscription = [];
list<string> expired = [];
list<string> rma = [];
list<string> provisional = [];
list<string> registered = [];
// 0 = empty file, -1 = missing
if (FileUtils::GetSize(file) <= 0)
{
y2milestone("File %1 does not exist", file);
registered_system = false;
}
else
{
// read the registration status
// see https://wiki.innerweb.novell.com/index.php/Registration#Add_Registration_Status_to_zmdconfig
// for more datils about the file format
map status = RegistrationStatus::ReadFile(file);
timestamp = tointeger(status["generated"]:"-1");
any read_products = status["productstatus"]:nil;
list<map> products = is(read_products, map) ? [ (map)read_products ] : (list<map>)read_products;
// check each product
foreach(map product, products,
{
string product_name = product["product"]:"";
// not registered (error present, but not "expired")
if (product["result"]:"" == "error" && product["errorcode"]:"" != "ERR_SUB_EXP")
{
failed = add(failed, product_name);
}
else
{
// registered, but subscription is not needed (e.g. SLES-SDK)
if (product["subscription"]:$[] == $[])
{
no_subscription = add(no_subscription, product_name);
}
else
{
string status = product["subscription", "status"]:"";
string expiration = product["subscription", "expiration"]:"";