Class: Yast::SaveConfigFinishClient

Inherits:
Client
  • Object
show all
Includes:
Logger
Defined in:
src/lib/installation/clients/save_config_finish.rb

Instance Method Summary collapse

Instance Method Details

#mainObject



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
# File 'src/lib/installation/clients/save_config_finish.rb', line 38

def main
  textdomain "installation"

  Yast.import "Directory"
  Yast.import "Mode"
  Yast.import "Timezone"
  Yast.import "Language"
  Yast.import "Keyboard"
  Yast.import "ProductFeatures"
  Yast.import "AutoInstall"
  Yast.import "Console"
  Yast.import "Product"
  Yast.import "Progress"
  Yast.import "SignatureCheckDialogs"
  Yast.import "Stage"
  Yast.import "AddOnProduct"
  Yast.import "FileUtils"
  Yast.import "Installation"
  Yast.import "String"

  @ret = nil
  @func = ""
  @param = {}

  # Check arguments
  if Ops.greater_than(Builtins.size(WFM.Args), 0) &&
      Ops.is_string?(WFM.Args(0))
    @func = Convert.to_string(WFM.Args(0))
    if Ops.greater_than(Builtins.size(WFM.Args), 1) &&
        Ops.is_map?(WFM.Args(1))
      @param = Convert.to_map(WFM.Args(1))
    end
  end

  Builtins.y2milestone("starting save_config_finish")
  Builtins.y2debug("func=%1", @func)
  Builtins.y2debug("param=%1", @param)

  minimal_inst = ::Installation::MinimalInstallation.instance.enabled?

  case @func
  when "Info"
    if Mode.autoinst
      steps = minimal_inst ? 3 : 6
    elsif Mode.update
      steps = minimal_inst ? 2 : 4
    elsif Mode.installation
      steps = minimal_inst ? 2 : 5
    else
      raise "Unknown mode"
    end
    return {
      "steps" => steps,
      "when"  => [:installation, :update, :autoinst]
    }
  when "Write"
    # Bugzilla #209119
    # ProductFeatures::Save() moved here from inst_kickoff.ycp
    # (After the SCR is switched)
    if Stage.initial
      Builtins.y2milestone("Saving ProductFeatures...")
      SCR.Execute(path(".target.bash"), "/bin/mkdir -p '/etc/YaST2'")
      SCR.Execute(
        path(".target.bash"),
        "touch '/etc/YaST2/ProductFeatures'"
      )
      ProductFeatures.Save
    end

    # Bugzilla #187558
    # Save Add-On products configuration
    # to be able to restore the settings
    @save_to = AddOnProduct.TmpExportFilename
    SCR.Execute(path(".target.remove"), @save_to) if FileUtils.Exists(@save_to)
    if Stage.initial
      Builtins.y2milestone("Saving Add-On configuration...")
      @exported_add_ons = AddOnProduct.Export
      if @exported_add_ons.nil?
        Builtins.y2error("Error, Add-Ons returned 'nil'")
      else
        @saved = SCR.Write(path(".target.ycp"), @save_to, @exported_add_ons)
        if @saved
          Builtins.y2milestone("Add-Ons configuration saved successfuly")
        else
          Builtins.y2error(
            "Error occurred when storing Add-Ons configuration!"
          )
        end
      end
    end

    if !Mode.update && !minimal_inst
      # progress step title
      Progress.Title(_("Saving time zone..."))
      # clock must be set correctly in new chroot
      Timezone.Set(Timezone.timezone, true)
      Timezone.Save
    end

    Progress.NextStep
    # save keyboard settings (via systemd-firstboot) before setting console
    # otherwise they are not written (bsc#1076798)
    if !minimal_inst
      # progress step title
      Progress.Title(_("Saving keyboard configuration..."))
      Keyboard.Save
      Progress.NextStep
    end
    if !Mode.update && !minimal_inst
      # progress step title
      Progress.Title(_("Saving language..."))
      Language.Save
      Progress.NextStep

      # progress step title
      Progress.Title(_("Saving console configuration..."))
      Console.Save
      Progress.NextStep
    elsif Mode.update
      @lang = Language.language
      @file = Ops.add(Directory.vardir, "/language.ycp")
      Builtins.y2milestone(
        "saving %1 to %2 for 2nd stage of update",
        @lang,
        @file
      )
      SCR.Write(
        path(".target.ycp"),
        @file,
        "second_stage_language" => @lang
      )
    end
    # progress step title
    Progress.Title(_("Saving product information..."))
    ProductFeatures.Save
    if Mode.autoinst || Mode.autoupgrade
      Progress.NextStep
      # progress step title
      Progress.Title(_("Saving automatic installation settings..."))
      AutoInstall.Save
    end
    Progress.NextStep
    # save supportconfig
    if Ops.greater_than(
      SCR.Read(path(".target.size"), "/etc/install.inf"),
      0
    )
      @url = Convert.to_string(
        SCR.Read(path(".etc.install_inf.supporturl"))
      )
      Builtins.y2milestone("URL value from /etc/install.inf : %1", @url)
      if !@url.nil? && Ops.greater_than(Builtins.size(@url), 0)
        @config_path = Builtins.sformat(
          "%1%2",
          String.Quote(Installation.destdir),
          "/etc/supportconfig.conf"
        )
        Builtins.y2milestone(
          "URL from install.inf readed, test if %1 exists",
          @config_path
        )
        if FileUtils.Exists(@config_path)
          Builtins.y2milestone(
            "Insert value into supportconfig.conf: %1",
            @url
          )
          SCR.Execute(
            path(".target.bash_output"),
            Builtins.sformat(
              "sed -i '/VAR_OPTION_UPLOAD_TARGET=.*/d;/^$/d' %1",
              @config_path
            )
          )
          SCR.Execute(
            path(".target.bash_output"),
            Builtins.sformat(
              "echo \"VAR_OPTION_UPLOAD_TARGET='%1'\">> %2",
              @url,
              @config_path
            )
          )
        else
          Builtins.y2error("filename %1 was not found", @config_path)
        end
      end
    else
      Builtins.y2warning("/etc/install.inf not found")
    end
  else
    Builtins.y2error("unknown function: %1", @func)
    @ret = nil
  end

  Builtins.y2debug("ret=%1", @ret)
  Builtins.y2milestone("save_config_finish finished")
  deep_copy(@ret)
end