Class: Yast::InstKickoffClient

Inherits:
Client
  • Object
show all
Defined in:
src/clients/inst_kickoff.rb,
src/clients/inst_kickoff.rb

Overview

Do various tasks before starting with installation of rpms.

Instance Method Summary collapse

Instance Method Details

#backup_stuffObject

Handle the backup.


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
# File 'src/clients/inst_kickoff.rb', line 191

def backup_stuff
  if Installation.update_backup_modified
    Pkg.CreateBackups(true)
    Pkg.SetBackupPath(Installation.update_backup_path)
    SCR.Write(
      path(".target.string"),
      Ops.add(Installation.destdir, "/var/lib/YaST2/backup_path"),
      Installation.update_backup_path
    )
  else
    Pkg.CreateBackups(false)
    SCR.Execute(
      path(".target.remove"),
      Ops.add(Installation.destdir, "/var/lib/YaST2/backup_path")
    )
  end

  # Removing all old backups
  if Installation.update_remove_old_backups
    Builtins.y2milestone(
      "Removing old backups *-*-*.tar.{gz,bz2} from %1",
      Installation.update_backup_path
    )
    SCR.Execute(
      path(".target.bash"),
      Ops.add(
        Ops.add(
          Ops.add(
            Ops.add(
              Ops.add("cd '", String.Quote(Installation.destdir)),
              "'; "
            ),
            "/bin/rm -f "
          ),
          Installation.update_backup_path
        ),
        "/*-*-*.tar.{gz,bz2}"
      )
    )
  end

  # timestamp
  date = Builtins.timestring("%Y%m%d", ::Time.now.to_i, false)

  Builtins.y2milestone("Creating backup of %1", Directory.logdir)

  filename = ""
  num = 0

  while Ops.less_than(num, 42)
    filename = Ops.add(
      Ops.add(
        Ops.add(
          Ops.add(
            Ops.add(Installation.update_backup_path, "/YaST2-"),
            date
          ),
          "-"
        ),
        Builtins.sformat("%1", num)
      ),
      ".tar.gz"
    )
    if SCR.Read(
      path(".target.size"),
      Ops.add(Installation.destdir, filename)
    ) == -1
      break
    end
    num = Ops.add(num, 1)
  end

  if SCR.Execute(
    path(".target.bash"),
    Ops.add(
      Ops.add(
        Ops.add(
          Ops.add(
            Ops.add(
              Ops.add("cd '", String.Quote(Installation.destdir)),
              "'; "
            ),
            "/bin/tar czf ."
          ),
          filename
        ),
        " "
      ),
      "var/log/YaST2"
    )
  ).nonzero?
    Builtins.y2error(
      "backup of %1 to %2 failed",
      Directory.logdir,
      filename
    )
    # an error popup
    Popup.Error(
      Builtins.sformat(
        _("Backup of %1 failed. See %2 for details."),
        Directory.logdir,
        Ops.add(Directory.logdir, "/y2log")
      )
    )
  else
    SCR.Execute(
      path(".target.bash"),
      Ops.add(
        Ops.add(
          Ops.add("cd '", String.Quote(Installation.destdir)),
          "'; "
        ),
        "/bin/rm -rf var/log/YaST2/*"
      )
    )
  end

  if Installation.update_backup_sysconfig
    # backup /etc/sysconfig
    if Ops.greater_than(
      SCR.Read(
        path(".target.size"),
        Ops.add(Installation.destdir, "/etc/sysconfig")
      ),
      0
    )
      Builtins.y2milestone("backup of /etc/sysconfig")

      filename = ""
      num = 0

      while Ops.less_than(num, 42)
        filename = Ops.add(
          Ops.add(
            Ops.add(
              Ops.add(
                Ops.add(Installation.update_backup_path, "/etc.sysconfig-"),
                date
              ),
              "-"
            ),
            Builtins.sformat("%1", num)
          ),
          ".tar.gz"
        )
        if SCR.Read(
          path(".target.size"),
          Ops.add(Installation.destdir, filename)
        ) == -1
          break
        end
        num = Ops.add(num, 1)
      end

      if SCR.Execute(
        path(".target.bash"),
        Ops.add(
          Ops.add(
            Ops.add(
              Ops.add(
                Ops.add(
                  Ops.add("cd '", String.Quote(Installation.destdir)),
                  "'; "
                ),
                "/bin/tar czf ."
              ),
              filename
            ),
            " "
          ),
          "etc/sysconfig"
        )
      ).nonzero?
        Builtins.y2error(
          "backup of %1 to %2 failed",
          "/etc/sysconfig",
          filename
        )
        # an error popup
        Popup.Error(
          Builtins.sformat(
            _("Backup of %1 failed. See %2 for details."),
            "/etc/sysconfig",
            Ops.add(Directory.logdir, "/y2log")
          )
        )
      end
    # backup of /etc/rc.config*
    elsif Ops.greater_than(
      SCR.Read(
        path(".target.size"),
        Ops.add(Installation.destdir, "/etc/rc.config")
      ),
      0
    ) &&
        Ops.greater_than(
          SCR.Read(
            path(".target.size"),
            Ops.add(Installation.destdir, "/etc/rc.config.d")
          ),
          0
        )
      Builtins.y2milestone("backup of /etc/rc.config.d")

      filename = ""
      num = 0

      while Ops.less_than(num, 42)
        filename = Ops.add(
          Ops.add(
            Ops.add(
              Ops.add(
                Ops.add(Installation.update_backup_path, "/etc.rc.config-"),
                date
              ),
              "-"
            ),
            Builtins.sformat("%1", num)
          ),
          ".tar.gz"
        )
        if SCR.Read(
          path(".target.size"),
          Ops.add(Installation.destdir, filename)
        ) == -1
          break
        end
        num = Ops.add(num, 1)
      end

      if SCR.Execute(
        path(".target.bash"),
        Ops.add(
          Ops.add(
            Ops.add(
              Ops.add(
                Ops.add(
                  Ops.add("cd '", String.Quote(Installation.destdir)),
                  "'; "
                ),
                "/bin/tar czf ."
              ),
              filename
            ),
            " "
          ),
          "etc/rc.config etc/rc.config.d"
        )
      ).nonzero?
        Builtins.y2error(
          "backup of %1 to %2 failed",
          "/etc/rc.config",
          filename
        )
        # an error popup
        Popup.Error(
          Builtins.sformat(
            _("Backup of %1 failed. See %2 for details."),
            "/etc/rc.config",
            Ops.add(Directory.logdir, "/y2log")
          )
        )
      end
    end
  end

  # Backup /etc/pam.d/ unconditionally
  # bnc #393066
  if Mode.update
    filename = ""
    num = 0

    while Ops.less_than(num, 42)
      filename = Ops.add(
        Ops.add(
          Ops.add(
            Ops.add(
              Ops.add(Installation.update_backup_path, "/etc.pam.d-"),
              date
            ),
            "-"
          ),
          Builtins.sformat("%1", num)
        ),
        ".tar.gz"
      )

      # avoid from filename conflicts
      break if !FileUtils.Exists(Ops.add(Installation.destdir, filename))
      num = Ops.add(num, 1)
    end

    what_to_backup = "etc/pam.d etc/security etc/securetty etc/environment"

    # enters the Installation::destdir
    # and creates backup of etc/pam.d directory in Installation::update_backup_path
    cmd = Builtins.sformat(
      "cd '%1'; /bin/tar --ignore-failed-read -czf '.%2' %3",
      String.Quote(Installation.destdir),
      String.Quote(filename),
      what_to_backup
    )

    Builtins.y2milestone(
      "Creating backup of %1 in %2",
      what_to_backup,
      Ops.add(Installation.destdir, filename)
    )

    if SCR.Execute(path(".target.bash"), cmd).nonzero?
      Builtins.y2error("backup command failed: %1", cmd)
      # an error popup
      Popup.Error(
        Builtins.sformat(
          _("Backup of %1 failed. See %2 for details."),
          "/etc/pam.d",
          Ops.add(Directory.logdir, "/y2log")
        )
      )
    end
  end

  nil
