Class: Yast::LinuxrcClass

Inherits:
Module
  • Object
show all
Includes:
Logger
Defined in:
library/general/src/modules/Linuxrc.rb

Constant Summary collapse

DISABLE_SNAPSHOTS =

Disables filesystem snapshots (fate#317973) Possible values: all, post, pre, single

"disable_snapshots".freeze

Instance Method Summary collapse

Instance Method Details

#brailleObject

braille mode ?



113
114
115
# File 'library/general/src/modules/Linuxrc.rb', line 113

def braille
  !InstallInf("Braille").nil?
end

#disable_remote(services) ⇒ Object

Reset settings for vnc, ssh,… in install.inf which have been made by linuxrc settings.

Parameters:

  • list (Array<String>)

    of remote-management services that will be disabled.



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
# File 'library/general/src/modules/Linuxrc.rb', line 248

def disable_remote(services)
  return if !services || services.empty?

  log.warn "Disabling #{services} due to missing packages."
  services.each do |service|
    # Service IDs are also used in another context in the code
    # Making sure we always compare apples with apples
    case polish(service.dup)

    when "vnc"
      SCR.Write(path(".etc.install_inf.VNC"), 0)
      SCR.Write(path(".etc.install_inf.VNCPassword"), "")
    when "ssh"
      SCR.Write(path(".etc.install_inf.UseSSH"), 0)
    when "braille"
      SCR.Write(path(".etc.install_inf.Braille"), 0)
    when "displayip"
      SCR.Write(path(".etc.install_inf.DISPLAY_IP"), 0)
    else
      log.error "Unknown service #{service}"
      raise ArgumentError, "Cannot disable #{service}: Unknown service."
    end
  end
  SCR.Write(path(".etc.install_inf"), nil) # Flush the cache
  ResetInstallInf()
end

#display_ipObject

remote X mode ?



123
124
125
# File 'library/general/src/modules/Linuxrc.rb', line 123

def display_ip
  !InstallInf("Display_IP").nil?
end

#InstallInf(key) ⇒ Object



80
81
82
83
# File 'library/general/src/modules/Linuxrc.rb', line 80

def InstallInf(key)
  ReadInstallInf()
  @install_inf[key]
end

#keysObject



85
86
87
88
# File 'library/general/src/modules/Linuxrc.rb', line 85

def keys
  ReadInstallInf()
  @install_inf.keys
end

#mainObject



40
41
42
43
44
45
46
47
# File 'library/general/src/modules/Linuxrc.rb', line 40

def main
  Yast.import "Mode"
  Yast.import "Stage"

  @install_inf = nil

  @_manual = nil
end

#manualObject

installation mode wrappers



92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'library/general/src/modules/Linuxrc.rb', line 92

def manual
  return @_manual if !@_manual.nil?
  @_manual = InstallInf("Manual") == "1"
  if !@_manual
    tmp = Convert.to_string(
      SCR.Read(path(".target.string"), "/proc/cmdline")
    )
    if !tmp.nil? &&
        Builtins.contains(Builtins.splitstring(tmp, " \n"), "manual")
      @_manual = true
    end
  end
  @_manual
end

#ReadInstallInfObject

routines for reading data from /etc/install.inf



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'library/general/src/modules/Linuxrc.rb', line 51

def ReadInstallInf
  return if !@install_inf.nil?

  @install_inf = {}
  # don't read anything if the file doesn't exist
  if SCR.Read(path(".target.size"), "/etc/install.inf") == -1
    Builtins.y2error("Reading install.inf, but file doesn't exist!!!")
    return
  end
  entries = SCR.Dir(path(".etc.install_inf"))
  if entries.nil?
    Builtins.y2error("install.inf is empty")
    return
  end
  Builtins.foreach(entries) do |e|
    val = Convert.to_string(
      SCR.Read(Builtins.add(path(".etc.install_inf"), e))
    )
    Ops.set(@install_inf, e, val)
  end

  nil
end

#ResetInstallInfObject



75
76
77
78
# File 'library/general/src/modules/Linuxrc.rb', line 75

def ResetInstallInf
  @install_inf = nil
  nil
end

#SaveInstallInf(root) ⇒ Object

Copy /etc/install.inf into built system so that the second phase of the installation can find it.

Parameters:

  • root

    mount point of system

Returns:

  • boolean true on success



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
# File 'library/general/src/modules/Linuxrc.rb', line 169

def SaveInstallInf(root)
  if Stage.initial && !Mode.test
    inst_if_file = "/etc/install.inf"

    if !root.nil? && root != "" && root != "/"
      if WFM.Read(path(".local.size"), inst_if_file) != -1
        Builtins.y2milestone("Copying %1 to %2", inst_if_file, root)
        if Convert.to_integer(
          WFM.Execute(
            path(".local.bash"),
            Builtins.sformat(
              "grep -vi '^Sourcemounted' '%1' > %2/%1; chmod 0600 %2/%1",
              inst_if_file,
              root
            )
          )
        ) != 0
          Builtins.y2error(
            "Cannot SaveInstallInf %1 to %2",
            inst_if_file,
            root
          )
        end
      else
        Builtins.y2error(
          "Can't SaveInstallInf, file %1 doesn't exist",
          inst_if_file
        )
      end
    else
      Builtins.y2error("Can't SaveInstallInf, root is %1", root)
    end

    # just for debug so we can see the original install.inf later
    SCR.Execute(
      path(".target.bash"),
      Ops.add(
        Ops.add("/bin/cp /etc/install.inf ", root),
        "/var/lib/YaST2/install.inf"
      )
    )
    SCR.Execute(
      path(".target.bash"),
      Ops.add(
        Ops.add("/bin/chmod 0600 ", root),
        "/var/lib/YaST2/install.inf"
      )
    )
  end
  true
end

#serial_consoleObject

running via serial console



108
109
110
# File 'library/general/src/modules/Linuxrc.rb', line 108

def serial_console
  !InstallInf("Console").nil?
end

#textObject

we're running in textmode (-> UI::GetDisplayInfo())



141
142
143
# File 'library/general/src/modules/Linuxrc.rb', line 141

def text
  InstallInf("Textmode") == "1"
end

#useiscsiObject

Returns if iSCSI has been requested in Linuxrc.



136
137
138
# File 'library/general/src/modules/Linuxrc.rb', line 136

def useiscsi
  InstallInf("WithiSCSI") == "1"
end

#usesshObject

ssh mode ? if booted with 'vnc=1 usessh=1', keep vnc mode, but start sshd if booted with 'display_ip=1.2.3.4 usessh=1', keep remote X mode, but start sshd this has to be checked by the caller, not here



131
132
133
# File 'library/general/src/modules/Linuxrc.rb', line 131

def usessh
  InstallInf("UseSSH") == "1"
end

#value_for(feature_key) ⇒ String?

Returns value of a given Linxurc key/feature defined on commandline and written into install.inf

Parameters:

Returns:

  • (String, nil)

    value of a given key or `nil` if not found



226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# File 'library/general/src/modules/Linuxrc.rb', line 226

def value_for(feature_key)
  ReadInstallInf()
  feature_key = polish(feature_key)

  # at first check the keys in install.inf
  install_inf_key, install_inf_val = @install_inf.find { |k, _v| polish(k) == feature_key }
  return install_inf_val if install_inf_key

  # then check the command line
  ret = nil
  @install_inf.fetch("Cmdline", "").split.each do |cmdline_entry|
    key, val = cmdline_entry.split("=", 2)
    ret = val if polish(key) == feature_key
  end

  ret
end

#vncObject

vnc mode ?



118
119
120
# File 'library/general/src/modules/Linuxrc.rb', line 118

def vnc
  InstallInf("VNC") == "1"
end

#WriteYaSTInf(linuxrc) ⇒ void

This method returns an undefined value.

Write /etc/yast.inf during installation

Parameters:

  • linuxrc (Hash{String => String})

    map of key value pairs for /etc/yast.inf



150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'library/general/src/modules/Linuxrc.rb', line 150

def WriteYaSTInf(linuxrc)
  linuxrc = deep_copy(linuxrc)
  yast_inf = ""
  Builtins.foreach(linuxrc) do |ykey, yvalue|
    yast_inf = Ops.add(
      Ops.add(Ops.add(Ops.add(yast_inf, ykey), ": "), yvalue),
      "\n"
    )
  end
  Builtins.y2milestone("WriteYaSTInf(%1) = %2", linuxrc, yast_inf)

  WFM.Write(path(".local.string"), "/etc/yast.inf", yast_inf) if !Mode.test
  nil
end