Class: Yast::InstserverClass

Inherits:
Module
  • Object
show all
Defined in:
../../src/modules/Instserver.rb

Instance Method Summary (collapse)

Instance Method Details

- (Boolean) Abort

Abort function

Returns:

  • (Boolean)


84
85
86
87
# File '../../src/modules/Instserver.rb', line 84

def Abort
  return Builtins.eval(@AbortFunction) if @AbortFunction != nil
  false
end

- (Object) basearch_mapping(basearch)



743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
# File '../../src/modules/Instserver.rb', line 743

def basearch_mapping(basearch)
  mapping = {
    "i586"   => ["i586", "i686"],
    "mips"   => ["mips", "mips64"],
    "ppc"    => ["ppc", "ppc64"],
    "sparc"  => ["sparc", "sparc64"],
    "x86_64" => ["x86_64"]
  }

  if !Builtins.haskey(mapping, basearch)
    Builtins.y2warning("Unknown BASEARCH: %1", basearch)
  end

  # return the original basearch if mapping is unknown
  ret = Ops.get(mapping, basearch) { [basearch] }

  Builtins.y2milestone("Using BASEARCH mapping: %1 -> %2", basearch, ret)

  deep_copy(ret)
end

- (void) configSetup

This method returns an undefined value.

Create XML Configuration



1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
# File '../../src/modules/Instserver.rb', line 1411

def configSetup
  doc = {}
  Ops.set(doc, "listEntries", {})
  Ops.set(doc, "cdataSections", [])
  Ops.set(doc, "rootElement", "instserver")
  Ops.set(doc, "systemID", "/usr/share/YaST2/dtd/instserver.dtd")
  Ops.set(doc, "nameSpace", "http://www.suse.com/1.0/yast2ns")
  Ops.set(doc, "typeNamespace", "http://www.suse.com/1.0/configns")
  XML.xmlCreateDoc(:instserver, doc)
  nil
end

- (Object) ConfigureService(module_auto, resource)

Configure service using _auto



279
280
281
282
283
284
285
286
287
288
289
290
291
# File '../../src/modules/Instserver.rb', line 279

def ConfigureService(module_auto, resource)
  resource = deep_copy(resource)
  Builtins.y2milestone(
    "New configuration for service %1: %2",
    module_auto,
    resource
  )

  ret = false
  ret = Convert.to_boolean(Call.Function(module_auto, ["Import", resource]))
  ret = Convert.to_boolean(Call.Function(module_auto, ["Write", resource]))
  ret
end

Create links



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
# File '../../src/modules/Instserver.rb', line 108

def createLinks(dir, product, files)
  files = deep_copy(files)
  shorttgt = Builtins.sformat("%1/CD%2", product, 1)
  cmds = []

  Builtins.foreach(files) do |symlink|
    f = Builtins.sformat("%1/%2/%3", dir, shorttgt, symlink)
    # always return success - the link may be missing if the target file doesn't exist
    cmds = Builtins.add(
      cmds,
      Builtins.sformat(
        "( test -f %1 || test -d %2) &&  pushd %3 && ln -sf %4/%5 && popd; exit 0",
        f,
        f,
        dir,
        shorttgt,
        symlink
      )
    )
  end
  cmds = Builtins.add(cmds, Builtins.sformat("mkdir -p %1/yast", dir))

  Builtins.y2debug("cmds: %1", cmds)
  deep_copy(cmds)
end

- (Object) createOrderFiles(dir)

Create yast directory with ordr/instorder files

Parameters:

  • string

    directory

Returns:

  • booelan



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
# File '../../src/modules/Instserver.rb', line 138

def createOrderFiles(dir)
  if Ops.greater_than(Builtins.size(@products), 1)
    SCR.Execute(path(".target.mkdir"), Ops.add(dir, "/yast"))

    Builtins.y2milestone("products: %1", @products)
    # create order: Service Packs, products which require any other product, other products
    order = Builtins.filter(@products) do |p|
      Ops.get_boolean(p, "SP", false)
    end
    order = Convert.convert(
      Builtins.union(order, Builtins.filter(@products) do |p|
        !Ops.get_boolean(p, "baseproduct", false) &&
          !Ops.get_boolean(p, "SP", false)
      end),
      :from => "list",
      :to   => "list <map>"
    )
    order = Convert.convert(
      Builtins.union(order, Builtins.filter(@products) do |p|
        Ops.get_boolean(p, "baseproduct", false) &&
          !Ops.get_boolean(p, "SP", false)
      end),
      :from => "list",
      :to   => "list <map>"
    )
    Builtins.y2milestone("order: %1", order)

    instorder = Builtins.filter(@products) do |p|
      Ops.get_boolean(p, "baseproduct", false)
    end
    instorder = Convert.convert(
      Builtins.union(instorder, Builtins.filter(@products) do |p|
        !Ops.get_boolean(p, "baseproduct", false)
      end),
      :from => "list",
      :to   => "list <map>"
    )

    # HACK: support sles8 too
    ul = Builtins.filter(instorder) do |u|
      Builtins.issubstring(
        Builtins.tolower(Ops.get_string(u, "name", "")),
        "unitedlinux"
      )
    end
    instorder = deep_copy(order) if Builtins.size(ul) == 0
    Builtins.y2milestone("instorder: %1", instorder)

    file = []
    Builtins.foreach(order) do |p|
      # workaround for NLD9 - if the subdir doesn't exists use root
      proddir = Ops.less_than(
        SCR.Read(
          path(".target.size"),
          Ops.add(Ops.add(dir, "/"), Ops.get_string(p, "name", ""))
        ),
        0
      ) ?
        "/" :
        Builtins.sformat("/%1/CD1", Ops.get_string(p, "name", ""))
      file = Builtins.add(
        file,
        Builtins.mergestring([proddir, proddir], "\t")
      )
    end
    file = Builtins.add(file, "")
    SCR.Write(
      path(".target.string"),
      Ops.add(dir, "/yast/order"),
      Builtins.mergestring(file, "\n")
    )
    file = []
    Builtins.foreach(instorder) do |p|
      # workaround for NLD9 - if the subdir doesn't exists use root
      proddir = Ops.less_than(
        SCR.Read(
          path(".target.size"),
          Ops.add(Ops.add(dir, "/"), Ops.get_string(p, "name", ""))
        ),
        0
      ) ?
        "/" :
        Builtins.sformat("/%1/CD1", Ops.get_string(p, "name", ""))
      file = Builtins.add(file, proddir)
    end
    file = Builtins.add(file, "")
    SCR.Write(
      path(".target.string"),
      Ops.add(dir, "/yast/instorder"),
      Builtins.mergestring(file, "\n")
    )
  end
  @products = []

  true