end

#createmdadmObject

Create /etc/mdadm.conf if it does not exist and it's needed bugs: #169710 and #146304


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
# File 'src/clients/inst_kickoff.rb', line 518

def createmdadm
  mdamd_configfile = Ops.add(Installation.destdir, "/etc/mdadm.conf")
  # File exists, no need to create it
  if FileUtils.Exists(mdamd_configfile)
    Builtins.y2milestone(
      "File /etc/mdadm.conf exists, skipping creation..."
    )
    return
  end

  # get the current raid configuration
  out = Convert.to_map(
    SCR.Execute(
      path(".target.bash_output"),
      Ops.add(
        Ops.add(
          Ops.add("chroot '", String.Quote(Installation.destdir)),
          "' "
        ),
        "mdadm -Ds"
      )
    )
  )
  if Ops.get_integer(out, "exit", -1).nonzero?
    Builtins.y2error(
      "Error occurred while getting raid configuration: %1",
      out
    )
    return
  end
  # There's no current raid configuration, no reason to create that file, bug #169710
  if Ops.get_string(out, "stdout", "") == ""
    Builtins.y2milestone(
      "No raid is currently configured, skipping file creation..."
    )
    return
  end

  # File format defined in bug #146304
  mdadm_content = Ops.add(
    Ops.add("DEV partitions\n", Ops.get_string(out, "stdout", "")),
    "\n"
  )

  Builtins.y2milestone("/etc/mdadm.conf doesn't exist, creating it")
  if !SCR.Write(path(".target.string"), mdamd_configfile, mdadm_content)
    Builtins.y2error(
      "Error occurred while creating /etc/mdadm.conf with content '%1'",
      mdadm_content
    )
  end

  nil
