Class: Yast::BootloaderFinishClient

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

Instance Method Summary (collapse)

Instance Method Details

- (Object) main



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

def main

  textdomain "bootloader"

  Yast.import "Arch"
  Yast.import "Bootloader"
  Yast.import "Installation"
  Yast.import "Linuxrc"
  Yast.import "Misc"
  Yast.import "Mode"
  Yast.import "BootCommon"


  @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 bootloader_finish")
  Builtins.y2debug("func=%1", @func)
  Builtins.y2debug("param=%1", @param)

  if @func == "Info"
    return {
      "steps" => 3,
      # progress step title
      "title" => _(
        "Saving bootloader configuration..."
      ),
      "when"  => [:installation, :live_installation, :update, :autoinst]
    }
  elsif @func == "Write"
    # provide the /dev content from the inst-sys also inside the chroot of just the upgraded system
    # umount of this bind mount will happen in umount_finish
    if Mode.update
      @cmd = Ops.add(
        Ops.add("targetdir=", Installation.destdir),
        "\n" +
          "if test ${targetdir} = / ; then echo targetdir is / ; exit 1 ; fi\n" +
          "grep -E \"^[^ ]+ ${targetdir}/dev \" < /proc/mounts\n" +
          "if test $? = 0\n" +
          "then\n" +
          "\techo targetdir ${targetdir} already mounted.\n" +
          "\texit 1\n" +
          "else\n" +
          "\tmkdir -vp ${targetdir}/dev\n" +
          "\tcp --preserve=all --recursive --remove-destination /lib/udev/devices/* ${targetdir}/dev\n" +
          "\tmount -v --bind /dev ${targetdir}/dev\n" +
          "fi\n"
      )
      Builtins.y2milestone("mount --bind cmd: %1", @cmd)
      @out = Convert.to_map(WFM.Execute(path(".local.bash_output"), @cmd))
      if Ops.get_integer(@out, "exit", 0) != 0
        Builtins.y2error("unable to bind mount /dev in chroot")
      end
      Builtins.y2milestone("mount --bind /dev /mnt/dev output: %1", @out)
    end
    # --------------------------------------------------------------
    # message after first round of packet installation
    # now the installed system is run and more packages installed
    # just warn the user that the screen is going back to text mode
    # and yast2 will come up again.
    # dont mention this "going back to text mode" here, maybe this
    # wont be necessary in the final version

    # we should tell the user to remove the cd on an SMP or Laptop system
    # where we do a hard reboot. However, the cdrom is still mounted here
    # and cant be removed.

    @finish_ret = nil
    if Arch.s390
      @reipl_client = "reipl_bootloader_finish"

      # Calling a special reIPL client
      # it returns a result map (keys: (boolean) different, (string) ipl_msg)

      if WFM.ClientExists(@reipl_client)
        @finish_ret = Convert.to_map(WFM.call(@reipl_client))
        Builtins.y2milestone(
          "result of reipl_bootloader_finish [%1, %2]",
          Ops.get_boolean(@finish_ret, "different", true),
          Ops.get_string(@finish_ret, "ipl_msg", "N/A2")
        )
        Builtins.y2milestone(
          "finish_ret[\"different\"]:true == true : %1",
          Ops.get_boolean(@finish_ret, "different", true) == true
        )
        if Ops.get_boolean(@finish_ret, "different", false) == true
          Builtins.y2milestone("finish_ret[\"different\"] is true")
        else
          Builtins.y2milestone(
            "finish_ret[\"different\"] is not true (either undefined or false)"
          )
        end
      else
        Builtins.y2error("No such client: %1", @reipl_client)
      end
    end

    if Arch.s390 && Ops.get_boolean(@finish_ret, "different", true) == true
      # reIPL message
      @ipl_msg = ""
      @ipl_msg = Ops.get_string(@finish_ret, "ipl_msg", "")

      # TRANSLATORS: reboot message
      # %1 is replaced with additional message from reIPL
      Misc.boot_msg = Builtins.sformat(
        _(
          "\n" +
            "Your system will now shut down.%1\n" +
            "For details, read the related chapter \n" +
            "in the documentation. \n"
        ),
        @ipl_msg
      )
    else
      # Final message after all packages from CD1 are installed
      # and we're ready to start (boot into) the installed system
      # Message that will be displayed along with information
      # how the boot loader was installed
      Misc.boot_msg = _("The system will reboot now...")
    end

    #--------------------------------------------------------------
    # Install bootloader (always, see #23018)
    # should also set Misc::boot_msg appropriate

    # In Mode::update(), the configuration is not yet read (for some
    # unresearched reason). Therefore, for Mode::update(), there is another
    # call of ResolveSymlinksInSections() after a Read() in
    # Bootloader::ReadOrProposeIfNeeded() (which is called the first time
    # Write() is reached from the call-chain that starts below:
    # Bootloader::Update() -> Write()).

    # perl-BL delayed section removal
    Bootloader.RunDelayedUpdates

    @retcode = false


    if !Mode.update
      @retcode = Bootloader.WriteInstallation
    else
      @retcode = Bootloader.Update
      # workaround for packages that forgot to update initrd(bnc#889616)
      # do not use Initrd module as it can also change configuration, which we do not want
      res = SCR.Execute(path(".target.bash_output"), "/sbin/mkinitrd")
      Builtins.y2milestone("Regerate initrd with result #{res}")
    end

    # FIXME workaround grub2 need manual rerun of branding due to overwrite by
    # pbl. see bnc#879686 and bnc#901003
    if Bootloader.getLoaderType =~ /grub2/
      prefix = Installation.destdir
      branding_activator = Dir["#{prefix}/usr/share/grub2/themes/*/activate-theme"].first
	  
      if branding_activator
        branding_activator = branding_activator[prefix.size..-1]
        res = SCR.Execute(path(".target.bash_output"), branding_activator)
        Builtins.y2milestone("Reactivate branding with #{branding_activator} and result #{res}")
        res = SCR.Execute(path(".target.bash_output"), "/usr/sbin/grub2-mkconfig -o /boot/grub2/grub.cfg")
        Builtins.y2milestone("Grub mkconfig with result #{res}")
      else
        Builtins.y2milestone("No branding_activator")
      end
    end

    if @retcode
      # re-read external changes, then boot through to second stage of
      # installation or update
      Bootloader.Read
      # fate #303395: Use kexec to avoid booting between first and second stage
      # copy vmlinuz, initrd and flush kernel option into /var/lib/YaST2
      @retcode = false
      if Linuxrc.InstallInf("kexec_reboot") == "1"
        @retcode = Bootloader.CopyKernelInird
      else
        @retcode = true
        Builtins.y2milestone("Installation started with kexec_reboot set 0")
      end

      # (bnc #381192) don't use it if kexec is used
      # update calling onetime boot bnc #339024
      if !@retcode
        @bl = Bootloader.getLoaderType
        return Bootloader.FlagOnetimeBoot(Bootloader.getDefaultSection)
      end
    else
      return @retcode
    end
  else
    Builtins.y2error("unknown function: %1", @func)
    @ret = nil
  end

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