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
|
# File '../../src/include/packager/repositories_include.rb', line 47
def createSourceImpl(url, plaindir, download, preffered_name, force_alias)
Builtins.y2milestone(
"createSource: %1, plaindir: %2, download: %3, name: %4",
URL.HidePassword(url),
plaindir,
download,
preffered_name
)
if url != ""
parsed = URL.Parse(url)
scheme = Ops.get_string(parsed, "scheme", "")
if plaindir == true
Builtins.y2milestone("Using PlainDir repository type")
end
if scheme == "smb" &&
Ops.less_than(SCR.Read(path(".target.size"), "/sbin/mount.cifs"), 0)
Builtins.y2milestone(
"SMB/CIFS share cannot be mounted, installing missing 'cifs-mount' package..."
)
PackageSystem.CheckAndInstallPackages(["cifs-mount"])
end
Progress.New(
_("Adding a New Repository"),
" ",
3,
[
_("Check Repository Type"),
_("Add Repository"),
_("Read Repository License")
],
[
_("Checking Repository Type"),
_("Adding Repository"),
_("Reading Repository License")
],
_(
"<p>The repository manager is downloading repository details...</p>"
)
)
Progress.NextStage
service_type = Pkg.ServiceProbe(url)
Builtins.y2milestone("Probed service type: %1", service_type)
if service_type != nil && service_type != "NONE"
Builtins.y2milestone("Adding a service of type %1...", service_type)
_alias = "service"
aliases = Builtins.maplist(@serviceStatesOut) do |s|
Ops.get_string(s, "alias", "")
end
idx = 1
while Builtins.contains(aliases, _alias)
_alias = Builtins.sformat("service_%1", idx)
idx = Ops.add(idx, 1)
end
autorefresh = true
schema = Builtins.tolower(Builtins.substring(url, 0, 3))
if schema == "cd:" || schema == "dvd"
autorefresh = false
Builtins.y2milestone("Disabling autorefresh for a CD/DVD service")
end
if preffered_name == nil || preffered_name == ""
preffered_name = _alias
end
new_service = {
"alias" => _alias,
"autorefresh" => autorefresh,
"enabled" => true,
"name" => preffered_name,
"url" => url
}
Builtins.y2milestone("Added new service: %1", new_service)
@serviceStatesOut = Builtins.add(@serviceStatesOut, new_service)
return :ok
end
new_repos = Pkg.RepositoryScan(url)
Builtins.y2milestone("new_repos: %1", new_repos)
if Builtins.size(new_repos) == 0
url_path = Ops.get_string(URL.Parse(url), "path", "")
p_elems = Builtins.splitstring(url_path, "/")
fallback = _("Repository")
if Ops.greater_than(Builtins.size(p_elems), 1)
url_path = Ops.get(
p_elems,
Ops.subtract(Builtins.size(p_elems), 1),
fallback
)
if url_path == nil || url_path == ""
url_path = Ops.get(
p_elems,
Ops.subtract(Builtins.size(p_elems), 2),
fallback
)
url_path = fallback if url_path == nil || url_path == ""
end
end
new_repos = [[url_path, "/"]]
end
newSources = []
auto_refresh = true
iso_prefix = "iso:"
if Builtins.substring(url, 0, Builtins.size(iso_prefix)) == iso_prefix
Builtins.y2milestone(
"ISO image detected, disabling autorefresh (%1)",
URL.HidePassword(url)
)
auto_refresh = false
end
cd_scheme = Builtins.contains(
["cd", "dvd"],
Builtins.tolower(Ops.get_string(URL.Parse(url), "scheme", ""))
)
if cd_scheme
Builtins.y2milestone(
"CD/DVD repository detected, disabling autorefresh (%1)",
URL.HidePassword(url)
)
auto_refresh = false
end
enter_again = false
Builtins.foreach(new_repos) do |repo|
next if enter_again
name = Ops.get(repo, 0, "")
name = preffered_name if preffered_name != nil && preffered_name != ""
prod_dir = Ops.get(repo, 1, "/")
repo_type = plaindir ?
@plaindir_type :
Pkg.RepositoryProbe(url, prod_dir)
Builtins.y2milestone(
"Repository type (%1,%2): %3",
URL.HidePassword(url),
prod_dir,
repo_type
)
if repo_type == nil || repo_type == "NONE"
if scheme == "dir"
if !Popup.AnyQuestion(
Popup.NoHeadline,
_(
"There is no product information available at the given location.\n" +
"If you expected to to point a product, go back and enter\n" +
"the correct location.\n" +
"To make rpm packages located at the specified location available\n" +
"in the packages selection, continue.\n"
),
Label.ContinueButton,
Label.BackButton,
:focus_no
)
enter_again = true
next
end
repo_type = @plaindir_type
Builtins.y2warning(
"Probing has failed, using Plaindir repository type."
)
else
next
end
end
_alias = ""
if force_alias == ""
_alias = Builtins.mergestring(Builtins.splitstring(name, " "), "_")
alias_orig = _alias
aliases = Builtins.maplist(Pkg.SourceGetCurrent(false)) do |i|
info = Pkg.SourceGeneralData(i)
Ops.get_string(info, "alias", "")
end
idx = 1
while Builtins.contains(aliases, _alias)
_alias = Builtins.sformat("%1_%2", alias_orig, idx)
idx = Ops.add(idx, 1)
end
else
_alias = force_alias
end
repo_prop = {}
Ops.set(repo_prop, "enabled", true)
Ops.set(repo_prop, "autorefresh", auto_refresh)
Ops.set(repo_prop, "name", name)
Ops.set(repo_prop, "prod_dir", Ops.get(repo, 1, "/"))
Ops.set(repo_prop, "alias", _alias)
Ops.set(repo_prop, "base_urls", [url])
Ops.set(repo_prop, "type", repo_type)
if force_alias != ""
Ops.set(repo_prop, "check_alias", false)
end
Progress.NextStage
new_repo_id = Pkg.RepositoryAdd(repo_prop)
repo_prop_log = deep_copy(repo_prop)
Ops.set(repo_prop_log, "base_urls", [URL.HidePassword(url)])
Builtins.y2milestone(
"Added repository: %1: %2",
new_repo_id,
repo_prop_log
)
newSources = Builtins.add(newSources, new_repo_id)
if cd_scheme
Builtins.y2milestone(
"Adding a CD or DVD repository, refreshing now..."
)
Pkg.SourceRefreshNow(new_repo_id)
end
end
if enter_again
Pkg.SourceReleaseAll
return :again
end
Builtins.y2milestone("New sources: %1", newSources)
if Builtins.size(newSources) == 0
Builtins.y2error("Cannot add the repository")
msg = Builtins.sformat(
_("Unable to create repository\nfrom URL '%1'."),
URL.HidePassword(url)
)
if Builtins.regexpmatch(url, "\\.iso$")
parsed_url = URL.Parse(url)
scheme2 = Builtins.tolower(Ops.get_string(parsed_url, "scheme", ""))
if Builtins.contains(["ftp", "sftp", "http", "https"], scheme2)
msg = Ops.add(
Ops.add(msg, "\n\n"),
_(
"Using an ISO image over ftp or http protocol is not possible.\nChange the protocol or unpack the ISO image on the server side."
)
)
end
end
msg = Ops.add(
Ops.add(msg, "\n\n"),
_("Change the URL and try again?")
)
tryagain = Popup.YesNo(msg)
return :again if tryagain
return :cancel
else
Progress.NextStage
license_accepted = true
Builtins.foreach(newSources) do |id|
if !LicenseAccepted(id)
Builtins.y2milestone("License NOT accepted, removing the source")
Pkg.SourceDelete(id)
license_accepted = false
else
src_data = Pkg.SourceGeneralData(id)
Builtins.y2milestone("Addded repository: %1", src_data)
sourceState = {
"SrcId" => id,
"enabled" => Ops.get_boolean(src_data, "enabled", true),
"autorefresh" => Ops.get_boolean(src_data, "autorefresh", true),
"name" => Ops.get_string(src_data, "name", ""),
"do_refresh" => download
}
@sourceStatesOut = Builtins.add(@sourceStatesOut, sourceState)
end
end
Pkg.SourceReleaseAll
return license_accepted ? :ok : :abort
end
else
Builtins.y2error(-1, "Empty URL! Backtrace:")
return :again
end
end
|