end

#load_network_modulesObject

Load all network modules. The package sysconfig requires this during

update.

575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
# File 'src/clients/inst_kickoff.rb', line 575

def load_network_modules
  cards = Convert.convert(
    SCR.Read(path(".probe.netcard")),
    from: "any",
    to:   "list <map>"
  )

  Builtins.foreach(cards) do |card|
    drivers = Ops.get_list(card, "drivers", [])
    one_active = false
    Builtins.foreach(drivers) do |driver|
      one_active = true if Ops.get_boolean(driver, "active", false)
    end
    if !one_active
      name = Ops.get_string(drivers, [0, "modules", 0, 0], "")
      if name != ""
        ModuleLoading.Load(name, "", "Linux", "", Linuxrc.manual, true)
      end
    end
  end

  nil
end

#LocalCommand(command) ⇒ Object

Calls a local command and returns if successful


600
601
602
603
604
605
606
607
608
609
610
# File 'src/clients/inst_kickoff.rb', line 600

def LocalCommand(command)
  cmd = Convert.to_map(WFM.Execute(path(".local.bash_output"), command))
  Builtins.y2milestone("Command %1 returned: %2", command, cmd)

  return true if Ops.get_integer(cmd, "exit", -1).zero?

  if Ops.get_string(cmd, "stderr", "") != ""
    Builtins.y2error("Error: %1", Ops.get_string(cmd, "stderr", ""))
  end
  false
end

#mainObject


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
# File 'src/clients/inst_kickoff.rb', line 8