end

- (Object) DetectMedia



995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
# File '../../src/modules/Instserver.rb', line 995

def DetectMedia
  if Ops.get_string(@ServerSettings, "directory", "") != ""
    f = Builtins.sformat(
      "find %1 -maxdepth 2 -name %2 | grep -v yast",
      Ops.get_string(@ServerSettings, "directory", ""),
      "content"
    )
    ret = Convert.to_map(SCR.Execute(path(".target.bash_output"), f))
    found = Builtins.splitstring(Ops.get_string(ret, "stdout", ""), "\n")
    found = Builtins.filter(found) { |s| s != "" }
    found = Builtins.filter(found) do |file|
      d = dirname(file)
      media = Builtins.sformat("%1/media.1/media", d)
      SCR.Read(path(".target.size"), media) != -1
    end
    Builtins.y2debug("media: %1", found)
    return deep_copy(found)
  else
    return []
  end
end

- (Object) EscapeSLPData(a)

some values are not allowed in SLP attributes and must be escaped ('\' followed by two hex numbers) see RFC2614 (www.openslp.org/doc/rfc/rfc2614.txt)



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
# File '../../src/modules/Instserver.rb', line 614

def EscapeSLPData(a)
  a = deep_copy(a)
  ret = {}

  Builtins.foreach(a) do |key, value|
    # String::Replace() enters endless loop in '\' -> '\5c' conversion
    # use splitstring() and mergestring() builtins instead
    new_key = Builtins.mergestring(Builtins.splitstring(key, "\\"), "\\5c")
    new_key = String.Replace(new_key, ".", "\\2e")
    new_key = String.Replace(new_key, "=", "\\3d")
    new_key = String.Replace(new_key, "#", "\\23")
    new_key = String.Replace(new_key, ";", "\\3b")
    new_value = Builtins.mergestring(
      Builtins.splitstring(value, "\\"),
      "\\5c"
    )
    new_value = String.Replace(new_value, "(", "\\28")
    new_value = String.Replace(new_value, ")", "\\29")
    new_value = String.Replace(new_value, ",", "\\2c")
    new_value = String.Replace(new_value, "#", "\\23")
    new_value = String.Replace(new_value, ";", "\\3b")
    Ops.set(ret, new_key, new_value)
  end 


  Builtins.y2milestone("Escaped SLP attributes: %1 -> %2", a, ret)

  deep_copy(ret)
end

- (Hash) Export

Dump the instserver settings to a single map (For use by autoinstallation.)

Returns:

  • (Hash)

    Dumped settings (later acceptable by Import ())



1436
1437
1438
# File '../../src/modules/Instserver.rb', line 1436

def Export
  {}
end

- (Object) FindAvailable



1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
# File '../../src/modules/Instserver.rb', line 1017

def FindAvailable
  _Available = {}
  Builtins.foreach(@Detected) do |c|
    ret = ReadContentFile(c)
    d = dirname(c)
    config_name = basename(d)
    if ret != {} && !Builtins.haskey(@Configs, config_name)
      Ops.set(_Available, d, ret)
    end
  end
  deep_copy(_Available)
end

- (Object) FTPValid(config)



1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
# File '../../src/modules/Instserver.rb', line 1065

def FTPValid(config)
  config = deep_copy(config)
  if vsftpd_is_standalone
    # is the service running?
    ret2 = Service.Status("vsftpd") == 0
    Builtins.y2milestone("FTP (vsftpd) server running: %1", ret2)

    return ret2
  end

  # read the current configuration
  resource = Convert.to_map(ReadServiceSettings("inetd_auto"))

  # check vsftpd config
  ftpdenabled = false
  servicefound = false

  Builtins.foreach(Ops.get_list(resource, "netd_conf", [])) do |conf|
    # the service is ftp with vsftpd server
    if Ops.get_string(conf, "service", "") == "ftp" &&
        Ops.get_string(conf, "script", "") == "vsftpd"
      servicefound = true
      # the default is true: missing tag means the service is enabled (!)
      ftpdenabled = Ops.get_boolean(conf, "enabled", true)
    end
  end 


  Builtins.y2milestone(
    "FTP service check: found: %1, enabled: %2",
    servicefound,
    ftpdenabled
  )

  return false if servicefound == false || ftpdenabled == false

  # is the service running?
  ret = Service.Status("xinetd") == 0
  Builtins.y2milestone("FTP server running: %1", ret)

  ret
end

- (Object) get_machines(basearch_value)



764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
# File '../../src/modules/Instserver.rb', line 764

def get_machines(basearch_value)
  archs = Builtins.splitstring(basearch_value, " ")
  archs = Builtins.filter(archs) { |a| a != nil && a != "" }

  ret = []

  Builtins.foreach(archs) do |a|
    ret = Convert.convert(
      Builtins.merge(ret, basearch_mapping(a)),
      :from => "list",
      :to   => "list <string>"
    )
  end 


  Builtins.y2milestone("Final BASEARCH mapping: %1", ret)

  deep_copy(ret)
end

- (Object) GetHostname



731
732
733
734
735
736
737
738
739
740
741
# File '../../src/modules/Instserver.rb', line 731

def GetHostname
  output = Convert.to_map(
    SCR.Execute(path(".target.bash_output"), "/bin/hostname --long")
  )
  Builtins.y2milestone("hostname --long: %1", output)
  hostname = Ops.get_string(output, "stdout", "")

  hostname = Ops.get(Builtins.splitstring(hostname, "\n"), 0, "")

  hostname
end

- (Object) GetIPAddr

Return the IP address of the local machine

Returns:

  • string IP Address



709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
# File '../../src/modules/Instserver.rb', line 709

def GetIPAddr
  ifconfig = Convert.convert(
    SCR.Read(path(".run.ifconfig")),
    :from => "any",
    :to   => "list <map>"
  )
  ifc = Builtins.filter(ifconfig) do |iface|
    Ops.get_string(iface, "name", "") == "eth0"
  end
  ip = Ops.get_integer(ifc, [0, "value", "inet", "addr"], 0)
  if ip == 0
    ifc = Builtins.filter(ifconfig) do |iface|
      Ops.get_string(iface, "name", "") != "lo" &&
        !Builtins.issubstring(Ops.get_string(iface, "name", ""), "dummy") &&
        Ops.get_integer(iface, ["value", "inet", "addr"], 0) != 0
    end
    ip = Ops.get_integer(ifc, [0, "value", "inet", "addr"], 0) if ifc != nil
  end

  IP.ToString(ip)
end

- (Object) HTTPValid(config)



1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
# File '../../src/modules/Instserver.rb', line 1108

def HTTPValid(config)
  config = deep_copy(config)
  config = "/etc/apache2/conf.d/inst_server.conf"

  # is the config missing
  config_size = Convert.to_integer(SCR.Read(path(".target.size"), config))
  Builtins.y2milestone("Size of %1: %2", config, config_size)

  if Ops.less_or_equal(config_size, 0)
    Builtins.y2warning("Missing config file: %1", config)
    return false
  end

  # is the service running?
  ret = Service.Status("apache2") == 0
  Builtins.y2milestone("HTTP server running: %1", ret)

  ret
end

- (Boolean) Import(settings)

Get all instserver settings from the first parameter (For use by autoinstallation.)

Parameters:

  • settings (Hash)

    The YCP structure to be imported.

Returns:

  • (Boolean)

    True on success



1428
1429
1430
1431
# File '../../src/modules/Instserver.rb', line 1428

def Import(settings)
  settings = deep_copy(settings)
  true
end

- (Object) InstallFTPPackages



307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
# File '../../src/modules/Instserver.rb', line 307

def InstallFTPPackages
  help = _(
    "The FTP installation server requires an FTP server package. The vsftpd package\nwill now be installed.\n"
  )
  if !Package.InstalledAll(
      ["xinetd", "vsftpd", "openslp-server", "yast2-inetd"]
    )
    Builtins.y2milestone("some packages are not installed")
  else
    return true
  end

  if !Package.InstallAll(
      ["xinetd", "vsftpd", "openslp-server", "yast2-inetd"]
    )
    Report.Error(Message.CannotContinueWithoutPackagesInstalled)
    Builtins.y2error("Error while installing packages")
    return false
  end

  true
end

- (Object) InstallHTTPPackages



457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
# File '../../src/modules/Instserver.rb', line 457

def InstallHTTPPackages
  help = _(
    "The HTTP installation server requires an HTTP server package. The apache2 package\nwill now be installed."
  )
  if !Package.InstalledAll(["apache2", "openslp-server"])
    Builtins.y2debug("some packages are not installed")

    if !Package.InstallAll(["apache2", "apache2-prefork", "openslp-server"])
      Report.Error(Message.CannotContinueWithoutPackagesInstalled)

      Builtins.y2error("Error while installing packages")
      return false
    end
  end

  true
end

- (Object) Instserver

Constructor



1498
1499
1500
1501
1502
# File '../../src/modules/Instserver.rb', line 1498

def Instserver
  configSetup

  nil
end

- (Object) main



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
# File '../../src/modules/Instserver.rb', line 16

def main
  textdomain "instserver"

  Yast.import "Progress"
  Yast.import "Report"
  Yast.import "Summary"
  Yast.import "XML"
  Yast.import "Popup"
  Yast.import "Package"
  Yast.import "Call"
  Yast.import "Service"
  Yast.import "IP"
  Yast.import "Message"
  Yast.import "SuSEFirewall"
  Yast.import "String"

  Yast.include self, "instserver/routines.rb"


  # Is this a service pack?
  @is_service_pack = false

  @test = false

  # Configuration Map
  @Config = {}

  # All Configurations
  @Configs = {}

  # Server Configuration
  @ServerSettings = {}

  # Configuration Repository
  @Rep = "/etc/YaST2/instserver"

  # config file
  @ConfigFile = Ops.add(@Rep, "/instserver.xml")


  @FirstDialog = "summary"


  @products = []


  @Detected = []

  @standalone = false

  # renamed repositories: $["old" : "new"]
  @renamed = {}

  # Data was modified?
  @modified = false



  @to_delete = []

  # Abort function
  # return boolean return true if abort
  @AbortFunction = Modified()
  Instserver()
end

- (Object) Modified

Data was modified?

Returns:

  • true if modified



91
92
93
94
# File '../../src/modules/Instserver.rb', line 91

def Modified
  Builtins.y2debug("modified=%1", @modified)
  @modified
end

- (Boolean) MountBind(dir, ftproot)

Mount directory to avoid symlinks

Parameters:

  • string

    directory to bind

  • string

    bind to

Returns:

  • (Boolean)

    (true means that /etc/fstab has been modified)



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
# File '../../src/modules/Instserver.rb', line 240

def MountBind(dir, ftproot)
  Builtins.y2milestone("Calling MountBind with: %1 %2", dir, ftproot)
  fstab = Convert.convert(
    SCR.Read(path(".etc.fstab")),
    :from => "any",
    :to   => "list <map>"
  )
  Builtins.y2debug("fstab: %1", fstab)
  exists = Builtins.filter(fstab) do |f|
    Ops.get_string(f, "spec", "") == Builtins.deletechars(dir, " ")
  end
  Builtins.y2milestone("existing: %1", exists)
  if Ops.greater_than(Builtins.size(exists), 0)
    return false
  else
    SCR.Execute(path(".target.mkdir"), ftproot)
    Builtins.y2milestone("mounting %1 to %2", dir, ftproot)
    SCR.Execute(path(".target.mount"), [dir, ftproot], "--bind")

    bindfs = {}
    bindfs = {
      "file"    => ftproot,
      "spec"    => dir,
      "freq"    => 1,
      "mntops"  => "bind",
      "passno"  => 1,
      "vfstype" => "auto"
    }

    fstab = Builtins.add(fstab, bindfs)

    Builtins.y2milestone("added /etc/fstab entry: %1", bindfs)
    SCR.Write(path(".etc.fstab"), fstab)
  end
  true
end

- (Object) NFSExported(dir)



1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
# File '../../src/modules/Instserver.rb', line 1030

def NFSExported(dir)
  nfs_config = Convert.to_map(ReadServiceSettings("nfs_server_auto"))
  exports = Ops.get_list(nfs_config, "nfs_exports", [])

  ret = false

  Builtins.foreach(exports) do |e|
    ret = true if Ops.get_string(e, "mountpoint", "") == dir
  end 


  Builtins.y2milestone("Directory %1 is exported: %2", dir, ret)

  ret
end

- (Object) NFSValid(config)



1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
# File '../../src/modules/Instserver.rb', line 1046

def NFSValid(config)
  config = deep_copy(config)
  dir = Ops.get_string(config, "directory", "")

  if dir == nil || dir == ""
    Builtins.y2milestone("Empty or missing directory in the configuration")
    return false
  end

  # is the directory in /etc/exports?
  return false if !NFSExported(dir)

  nfsserver_running = Service.Status("nfsserver") == 0
  Builtins.y2milestone("NFS server running: %1", nfsserver_running)

  # is the nfsserver running?
  nfsserver_running
end

- (Object) Overview

Create an overview table with all configured data

Returns:

  • table items



1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
# File '../../src/modules/Instserver.rb', line 1481

def Overview
  Builtins.y2milestone("Configs: %1", @Configs)
  overview = Builtins.maplist(@Configs) do |name, cfg|
    Item(
      Id(name),
      name,
      Ops.add(
        Ops.add(Ops.get_string(cfg, "PRODUCT", ""), " "),
        Ops.get_string(cfg, "VERSION", "")
      )
    )
  end
  deep_copy(overview)
end

- (Array) PrepareConfigs

Prepare map for writing into XML

Returns:

  • (Array)

    s of configurations



1242
1243
1244
1245
# File '../../src/modules/Instserver.rb', line 1242

def PrepareConfigs
  c = Builtins.maplist(@Configs) { |k, v| v }
  deep_copy(c)
end

- (Object) Read

Read all instserver settings

Returns:

  • true on success



1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
# File '../../src/modules/Instserver.rb', line 1150

def Read
  # Instserver read dialog caption
  caption = _("Initializing Configuration")

  steps = 4

  sl = 1
  Builtins.sleep(sl)

  # We do not set help text here, because it was set outside
  Progress.New(
    caption,
    " ",
    steps,
    [
      # Progress stage 1/2
      _("Read configuration file"),
      # Progress stage 2/2
      _("Search for a new repository")
    ],
    [
      # Progress step 1/2
      _("Reading configuration file..."),
      # Progress step 2/2
      _("Searching for a new repository..."),
      # Progress finished
      _("Finished")
    ],
    ""
  )

  # read database
  return false if Abort()
  Progress.NextStage
  c = {}


  if SCR.Read(path(".target.size"), @ConfigFile) != -1
    c = XML.XMLToYCPFile(@ConfigFile)
  end
  all = Ops.get_list(c, "configurations", [])
  @ServerSettings = Ops.get_map(c, "servers", {})

  @Configs = Builtins.listmap(all) do |i|
    name = Ops.get_string(i, "name", "")
    { name => i }
  end
  Builtins.y2milestone("Configs: %1", @Configs)

  @ServerSettings = Ops.get_map(c, "servers", {})
  Builtins.y2milestone("Server config: %1", @ServerSettings)

  # check the server status here
  if @ServerSettings == {} || !ServiceValid(@ServerSettings)
    @FirstDialog = "settings"
  end

  # disable progress for firewall
  prg = Progress.set(false)
  # read firewall settings
  SuSEFirewall.Read
  Progress.set(prg)

  Builtins.sleep(sl)


  # read current settings
  return false if Abort()
  Progress.NextStage


  @Detected = DetectMedia()

  # Error message
  Report.Error(_("Cannot read current settings.")) if false
  Builtins.sleep(sl)


  return false if Abort()
  # Progress finished
  Progress.NextStage
  Builtins.sleep(sl)

  return false if Abort()
  @modified = false
  true
end

- (Object) ReadServiceSettings(module_auto)

Read service data using _auto



294
295
296
297
298
299
300
301
302
303
304
305
# File '../../src/modules/Instserver.rb', line 294

def ReadServiceSettings(module_auto)
  r = Convert.to_boolean(Call.Function(module_auto, ["Read"]))
  ret = Call.Function(module_auto, ["Export"])

  Builtins.y2milestone(
    "Current configuration of service %1: %2",
    module_auto,
    ret
  )

  deep_copy(ret)
end

- (void) RunSuseConfigApache(enable)

This method returns an undefined value.

Write Apache config

Parameters:

  • string

    state : Yes/No



433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
# File '../../src/modules/Instserver.rb', line 433

def RunSuseConfigApache(enable)
  flags = Convert.to_string(
    SCR.Read(path(".sysconfig.apache2.APACHE_SERVER_FLAGS"))
  )
  if !Builtins.issubstring(flags, "inst_server") && enable
    SCR.Write(
      path(".sysconfig.apache2.APACHE_SERVER_FLAGS"),
      Ops.add(flags, " inst_server")
    )
  elsif Builtins.issubstring(flags, "inst_server") && !enable
    SCR.Write(
      path(".sysconfig.apache2.APACHE_SERVER_FLAGS"),
      Builtins.regexpsub(flags, "(.*)inst_server(.*)", "")
    )
  end

  if !SCR.Write(path(".sysconfig.apache2"), nil)
    Popup.Error(_("Unable to write /etc/sysconfig/apache2"))
    return
  end

  nil
end

- (Object) ServiceValid(config)



1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
# File '../../src/modules/Instserver.rb', line 1128

def ServiceValid(config)
  config = deep_copy(config)
  service = Ops.get_symbol(config, "service", :unknown)

  if service == :nfs
    return NFSValid(config)
  elsif service == :ftp
    return FTPValid(config)
  elsif service == :http
    return HTTPValid(config)
  end

  Builtins.y2warning(
    "Unknown service type %1, cannot check configuration",
    service
  )

  false
end

- (Boolean) SetupFTP(dir, ftproot, ftpalias)

Setup FTP server

Parameters:

  • string

    inst server root

  • string

    ftp server root

Returns:

  • (Boolean)


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
# File '../../src/modules/Instserver.rb', line 334

def SetupFTP(dir, ftproot, ftpalias)
  return false if !InstallFTPPackages()

  # create repository directory if it doesn't exist
  SCR.Execute(
    path(".target.bash"),
    Builtins.sformat("[ -d %1 ] || /bin/mkdir %1", dir)
  )

  if !Builtins.issubstring(dir, ftproot)
    if ftpalias != ""
      a = ""
      a = Ops.add(Ops.add(ftproot, "/"), ftpalias)
      SCR.Execute(path(".target.bash"), Ops.add("mkdir -p ", a))
      ftproot = a
    end
    Builtins.y2milestone("binding dir")
    MountBind(dir, ftproot)
  else
    # FIXME
    Builtins.y2warning("not implemented")
  end

  # check if vsftpd is configured in standalone mode (listen=YES) (bnc#438694)
  # see 'man vsftpd.conf'
  vsftpd_standalone = vsftpd_is_standalone

  if vsftpd_standalone
    Builtins.y2milestone("Configuring FTP service in standalone mode")

    # enable/start the service
    Service.Enable("vsftpd")
    if Service.Status("vsftpd") == 0
      Service.Reload("vsftpd")
    else
      Service.Start("vsftpd")
    end
  else
    Builtins.y2milestone("Configuring FTP service in xinetd mode")
    # read the current configuration
    resource = Convert.to_map(ReadServiceSettings("inetd_auto"))
    netdconf = []

    # replace vsftpd config
    ftpdenabled = false
    servicefound = false
    Builtins.foreach(Ops.get_list(resource, "netd_conf", [])) do |conf|
      # the service is ftp with vsftpd server
      if Ops.get_string(conf, "service", "") == "ftp" &&
          Ops.get_string(conf, "script", "") == "vsftpd"
        servicefound = true

        # enable disabled service
        if Ops.get_boolean(conf, "enabled", false) != true
          Ops.set(conf, "enabled", true)
        else
          ftpdenabled = true
        end
      end
      # add the configuration to the list
      netdconf = Builtins.add(netdconf, conf)
    end 


    if servicefound == false
      # the FTP service config was not found, add it
      vsftpdconf = {
        "protocol" => "tcp",
        "script"   => "vsftpd",
        "server"   => "/usr/sbin/vsftpd",
        "service"  => "ftp"
      }
      netdconf = Builtins.add(netdconf, vsftpdconf)
    end

    # ftp service was not enabled/configured
    if ftpdenabled == false
      # update the configuration
      Ops.set(resource, "netd_conf", netdconf)

      # write the configuration
      ConfigureService("inetd_auto", resource)
    end

    # enable/start the service
    Service.Enable("xinetd")
    if Service.Status("xinetd") == 0
      Service.Reload("xinetd")
    else
      Service.Start("xinetd")
    end
  end

  true
end

- (Boolean) SetupHTTP(dir, _alias)

Setup HTTP server

Parameters:

  • string

    inst server root

  • alias (String)

Returns:

  • (Boolean)


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
# File '../../src/modules/Instserver.rb', line 479

def SetupHTTP(dir, _alias)
  return false if !InstallHTTPPackages()

  if Ops.greater_than(
      Convert.to_integer(
        SCR.Read(
          path(".target.size"),
          "/etc/apache2/conf.d/inst_server.conf.in"
        )
      ),
      0
    )
    conf = Convert.to_string(
      SCR.Read(
        path(".target.string"),
        "/etc/apache2/conf.d/inst_server.conf.in"
      )
    )
    confline = Builtins.splitstring(conf, "\n")

    _alias = Ops.add("/", _alias) if Builtins.findfirstof(_alias, "/") != 0
    confline = Builtins.maplist(confline) do |line|
      res = Builtins.regexpsub(
        line,
        "(.*)@ALIAS@(.*)",
        Builtins.sformat("\\1%1/\\2", _alias)
      )
      res = Builtins.regexpsub(
        res != nil ? Convert.to_string(res) : line,
        "(.*)@SERVERDIR@(.*)",
        Builtins.sformat("\\1%1/\\2", dir)
      )
      if res != nil
        next Convert.to_string(res)
      else
        next line
      end
    end

    Builtins.y2debug("conf: %1", confline)

    conf = Builtins.mergestring(confline, "\n")
    if !SCR.Write(
        path(".target.string"),
        "/etc/apache2/conf.d/inst_server.conf",
        conf
      )
      Builtins.y2error("Error writing apache2 config file")
    end
  else
    Builtins.y2error(
      "/etc/apache2/conf.d/inst_server.conf.in does not exist"
    )
    return false
  end
  RunSuseConfigApache(true)

  # write firewall config if it has been modified
  SuSEFirewall.Write if SuSEFirewall.GetModified

  Service.Enable("apache2")
  if Service.Status("apache2") == 0
    Service.Reload("apache2")
  else
    Service.Start("apache2")
  end
  true
end

- (Boolean) SetupNFS(dir, options)

Setup NFS Server

Parameters:

  • string

    directory

  • options (String)

Returns:

  • (Boolean)


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
# File '../../src/modules/Instserver.rb', line 553

def SetupNFS(dir, options)
  if !Package.InstallAll(["yast2-nfs-server"])
    Report.Error(Message.CannotContinueWithoutPackagesInstalled)

    Builtins.y2error("Error while installing packages")
    return false
  end

  resource = Convert.to_map(ReadServiceSettings("nfs_server_auto"))
  oldexp = Ops.get_list(resource, "nfs_exports", [])
  Builtins.y2milestone("oldexp: %1", oldexp)

  oldexists = Builtins.filter(oldexp) do |e|
    Ops.get_string(e, "mountpoint", "") == dir
  end
  if Ops.greater_than(Builtins.size(oldexists), 0)
    yesno = Popup.YesNo(
      _(
        "Directory is already exported via NFS.\nLeave NFS exports unmodified?\n"
      )
    )
    if yesno
      return true
    else
      oldexp = Builtins.filter(oldexp) do |e|
        Ops.get_string(e, "mountpoint", "") != dir
      end
    end
  end
  exports = deep_copy(oldexp)
  nfs = {}
  Ops.set(nfs, "start_nfsserver", true)
  allowed = []
  if Builtins.size(options) == 0
    options = "*(ro,root_squash,sync,no_subtree_check)"
  end
  allowed = Builtins.add(allowed, options)
  ex = {}
  Ops.set(ex, "allowed", allowed)
  Ops.set(ex, "mountpoint", dir)
  exports = Builtins.add(exports, ex)
  Ops.set(nfs, "nfs_exports", exports)

  ConfigureService("nfs_server_auto", nfs)

  Service.Enable("nfsserver")
  if Service.Status("nfsserver") == 0
    Service.Reload("nfsserver")
  else
    Service.Start("nfsserver")
  end

  # write firewall config if it has been modified
  SuSEFirewall.Write if SuSEFirewall.GetModified

  true
end

- (Boolean) SLPRegFile(service, attr, regfile)

Register service with SLP using a reg file

Parameters:

  • service (String)

    The service to be registered

  • attr (Hash{String => String})

    Attributes

  • regfile (String)

    Reg File

Returns:

  • (Boolean)

    True on Success



790
791
792
793
794
795
796
797
# File '../../src/modules/Instserver.rb', line 790

def SLPRegFile(service, attr, regfile)

  slp = [service] + attr.map { |k, v| k.downcase + "=" + v }

  regd_path = "/etc/slp.reg.d"
  SCR.Execute(path(".target.mkdir"), regd_path)
  SCR.Write(path(".target.string"), "#{regd_path}/#{regfile}", slp.join("\n"))
end

- (Object) subreplace(text, _in, out)



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
# File '../../src/modules/Instserver.rb', line 644

def subreplace(text, _in, out)
  parts = Builtins.splitstring(text, "\\")

  # don't modify the first item, it's the non-matched prefix
  first = true
  new_parts = Builtins.maplist(parts) do |p|
    if first
      first = false
      next p
    end
    new_part = p
    if _in == Builtins.substring(p, 0, 2)
      new_part = Ops.add(out, Builtins.substring(p, 2))
    else
      # put the backslash back if the remaining part doesn't match
      new_part = Ops.add("\\", p)
    end
    new_part
  end

  ret = Builtins.mergestring(new_parts, "")
  Builtins.y2debug(
    "unescaped str: text: %1, in: %2, out: %3 => %4",
    text,
    _in,
    out,
    ret
  )

  ret
end

- (Object) Summary

Create a textual summary and a list of unconfigured cards

Returns:

  • summary of the current configuration



1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
# File '../../src/modules/Instserver.rb', line 1445

def Summary
  # Configuration summary text for autoyast
  sum = ""
  _Available = Builtins.filter(FindAvailable()) do |d, avail|
    !Builtins.haskey(@Configs, basename(d))
  end
  unconf = Builtins.maplist(_Available) do |d, avail|
    dir = basename(d)
    Item(
      Id(dir),
      Ops.add(
        Ops.add(
          Ops.add(Ops.get_string(avail, "LABEL", ""), "("),
          Ops.get_string(avail, "DEFAULTBASE", "")
        ),
        ")"
      )
    )
  end

  sum = Summary.AddHeader(sum, _("Configured Repositories"))
  sum = Summary.OpenList(sum)

  Builtins.foreach(@Configs) do |name, cfg|
    source = Ops.add(
      Ops.add(Ops.get_string(cfg, "LABEL", ""), "<br><b>Architecture: </b>"),
      Ops.get_string(cfg, "DEFAULTBASE", "")
    )
    sum = Summary.AddListItem(sum, source)
  end
  sum = Summary.CloseList(sum)
  [sum, unconf]
end

- (Object) UnEscapeSLPData(a)

this is an oppsite function to EscapeSLPData() it takes SLP input and unescpaes the backslash sequences



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
# File '../../src/modules/Instserver.rb', line 678

def UnEscapeSLPData(a)
  a = deep_copy(a)
  ret = {}

  Builtins.foreach(a) do |key, value|
    # String::Replace() enters endless loop in '\' -> '\5c' conversion
    # use splitstring() and mergestring() builtins instead
    new_key = key
    new_key = subreplace(new_key, "2e", ".")
    new_key = subreplace(new_key, "3d", "=")
    new_key = subreplace(new_key, "23", "#")
    new_key = subreplace(new_key, "3b", ";")
    new_key = subreplace(new_key, "5c", "\\")
    new_value = value
    new_value = subreplace(new_value, "28", "(")
    new_value = subreplace(new_value, "29", ")")
    new_value = subreplace(new_value, "2c", ",")
    new_value = subreplace(new_value, "23", "#")
    new_value = subreplace(new_value, "3b", ";")
    new_value = subreplace(new_value, "5c", "\\")
    Ops.set(ret, new_key, new_value)
  end 


  Builtins.y2milestone("Unescaped SLP attributes: %1 -> %2", a, ret)

  deep_copy(ret)
end

- (Object) UpdateConfig



1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
# File '../../src/modules/Instserver.rb', line 1387

def UpdateConfig
  Builtins.y2debug("current config: %1", @Configs)

  name = Ops.get_string(@Config, "name", "")
  old_name = Ops.get_string(@Config, "old_name", "")

  # remove the old config
  if Builtins.haskey(@Configs, old_name) && old_name != ""
    @Configs = Builtins.filter(@Configs) { |k, v| k != old_name }
    Builtins.remove(@Config, "old_name")
  end

  if name != ""
    # update the config
    Ops.set(@Configs, name, @Config)
  end

  Builtins.y2debug("current config: %1", @Configs)
  nil
end

- (Object) vsftpd_is_standalone



97
98
99
100
101
102
103
104
105
# File '../../src/modules/Instserver.rb', line 97

def vsftpd_is_standalone
  ret = SCR.Execute(
    path(".target.bash"),
    "grep -q '^listen=YES$' /etc/vsftpd.conf"
  ) == 0

  Builtins.y2milestone("vsftpd in standalone mode: %1", ret)
  ret
end

- (Object) Write

Write all instserver settings

Returns:

  • true on success



1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
# File '../../src/modules/Instserver.rb', line 1250

def Write
  Builtins.y2debug("Instserver::Write() called")

  # Instserver read dialog caption
  caption = _("Saving Installation Server Configuration")

  steps = 2

  sl = 1
  Builtins.sleep(sl)

  # We do not set help text here, because it was set outside
  Progress.New(
    caption,
    " ",
    steps,
    [
      # Progress stage 1/2
      _("Write the settings"),
      # Progress stage 2/2
      _("Run SuSEconfig")
    ],
    [
      # Progress step 1/2
      _("Writing the settings..."),
      # Progress step 2/2
      _("Running SuSEconfig..."),
      # Progress finished
      _("Finished")
    ],
    ""
  )

  # write settings
  return false if Abort()
  Progress.NextStage

  c = PrepareConfigs()
  xml = { "configurations" => c, "servers" => @ServerSettings }
  ret = XML.YCPToXMLFile(:instserver, xml, @ConfigFile)

  # Error message
  Report.Error(_("Cannot write settings.")) if false
  Builtins.sleep(sl)

  # run SuSEconfig
  return false if Abort()
  Progress.NextStage

  slpreload = false

  regs_delete = deep_copy(@to_delete)

  # remove the deleted repositories
  Builtins.foreach(regs_delete) do |c2|
    dir = Ops.add(
      Ops.add(Ops.get_string(@ServerSettings, "directory", ""), "/"),
      c2
    )
    Builtins.y2milestone("removing directory: %1", dir)
    rm = Ops.add("rm -rf ", dir)
    SCR.Execute(path(".target.bash"), rm)
  end

  # add disabled SLP repositories
  Builtins.foreach(@Configs) do |confname, conf|
    if Ops.get_boolean(conf, "slp", true) == false
      regs_delete = Builtins.add(
        regs_delete,
        Ops.get_string(conf, "name", "")
      )
    end
  end 


  # Remove the SLP files of removed or SLP disabled repositories
  Builtins.foreach(regs_delete) do |c2|
    regfile = Builtins.sformat("/etc/slp.reg.d/YaST-%1.reg", c2)
    if Ops.greater_than(SCR.Read(path(".target.size"), regfile), 0)
      slpreload = true
      SCR.Execute(path(".target.remove"), regfile)
    end
  end

  # Write all SLP files
  Builtins.foreach(@Configs) do |cn, cm|
    if Ops.get_boolean(cm, "slp", false)
      regfile = Builtins.sformat(
        "/etc/slp.reg.d/YaST-%1.reg",
        Ops.get_string(cm, "name", "")
      )
      WriteSLPReg(cm)
      slpreload = true
    end
  end

  # move content of the renamed repositories
  Builtins.foreach(@renamed) do |orig, new|
    # remove old reg file
    old_regfile = Builtins.sformat("/etc/slp.reg.d/YaST-%1.reg", orig)
    Builtins.y2milestone("removing old reg file: %1", old_regfile)
    SCR.Execute(path(".target.bash"), Ops.add("rm -f ", old_regfile))
    # rename the directory
    cmd = Builtins.sformat(
      "mv %1/%2 %1/%3",
      Ops.get_string(@ServerSettings, "directory", ""),
      orig,
      new
    )
    Builtins.y2milestone("moving directory: %1", cmd)
    if SCR.Execute(path(".target.bash"), cmd) != 0
      Popup.Error(_("Error while moving repository content."))
      next
    end
  end 



  # slp service reload is required - the configuration has been changed
  if slpreload
    if Service.Status("slpd") == 0
      Service.Restart("slpd")
    else
      Service.Start("slpd")
    end
  end

  return false if Abort()
  # Progress finished
  Progress.NextStage
  Builtins.sleep(sl)

  return false if Abort()
  true
end

- (Object) WriteSLPReg(cm)

Write SLP configuration



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
# File '../../src/modules/Instserver.rb', line 800

def WriteSLPReg(cm)
  cm = deep_copy(cm)
  Builtins.y2debug("WriteSLPReg(%1)", cm)

  ip = GetIPAddr()
  hostname = GetHostname()
  serv = ""
  regfile = Builtins.sformat("YaST-%1.reg", Ops.get_string(cm, "name", ""))
  if Ops.get_symbol(@ServerSettings, "service", :none) == :nfs
    serv = Builtins.sformat(
      "service:install.suse:nfs://%1/%2/%3%4,en,65535",
      ip,
      Ops.get_string(@ServerSettings, "directory", ""),
      Ops.get_string(cm, "name", ""),
      "/CD1"
    )
  elsif Ops.get_symbol(@ServerSettings, "service", :none) == :ftp
    serv = Builtins.sformat(
      "service:install.suse:ftp://%1/%2%3,en,65535",
      ip,
      Ops.get_string(cm, "name", ""),
      "/CD1"
    )
  elsif Ops.get_symbol(@ServerSettings, "service", :none) == :http
    serv = Builtins.sformat(
      "service:install.suse:http://%1/%2/%3%4,en,65535",
      ip,
      Ops.get_string(@ServerSettings, "alias", ""),
      Ops.get_string(cm, "name", ""),
      "/CD1"
    )
  end

  attr = {}
  Builtins.foreach(
    [
      "LABEL",
      "VERSION",
      "VENDOR",
      "DEFAULTBASE",
      "BASEPRODUCT",
      "BASEVERSION"
    ]
  ) do |a|
    if Ops.get_string(cm, a, "") != ""
      Ops.set(attr, Builtins.tolower(a), Ops.get_string(cm, a, ""))
    end
  end

  # Check if the description is already used
  # don't check file which will be rewritten
  #    string checkfiles = "/etc/slp.reg.d/YaST-*.reg";
  targetfile = Ops.add("/etc/slp.reg.d/", regfile)

  hostname_reg = ""
  # add the hostname
  if hostname != nil && hostname != "" && Builtins.haskey(attr, "label")
    hostname_reg = Ops.add(hostname, ": ")
  end

  descr = Ops.add(hostname_reg, Ops.get_string(cm, "LABEL", ""))
  if Ops.get_string(cm, "DISTPRODUCT", "") != ""
    descr = Ops.add(
      descr,
      Builtins.sformat(" [%2]", Ops.get_string(cm, "DISTPRODUCT", ""))
    )
  end

  Ops.set(attr, "description", descr)

  read_file = targetfile

  Builtins.foreach(@renamed) do |orig, new|
    if new == Ops.get_string(cm, "name", "")
      Builtins.y2milestone("Config renamed from %1 to %2", orig, new)

      read_file = Ops.add(
        "/etc/slp.reg.d/",
        Builtins.sformat("YaST-%1.reg", orig)
      )
    end
  end 


  machine = ""
  machines = []
  Builtins.foreach(cm) do |k, v|
    Builtins.y2debug("Read Key: '%1'", k)
    if k == "BASEARCHS"
      # machine mapping
      machines = get_machines(Convert.to_string(v))
    elsif Builtins.issubstring(k, "ARCH")
      a = Builtins.regexpsub(k, "ARCH\\.(.*)", "\\1")

      if a != nil
        Builtins.y2milestone(
          "Found %1 key, adding arch %2 to the list",
          k,
          a
        )
        machines = Builtins.add(machines, a)
      end
    end
  end
  machines = Builtins.filter(machines) { |m| m != "" && m != "noarch" }
  machines = Builtins.toset(machines)

  # sort the list so it looks better
  machines = Builtins.sort(machines)
  machines_string = Builtins.mergestring(machines, ",")

  Builtins.y2debug("machines: %1", machines)

  # preserve the old configuration
  if Ops.greater_or_equal(SCR.Read(path(".target.size"), read_file), 0)
    Builtins.y2milestone("Existing reg.d file found: %1", read_file)
    old_attr = {}

    reg_cont = Convert.to_string(
      SCR.Read(path(".target.string"), read_file)
    )
    lines = Builtins.splitstring(reg_cont, "\n")

    Builtins.foreach(lines) do |l|
      parsed_name = Builtins.regexpsub(
        l,
        "^[ \t]*([^ \t]*)[ \t]*=(.*)",
        "\\1"
      )
      parsed_value = Builtins.regexpsub(
        l,
        "^[ \t]*([^ \t]*)[ \t]*=(.*)",
        "\\2"
      )
      if parsed_name != nil
        Builtins.y2milestone(
          "Reusing attribute: %1=%2",
          parsed_name,
          parsed_value
        )
        Ops.set(old_attr, parsed_name, parsed_value)
      end
    end 


    # unescape the read value
    old_attr = UnEscapeSLPData(old_attr)

    if Builtins.haskey(old_attr, "machine")
      # backup the "machine" value
      machines_string = Ops.get(old_attr, "machine", "")
    end

    # merge them with read values,
    # keep the original setting if a value was already set
    attr = Convert.convert(
      Builtins.union(attr, old_attr),
      :from => "map",
      :to   => "map <string, string>"
    ) 

    # TODO: checking?
    # 	// don't check the overwritten config file
    # 	// get names of all config files except the rewritten one
    # 	map lsout = (map)SCR::Execute(.target.bash_output, "/bin/ls /etc/slp.reg.d/* | grep -v /etc/slp.reg.d/YaST-sles9.reg");
    # 	if (lsout["exit"]:-1 == 0)
    # 	{
    # 	    // merge the output into single line
    # 	    checkfiles = mergestring(splitstring(lsout["stdout"]:"", "\n"), " ");
    # 	    y2debug("files to check: %1", checkfiles);
    # 	}
  end

  # escape invalid characters
  attr = EscapeSLPData(attr)

  # replace the machine option after escaping,
  # it actually _is_ a list so "," is valid here
  Ops.set(attr, "machine", machines_string)
  Builtins.y2milestone("machine: %1", Ops.get(attr, "machine", ""))

  Builtins.y2milestone(
    "registering SLP service: serv: %1, attr: %2, regfile: %3",
    serv,
    attr,
    regfile
  )

  ret = SLPRegFile(serv, attr, regfile)

  ret
end