/
AddOnProduct.rb
2293 lines (1996 loc) · 75.7 KB
/
AddOnProduct.rb
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
require "yast"
require "shellwords"
require "packager/product_patterns"
require "y2packager/resolvable"
require "y2packager/repository"
# Yast namespace
module Yast
# This module provides integration of the add-on products
class AddOnProductClass < Module
include Yast::Logger
# @return [Hash] Product renames default map. Used when information is not
# found elsewhere. Also describes the allowed migration paths
# (e.g. openSUSE Leap => SLES).
DEFAULT_PRODUCT_RENAMES = {
"SUSE_SLES" => ["SLES"],
# SLED or Workstation extension
"SUSE_SLED" => ["SLED", "sle-we"],
# SLE11 HA has been renamed since SLE12
"sle-hae" => ["sle-ha"],
# SLE11 HA GEO is now included in SLE15 HA
"sle-haegeo" => ["sle-ha"],
# SLE12 HA GEO is now included in SLE15 HA
"sle-ha-geo" => ["sle-ha"],
"SUSE_SLES_SAP" => ["SLES_SAP"],
# SMT is now integrated into the base SLES
"sle-smt" => ["SLES"],
# Live patching is a module now (bsc#1074154)
"sle-live-patching" => ["sle-module-live-patching"],
# The Advanced Systems Management Module has been moved to the Basesystem module
"sle-module-adv-systems-management" => ["sle-module-basesystem"],
# Toolchain and SDK are now included in the Development Tools SLE15 module
"sle-module-toolchain" => ["sle-module-development-tools"],
"sle-sdk" => ["sle-module-development-tools"],
# openSUSE => SLES migration
"openSUSE" => ["SLES"],
# openSUSE 15.3+ => SLES migration
"Leap" => ["SLES"],
# the IBM tools have been renamed in SLE12->SLE15 upgrade
"ibm-dlpar-utils" => ["ibm-power-tools"]
# NOTE: if you change anything here then check
# https://github.com/yast/yast-packager/blob/master/src/lib/y2packager/product_upgrade.rb#L27
# maybe it needs an update as well...
}.freeze
private_constant :DEFAULT_PRODUCT_RENAMES
attr_accessor :new_renames
def default_product_renames
# special handling for the HPC product
product_mapping = if new_renames
{
# in SLE15-SP6+ SLE_HPC is replaced by SLES + HPC module
"SLE-HPC" => ["SLES"],
"SLE_HPC" => ["SLES"]
}
else
{
# in SLE15 SP5 (or older) the SLES + HPC module is upgraded to SLE_HPC
"SLES" => ["SLE_HPC"],
"SLE-HPC" => ["SLE_HPC"]
}
end
product_mapping.merge!(DEFAULT_PRODUCT_RENAMES)
end
# @return [Hash] Product renames added externally through the #add_rename method
attr_accessor :external_product_renames
private :external_product_renames, :external_product_renames=
# Products which are selected for installation in libzypp.
attr_reader :selected_installation_products
def main
Yast.import "UI"
Yast.import "Pkg"
# IMPORTANT: maintainer of yast2-add-on is responsible for this module
textdomain "packager"
Yast.import "Label"
Yast.import "Mode"
Yast.import "ProductControl"
Yast.import "ProductFeatures"
Yast.import "Report"
Yast.import "XML"
Yast.import "Wizard"
Yast.import "FileUtils"
Yast.import "Popup"
Yast.import "InstShowInfo"
Yast.import "ProductLicense"
Yast.import "Directory"
Yast.import "String"
Yast.import "WorkflowManager"
Yast.import "URL"
Yast.import "Stage"
Yast.import "Icon"
Yast.import "Package"
Yast.import "PackageCallbacks"
Yast.import "PackagesProposal"
Yast.import "SourceManager"
Yast.include self, "packager/load_release_notes.rb"
# variables for installation with product
# ID for cache in the inst-sys
@src_cache_id = -1
# System proposals have already been prepared for merging?
@system_proposals_prepared = false
# System workflows have already been prepared for merging?
@system_workflows_prepared = false
# List of all selected repositories
#
#
# **Structure:**
#
# add_on_products = [
# $[
# "media" : 4, // ID of the source
# "product_dir" : "/",
# "product" : "openSUSE version XX.Y",
# "autoyast_product" : "'PRODUCT' tag for AutoYaST Export",
# ],
# ...
# ]
@add_on_products = []
# ID of currently added repository for the add-on product
@src_id = nil
# for the add-on product workflow - needed for dialog skipping
# return value of last step in the product adding workflow
@last_ret = nil
@modified = false
@mode_config_sources = []
@current_addon = {}
# Bugzilla #239630
# In installation: check for low-memory machines
@low_memory_already_reported = false
# Bugzilla #305554
# Both online-repositories and add-ons use the same function and variable
# if true, both are skipped at once without asking
@skip_add_ons = false
#
# **Structure:**
#
# $["src_id|media|filename" : "/path/to/the/file"]
@source_file_cache = {}
@filecachedir = Builtins.sformat("%1/AddOns_CacheDir/", Directory.tmpdir)
@filecachecounter = -1
# Which part installation.xml will be used
@_inst_mode = "installation"
# --> FATE #302123: Allow relative paths in "add_on_products" file
@base_product_url = nil
# Contains list of repository IDs that request registration
@addons_requesting_registration = []
# Every Add-On can preselect some patterns.
# Only patterns that are not selected/installed yet will be used.
#
#
# **Structure:**
#
# $[
# src_id : [
# "pattern_1", "pattern_2", "pattern_6"
# ]
# ]
@patterns_preselected_by_addon = {}
# additional product renames needed for detecting the product update
# @see #add_rename
@external_product_renames = {}
# Products which are selected for installation in libzypp.
# Due the "buddy" libzypp functionality also the release packages will
# be regarded.
# E.g.: product:sle-module-basesystem-15-0.x86_64 has buddy
# sle-module-basesystem-release-15-91.2.x86_64
@selected_installation_products = [] # e.g.: ["sle-module-basesystem"]
# Libzypp product renames cache. When loaded, it is supposed to be a Hash.
# @see #product_renames_from_libzypp
@libzypp_product_renames = nil
end
# Downloads a requested file, caches it and returns path to that cached file.
# If a file is alerady cached, just returns the path to a cached file.
# Parameter 'sod' defines whether a file is 'signed' (file + file.asc) or 'digested'
# (file digest mentioned in signed content file).
#
# @param [Fixnum] src_id
# @param [Fixnum] media
# @param [String] filename
# @param [String] sod ("signed" or "digested")
# @param [Boolean] optional (false if mandatory)
# @return [String] path to a cached file
#
# @example
# // content file is usually signed with content.asc
# AddOnProduct::GetCachedFileFromSource (8, 1, "/content", "signed", false);
# // the other files are usually digested in content file
# AddOnProduct::GetCachedFileFromSource (8, 1, "/images/images.xml", "digested", true);
def GetCachedFileFromSource(src_id, media, filename, sod, optional)
# BNC #486785: Jukebox when using more physical media-based Add-Ons at once
file_ID = Builtins.sformat("%1|%2|%3", src_id, media, filename)
provided_file = Ops.get(@source_file_cache, file_ID, "")
if !provided_file.nil? && provided_file != ""
# Checking whether the cached file exists
if FileUtils.Exists(provided_file)
Builtins.y2milestone(
"File %1 found in cache: %2",
file_ID,
provided_file
)
return provided_file
else
Builtins.y2warning("Cached file %1 not accessible!", provided_file)
@source_file_cache = Builtins.remove(@source_file_cache, file_ID)
end
end
optional = true if optional.nil?
case sod
when "signed"
provided_file = Pkg.SourceProvideSignedFile(
src_id,
media,
filename,
optional
)
when "digested"
provided_file = Pkg.SourceProvideDigestedFile(
src_id,
media,
filename,
optional
)
else
Builtins.y2error(
"Unknown SoD: %1. It can be only 'signed' or 'digested'",
sod
)
provided_file = nil
end
# A file has been found, caching...
if !provided_file.nil?
@filecachecounter = Ops.add(@filecachecounter, 1)
# Where the file is finally cached
cached_file = Builtins.sformat("%1%2", @filecachedir, @filecachecounter)
cmd = "/usr/bin/mkdir -p #{@filecachedir.shellescape}; " \
"/usr/bin/cp #{provided_file.shellescape} #{cached_file.shellescape}"
cmd_run = Convert.to_map(SCR.Execute(path(".target.bash_output"), cmd))
# Unable to cache a file, the original file will be returned
if Ops.get_integer(cmd_run, "exit", -1).nonzero?
Builtins.y2warning("Error caching file: %1: %2", cmd, cmd_run)
else
Builtins.y2milestone("File %1 cached as %2", file_ID, cached_file)
# Writes entry into cache database
Ops.set(@source_file_cache, file_ID, cached_file)
# Path to a cached file will be returned
provided_file = cached_file
end
end
provided_file
end
# Returns the current add-on installation mode.
#
# @return [String] current mode
# @see #SetMode()
def GetMode
@_inst_mode
end
# Sets internal add-on installation mode to either "installation" or "update".
# Mode is used later when deciding which part of the installation.xml to use.
#
# @param [String] new_mode ("installation" or "update")
# @see #GetMode();
def SetMode(new_mode)
if new_mode.nil? ||
!Builtins.contains(["installation", "update"], new_mode)
Builtins.y2error("Wrong Add-On mode: %1", new_mode)
end
@_inst_mode = new_mode
nil
end
# Returns whether add-on product got as parameter (source id)
# replaces some already installed add-on or whether it is a new
# installation. Repositories and target have to be initialized.
#
# @param [Fixnum] source_id source ID
def AddOnMode(source_id)
all_products = Y2Packager::Resolvable.find(kind: :product)
check_add_on = nil
# Search for an add-on using source ID
Builtins.foreach(all_products) do |one_product|
if one_product.source == source_id
check_add_on = deep_copy(one_product)
raise Break
end
end
ret = "installation"
supported_statuses = [:installed, :selected]
already_found = false
return ret if check_add_on.nil?
product_replaces = Ops.get_list(check_add_on, "replaces", [])
# Run through through all products that the add-on can replace
Builtins.foreach(product_replaces) do |one_replaces|
raise Break if already_found
# Run through all installed (or selected) products
Builtins.foreach(all_products) do |one_product|
# checking the status
if !Builtins.contains(
supported_statuses,
Ops.get_symbol(one_product, "status", :unknown)
)
next
end
# ignore itself
next if Ops.get_integer(one_product, "source", -42) == source_id
# check name to replace
if Ops.get_string(one_product, "name", "-A-") !=
Ops.get_string(one_replaces, "name", "-B-")
next
end
# check version to replace
if Ops.get_string(one_product, "version", "-A-") !=
Ops.get_string(one_replaces, "version", "-B-")
next
end
# check version to replace
if Ops.get_string(one_product, "arch", "-A-") !=
Ops.get_string(one_replaces, "arch", "-B-")
next
end
Builtins.y2milestone(
"Found product matching update criteria: %1 -> %2",
one_product,
check_add_on
)
ret = "update"
already_found = true
raise Break
end
end
ret
end
def SetBaseProductURL(url)
Builtins.y2warning("Empty base url") if url == "" || url.nil?
@base_product_url = url
Builtins.y2milestone(
"New base URL: %1",
URL.HidePassword(@base_product_url)
)
nil
end
def GetBaseProductURL
@base_product_url
end
# Returns an absolute URL from base + relative url.
# Relative URL needs to start with 'reulrl://' othewise
# it is not considered being relative and it's returned
# as it is (just the relative_url parameter).
#
# @param [String] base_url
# @param [String] url URL relative to the base
#
# @example
# AddOnProduct::GetAbsoluteURL (
# "http://www.example.org/some%20dir/another%20dir",
# "relurl://../AnotherProduct/"
# ) -> "http://www.example.org/some%20dir/AnotherProduct/"
# AddOnProduct::GetAbsoluteURL (
# "username:password@ftp://www.example.org/dir/",
# "relurl://./Product_CD1/"
# ) -> "username:password@ftp://www.example.org/dir/Product_CD1/"
def GetAbsoluteURL(base_url, url)
if !Builtins.regexpmatch(url, "^relurl://")
Builtins.y2debug("Not a relative URL: %1", URL.HidePassword(url))
return url
end
if base_url.nil? || base_url == ""
Builtins.y2error("No base_url defined")
return url
end
# bugzilla #306670
base_params_pos = Builtins.search(base_url, "?")
base_params = ""
if !base_params_pos.nil? && Ops.greater_or_equal(base_params_pos, 0)
base_params = Builtins.substring(base_url, Ops.add(base_params_pos, 1))
base_url = Builtins.substring(base_url, 0, base_params_pos)
end
added_params_pos = Builtins.search(url, "?")
added_params = ""
if !added_params_pos.nil? && Ops.greater_or_equal(added_params_pos, 0)
added_params = Builtins.substring(url, Ops.add(added_params_pos, 1))
url = Builtins.substring(url, 0, added_params_pos)
end
base_url = Ops.add(base_url, "/") if !Builtins.regexpmatch(base_url, "/$")
Builtins.y2milestone(
"Merging '%1' (params '%2') to '%3' (params '%4')",
url,
added_params,
base_url,
base_params
)
url = Builtins.regexpsub(url, "^relurl://(.*)$", "\\1")
url = Builtins.sformat("%1%2", base_url, url)
# merge /something/../
max_count = 100
while Ops.greater_than(max_count, 0) &&
Builtins.regexpmatch(url, "(.*/)[^/]+/+\\.\\./")
max_count = Ops.subtract(max_count, 1)
str_offset_l = Builtins.regexppos(url, "/\\.\\./")
str_offset = Ops.get(str_offset_l, 0)
next unless !str_offset.nil? && Ops.greater_than(str_offset, 0)
stringfirst = Builtins.substring(url, 0, str_offset)
stringsecond = Builtins.substring(url, str_offset)
Builtins.y2debug(
"Pos: %1 First: >%2< Second: >%3<",
str_offset,
stringfirst,
stringsecond
)
stringfirst = Builtins.regexpsub(stringfirst, "^(.*/)[^/]+/*$", "\\1")
stringsecond = Builtins.regexpsub(
stringsecond,
"^/\\.\\./(.*)$",
"\\1"
)
url = Ops.add(stringfirst, stringsecond)
end
# remove /./
max_count = 100
while Ops.greater_than(max_count, 0) && Builtins.regexpmatch(url, "/\\./")
max_count = Ops.subtract(max_count, 1)
url = Builtins.regexpsub(url, "^(.*)/\\./(.*)", "\\1/\\2")
end
base_params_map = URL.MakeMapFromParams(base_params)
added_params_map = URL.MakeMapFromParams(added_params)
final_params_map = Convert.convert(
Builtins.union(base_params_map, added_params_map),
from: "map",
to: "map <string, string>"
)
if Ops.greater_than(Builtins.size(final_params_map), 0)
Builtins.y2milestone(
"%1 merge %2 -> %3",
base_params_map,
added_params_map,
final_params_map
)
url = Ops.add(
Ops.add(url, "?"),
URL.MakeParamsFromMap(final_params_map)
)
end
Builtins.y2milestone("Final URL: '%1'", URL.HidePassword(url))
url
end
# <--
# Adapts the inst-sys from the tarball
# @param [String] filename string the filename with the tarball to use to the update
# @return [Boolean] true on success
def UpdateInstSys(filename)
@src_cache_id = Ops.add(@src_cache_id, 1)
tmpdir = Convert.to_string(SCR.Read(path(".target.tmpdir")))
tmpdir = Builtins.sformat("%1/%2", tmpdir, @src_cache_id)
out = SCR.Execute(
path(".target.bash_output"),
Builtins.sformat(
"\n" \
"/usr/bin/mkdir %1;\n" \
"cd %1;\n" \
"/bin/tar -xvf %2;\n" \
"/sbin/adddir %1 /;\n",
tmpdir.shellescape,
filename.shellescape
)
)
if Ops.get_integer(out, "exit", 0).nonzero?
Builtins.y2error("Including installation image failed: %1", out)
return false
end
Builtins.y2milestone("Including installation image succeeded")
true
end
# New add-on product might add also new agents.
# Functions Rereads all available agents.
#
# @see bugzilla #239055, #245508
def RereadAllSCRAgents
Builtins.y2milestone("Registering new agents...")
ret = SCR.RegisterNewAgents
if ret
Builtins.y2milestone("Successful")
else
Builtins.y2error("Error occured during registering new agents!")
Report.Error(
_("An error occurred while preparing the installation system.")
)
end
nil
end
# Remove the /y2update directory from the system
def CleanY2Update
SCR.Execute(path(".target.bash"), "/bin/rm -rf /y2update")
nil
end
# Show beta file in a pop-up message if such file exists.
# Show license if such exists and return whether users accepts it.
# Returns 'nil' when did not succed.
#
# @return [Boolean] whether the license has been accepted
def AcceptedLicenseAndInfoFile(src_id)
ret = ProductLicense.AskAddOnLicenseAgreement(src_id)
return nil if ret.nil?
if [:refused, :abort, :back].include?(ret)
Builtins.y2milestone("License confirmation failed")
return false
end
true
end
def AnyPatternInRepo
patterns = Y2Packager::Resolvable.find(kind: :pattern, source: @src_id)
Builtins.y2milestone("Found %1 add-on patterns", Builtins.size(patterns))
Builtins.y2debug("Found add-on patterns: %1", patterns)
Ops.greater_than(Builtins.size(patterns), 0)
end
def DoInstall_NoControlFile
Builtins.y2milestone(
"File /installation.xml not found, running sw_single for this repository"
)
# display pattern the dialog when there is a pattern provided by the addon
# otherwise use the summary mode
mode = AnyPatternInRepo() ? :patternSelector : :summaryMode
# enable repository management if not in installation mode
enable_repo_management = Mode.normal
args = { "dialog_type" => mode, "repo_mgmt" => enable_repo_management }
Builtins.y2milestone("Arguments for sw_single: %1", args)
ret = WFM.CallFunction("sw_single", [args])
Builtins.y2milestone("sw_single returned: %1", ret)
return :abort if [:abort, :cancel, :close].include?(ret)
:register
end
def IntegrateY2Update(src_id)
# this works only with the SUSE tags repositories
binaries = GetCachedFileFromSource(
src_id, # optional
1,
"/y2update.tgz",
"digested",
true
)
# try the package containing the installer update, works with all repositories,
# including RPM-MD
binaries ||= y2update_path(src_id)
# File /y2update.tgz exists
if binaries.nil?
Builtins.y2milestone("File /y2update.tgz not provided")
else
# Try to extract files from the archive
out = Convert.to_map(
SCR.Execute(
path(".target.bash_output"),
Builtins.sformat(
"\n" \
"/usr/bin/test -d /y2update && /usr/bin/rm -rf /y2update;\n" \
"/bin/mkdir -p /y2update/all;\n" \
"cd /y2update/all;\n" \
"/bin/tar -xvf %1;\n" \
"cd /y2update;\n" \
"/usr/bin/ln -s all/usr/share/YaST2/* .;\n" \
"/usr/bin/ln -s all/usr/lib/YaST2/* .;\n",
binaries.shellescape
)
)
)
# Failed
if Ops.get_integer(out, "exit", 0).nonzero?
# error report
Report.Error(
_("An error occurred while preparing the installation system.")
)
CleanY2Update()
return false
else
# bugzilla #239055
RereadAllSCRAgents()
end
end
true
end
def DoInstall_WithControlFile(control)
Builtins.y2milestone(
"File /installation.xml was found, running own workflow..."
)
# copy the control file to local filesystem - in case of media release
tmp = Convert.to_string(SCR.Read(path(".target.tmpdir")))
tmp = Ops.add(tmp, "/installation.xml")
SCR.Execute(
path(".target.bash"),
"/usr/bin/cp #{control.shellescape} #{tmp.shellescape}"
)
control = tmp
return nil if !IntegrateY2Update(@src_id)
# set control file
ProductControl.custom_control_file = control
if !ProductControl.Init
# error report
Report.Error(
Builtins.sformat(_("Control file %1 not found on media."), control)
)
CleanY2Update()
return nil
end
current_stage = "normal"
current_mode = "installation"
# Special add-on mode (GetMode()) returns the same
# add-on can be either installed (first time) or updated by another add-on
ProductControl.SetAdditionalWorkflowParams(
"add_on_mode" => AddOnMode(@src_id)
)
steps = ProductControl.getModules(current_stage, current_mode, :enabled)
if steps.nil? || Ops.less_than(Builtins.size(steps), 1)
Builtins.y2warning(
"Add-On product workflow for stage: %1, mode: %2 not defined",
current_stage,
current_mode
)
ProductControl.ResetAdditionalWorkflowParams
return nil
end
# start workflow
Wizard.OpenNextBackStepsDialog
# dialog caption
Wizard.SetContents(_("Initializing..."), Empty(), "", false, false)
stage_mode = [{ "stage" => current_stage, "mode" => current_mode }]
Builtins.y2milestone("Using Add-On control file parts: %1", stage_mode)
ProductControl.AddWizardSteps(stage_mode)
old_mode = nil
# Running system, not installation, not update
if Stage.normal && Mode.normal
old_mode = Mode.mode
Mode.SetMode(current_mode)
end
# Run the workflow
ret = ProductControl.Run
Mode.SetMode(old_mode) if !old_mode.nil?
UI.CloseDialog
CleanY2Update()
ProductControl.ResetAdditionalWorkflowParams
ret
end
def ClearRegistrationRequest(src_id)
Builtins.y2milestone(
"Clearing registration flag for repository ID %1",
src_id
)
if !src_id.nil?
@addons_requesting_registration = Builtins.filter(
@addons_requesting_registration
) { |one_source| one_source != src_id }
end
nil
end
# Returns whether registration is requested by at least one of
# used Add-On products.
#
# @return [Boolean] if requested
def ProcessRegistration
force_registration = false
# checking add-on products one by one
Builtins.foreach(@add_on_products) do |prod|
srcid = Ops.get_integer(prod, "media")
if !srcid.nil? &&
Builtins.contains(@addons_requesting_registration, srcid)
force_registration = true
raise Break
end
end
Builtins.y2milestone("Requesting registration: %1", force_registration)
force_registration
end
# Add-On product might have been added into products requesting
# registration. This pruduct has been removed (during configuring
# list of add-on products).
def RemoveRegistrationFlag(src_id)
# filtering out src_id
@addons_requesting_registration = Builtins.filter(
@addons_requesting_registration
) { |one_id| one_id != src_id }
# removing cached file
tmpdir = Ops.add(
Convert.to_string(SCR.Read(path(".target.tmpdir"))),
"/add-on-content-files/"
)
cachedfile = Builtins.sformat("%1content-%2", tmpdir, src_id)
if FileUtils.Exists(cachedfile)
Builtins.y2milestone("Removing cached file %1", cachedfile)
SCR.Execute(path(".target.remove"), cachedfile)
end
nil
end
# Checks whether the addon at src_id need registration
# If it has, product is added into list of products that need registration.
#
# @param [Fixnum] src_id source id
def PrepareForRegistration(src_id)
control_file = WorkflowManager.GetCachedWorkflowFilename(:addon, src_id, "")
return unless WorkflowManager.IncorporateControlFileOptions(control_file)
# FATE #305578: Add-On Product Requiring Registration
return unless WorkflowManager.WorkflowRequiresRegistration(src_id)
log.info "REGISTERPRODUCT (require_registration) defined in control file"
@addons_requesting_registration << deep_copy(src_id)
end
# Calls registration client if needed.
#
# @param [Fixnum] src_id source id
def RegisterAddOnProduct(src_id)
# FATE #305578: Add-On Product Requiring Registration
if WorkflowManager.WorkflowRequiresRegistration(src_id) ||
Builtins.contains(@addons_requesting_registration, src_id)
Builtins.y2milestone("Repository ID %1 requests registration", src_id)
if !WFM.ClientExists("inst_scc")
package_installed = Package.Install("yast2-registration")
if !package_installed
Report.Error(_("Package '%s' is not installed.\n" \
"The add-on product cannot be registered.") % "yast2-registration")
return nil
end
end
# pass the addon so it could be registered
WFM.CallFunction("inst_scc", ["register_media_addon", src_id])
else
Builtins.y2milestone(
"Repository ID %1 doesn't need registration",
src_id
)
end
nil
end
# Do installation of the add-on product within an installed system
# srcid is got via AddOnProduct::src_id
#
# @param install_packages [Boolean] install the selected packages if no
# installation.xml is found on the addon, can be optionally disabled
# @return [Symbol] the result symbol from wizard sequencer
def DoInstall(install_packages: true)
# Display beta file if such file exists
# Display license and wait for agreement
# Not needed here, license already shown in the workflow
# boolean license_ret = AcceptedLicenseAndInfoFile(src_id);
# if (license_ret != true) {
# y2milestone("Removing the current source ID %1", src_id);
# Pkg::SourceDelete(src_id);
# return nil;
# }
# FATE #301312
PrepareForRegistration(@src_id)
# FATE #301997: Support update of add-on products properly
add_on_mode = AddOnMode(@src_id)
SetMode(add_on_mode)
# BNC #468449
# Always store the current set of repositories as they might get
# changed by registration or the called add-on workflow
Pkg.SourceSaveAll
ret = nil
control = WorkflowManager.GetCachedWorkflowFilename(:addon, @src_id, "")
if !control.nil?
# FATE #305578: Add-On Product Requiring Registration
WorkflowManager.AddWorkflow(:addon, @src_id, "")
Builtins.y2milestone("Add-On has own control file")
ret = DoInstall_WithControlFile(control)
end
# Fallback -- Repository didn't provide needed control file
# or control file doesn't contain needed stage/mode
# Handling as it was a repository
ret = DoInstall_NoControlFile() if install_packages && (control.nil? || ret.nil?)
Builtins.y2milestone("Result of the add-on installation: %1", ret)
if !ret.nil? && ret != :abort
# registers Add-On product if requested
RegisterAddOnProduct(@src_id)
end
if ret == :abort
# cleanup after abort
Builtins.y2milestone(
"Add-on installation aborted, removing installation source %1: %2",
@src_id,
Pkg.SourceGeneralData(@src_id)
)
Pkg.SourceDelete(@src_id)
Pkg.SourceSaveAll
# remove from the internal list
@add_on_products = Builtins.filter(@add_on_products) do |add_on_product|
Ops.get_integer(add_on_product, "media", -1) != @src_id
end
# reset the src id, it's not valid
@src_id = nil
end
Builtins.y2milestone("Returning: %1", ret)
ret
end
def PackagesProposalAddonID(src_id)
"Add-On-Product-ID:#{src_id}"
end
# Integrate the add-on product to the installation workflow, including
# preparations for 2nd stage and inst-sys update
# @param [Fixnum] srcid integer the ID of the repository
# @return [Boolean] true on success
def Integrate(srcid)
Builtins.y2milestone("Integrating repository %1", srcid)
# Updating inst-sys, this works only with the SUSE tags repositories
y2update = GetCachedFileFromSource(
srcid, # optional
1,
"/y2update.tgz",
"digested",
true
)
# try the package containing the installer update, works with all repositories,
# including RPM-MD
y2update ||= y2update_path(srcid)
if y2update.nil?
Builtins.y2milestone("No YaST update found on the media")
else
UpdateInstSys(y2update)
end
# FATE #302398: PATTERNS keyword in content file
# changed for software section in installation.xml
# or 'defaultpattern()' product Provides (FATE#320199)
# Adds workflow to the Workflow Store if any workflow exists
WorkflowManager.AddWorkflow(:addon, srcid, "")
true
end
# Opposite to Integrate()
#
# @param [Fixnum] srcid integer the ID of the repository
def Disintegrate(srcid)
WorkflowManager.RemoveWorkflow(:addon, srcid, "")
nil
end
# Some product(s) were removed, reintegrating their control files from scratch.
def ReIntegrateFromScratch
Builtins.y2milestone("Reintegration workflows from scratch...")
# bugzilla #239055
RereadAllSCRAgents()
# Should have been done before (by calling AddOnProduct::Integrate()
# foreach (map<string,any> prod, AddOnProduct::add_on_products, {
# integer srcid = (integer) prod["media"]:nil;