def main
  Yast.import "Pkg"
  textdomain "packager"

  Yast.import "Mode"
  Yast.import "Stage"
  Yast.import "Linuxrc"
  Yast.import "Installation"
  Yast.import "Popup"
  Yast.import "Directory"
  Yast.import "ModuleLoading"
  Yast.import "Kernel"
  Yast.import "Arch"
  Yast.import "FileUtils"
  Yast.import "String"
  Yast.import "Mtab"

  if !Mode.update
    # fake mtab on target system for rpm post-scripts
    Mtab.clone_to_target
  end

  # Disabling VPN, SSH,.... if the packages are not available
  Linuxrc.disable_remote(Packages.missing_remote_kind)

  # Feature #301903, bugzilla #244937
  if Mode.update
    # "/" means updating the running system, bugzilla #246389
    if Installation.destdir == "/"
      # When upgrading system, remove devs.rpm just from rpm database
      LocalCommand(
        "/bin/rpm -q 'devs' && /bin/rpm --nodeps --justdb -e 'devs'"
      )
      # normal upgrade
    else
      # When upgrading system, remove devs.rpm if installed
      LocalCommand(
        Builtins.sformat(
          "/bin/rpm --root '%1' -q 'devs' && /bin/rpm --nodeps --root '%1' -e 'devs'",
          String.Quote(Installation.destdir)
        )
      )

      # Mount (bind) the current /dev/ to the /installed_system/dev/
      LocalCommand(
        Builtins.sformat(
          "/bin/rm -rf '%1/dev/' && /bin/mkdir -p '%1/dev/' && " \
            "/bin/mount -v --bind '/dev/' '%1/dev/'",
          String.Quote(Installation.destdir)
        )
      )
    end
  end

  # copy the credential files, libzypp loads them from target
  zypp_dir = "/etc/zypp"
  credentials_d = zypp_dir + "/credentials.d"

  if File.exist?(credentials_d) && Installation.destdir != "/"
    target_zypp = Installation.destdir + zypp_dir
    Builtins.y2milestone("Copying libzypp credentials to #{target_zypp}...")
    ::FileUtils.mkdir_p(target_zypp)
    ::FileUtils.cp_r(credentials_d, target_zypp)
  end

  # installation, for instance...
  if !Mode.update
    # make some directories
    SCR.Execute(
      path(".target.mkdir"),
      Ops.add(Installation.destdir, "/etc")
    )
    SCR.Execute(
      path(".target.mkdir"),
      Ops.add(Installation.destdir, Directory.logdir)
    )

    # fake mtab on target system
    Mtab.clone_to_target

    # F#302660: System installation and upgrade workflow: kernel %post
    # calling ins_bootloader write all config files for bootloader
    # if (Stage::initial ())
    #     {
    # call it always, it handles installation mode inside
    WFM.CallFunction("inst_bootloader", WFM.Args)
    # }
  elsif Stage.normal
    Yast.import "Kernel"
    @kernel = Kernel.ComputePackage
    Kernel.SetInformAboutKernelChange(Pkg.IsSelected(@kernel))

    SCR.Execute(
      path(".target.mkdir"),
      Ops.add(Installation.destdir, Installation.update_backup_path)
    )
    backup_stuff
    createmdadm
  else
    # disable all repositories at the target
    Pkg.TargetDisableSources

    # make some directories
    SCR.Execute(
      path(".target.mkdir"),
      Ops.add(Installation.destdir, Directory.logdir)
    )
    SCR.Execute(
      path(".target.mkdir"),
      Ops.add(Installation.destdir, Installation.update_backup_path)
    )

    # backup some stuff
    backup_stuff

    # remove some stuff
    # do not remove when updating running system (#49608)
    remove_stuff

    # set update mode to yes
    SCR.Write(
      path(".target.string"),
      Ops.add(Installation.destdir, "/var/lib/YaST2/update_mode"),
      "YES"
    )
    SCR.Execute(
      path(".target.remove"),
      Ops.add(Installation.destdir, "/var/lib/YaST/update.inf")
    )

    # check passwd and group of target
    SCR.Execute(
      path(".target.bash"),
      Ops.add(
        Ops.add(
          "/usr/lib/YaST2/bin/update_users_groups " + "'",
          String.Quote(Installation.destdir)
        ),
        "'"
      )
    )

    # create /etc/mdadm.conf if it does not exist
    createmdadm

    # load all network modules
    load_network_modules

    # initialize bootloader
    # will return immediatly unless bootloader configuration was
    # proposed from scratch (bnc#899743)
    WFM.CallFunction("inst_bootloader", WFM.Args)
  end

  :next
end

#remove_stuffObject

Remove some old junk.


166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'src/clients/inst_kickoff.rb', line 166

def remove_stuff
  # remove old junk, script is in yast2-update
  SCR.Execute(
    path(".target.bash"),
    Ops.add(
      Ops.add(
        Ops.add(Ops.add(Directory.ybindir, "/remove_junk "), "'"),
        String.Quote(Installation.destdir)
      ),
      "'"
    )
  )

  # possibly remove /usr/share/info/dir
  if !Pkg.TargetFileHasOwner("/usr/share/info/dir")
    SCR.Execute(
      path(".target.remove"),
      Ops.add(Installation.destdir, "/usr/share/info/dir")
    )
  end

  nil
end