ACC SHELL

Path : /usr/share/YaST2/clients/
File Upload :
Current File : //usr/share/YaST2/clients/yast_inf_finish.ycp

/**
 * File:
 *  yast_inf_finish.ycp
 *
 * Module:
 *  Step of base installation finish
 *
 * Authors:
 *  Jiri Srain <jsrain@suse.cz>
 *
 * $Id: yast_inf_finish.ycp 54888 2009-01-22 11:47:19Z locilka $
 *
 */

{

textdomain "installation";

import "Mode";
import "Linuxrc";
import "AutoinstConfig";
import "Language";
import "Keyboard";
import "Directory";
import "String";
import "Arch";

include "installation/misc.ycp";

any ret = nil;
string func = "";
map param = $[];

// fate #303395: Use kexec to avoid booting between first and second stage
// run new kernel via kexec instead of reboot

define boolean LoadKexec()
{

    // command for reading kernel_params
    string cmd = sformat("ls '%1/kernel_params' |tr -d '\n'", String::Quote (Directory::vardir));
    y2milestone("Checking existing file kernel_params via command %1", cmd);

    map out = (map)WFM::Execute(.local.bash_output, cmd);

    cmd = sformat("%1/kernel_params",Directory::vardir);
    // check output
    if (out["stdout"]:"" != cmd)
    {
	y2milestone ("File kernel_params was not found, output: %1", out);
	return false;
    }

    // command for reading kernel_params
    cmd = sformat("cat '%1/kernel_params' |tr -d '\n'", String::Quote (Directory::vardir));
    y2milestone("Reading kernel arguments via command %1", cmd);
    // read data from /var/lib/YaST2/kernel_params
    out = (map)WFM::Execute(.local.bash_output, cmd);
    // check output
    if (out["exit"]:nil != 0)
    {
	y2error ("Reading kernel arguments failed, output: %1", out);
	return false;
    }

    string kernel_args = out["stdout"]:"";
    // check if kernel_params contains any data
    if (size(kernel_args) <2)
    {
	y2error ("%1/kernel_params is empty, kernel_params=%2 ", Directory::vardir, kernel_args);
	return false;
    }

    // command for finding initrd file
    cmd = sformat ("ls %1/initrd-* |tr -d '\n'", Directory::vardir);
    y2milestone("Finding initrd file via command: %1", cmd);
    // find inird file
    out = (map)WFM::Execute(.local.bash_output, cmd);
    // check output
    if (out["exit"]:nil != 0)
    {
	y2error ("Finding initrd file failed, output: %1", out);
	return false;
    }
 
    string initrd = out["stdout"]:"";
    // check if initrd (string) contains any data
    if (size(initrd) <2)
    {
	y2error ("initrd was not found: %1", initrd);
	return false;
    }
 
    // command for finding vmlinuz file
    cmd = sformat ("ls %1/vmlinuz-* |tr -d '\n'", Directory::vardir);
    y2milestone("Finding vmlinuz file via command: %1", cmd);
    // find inird file
    out = (map)WFM::Execute(.local.bash_output, cmd);
    // check output
    if (out["exit"]:nil != 0)
    {
	y2error ("Finding vmlinuz file failed, output: %1", out);
	return false;
    }
 
    string vmlinuz = out["stdout"]:"";
    // check if initrd (string) contains any data
    if (size(vmlinuz) <2)
    {
	y2error ("vmlinuz was not found: %1", vmlinuz);
	return false;
    }

    // command for calling kexec
    cmd = sformat("kexec -l --command-line='%1' --initrd='%2' '%3'",
	String::Quote (kernel_args), String::Quote (initrd), String::Quote (vmlinuz));
    y2milestone("Calling kexec via command: %1", cmd);

    // call kexec
    out = (map)WFM::Execute(.local.bash_output, cmd);
    // check output
    if (out["exit"]:nil != 0)
    {
	y2error ("Calling kexec failed, output: %1", out);
	return false;
    }

    y2milestone("Loading new kernel was succesful");
    return true;

}


/* Check arguments */
if(size(WFM::Args()) > 0 && is(WFM::Args(0), string)) {
    func = (string)WFM::Args(0);
    if(size(WFM::Args()) > 1 && is(WFM::Args(1), map))
	param = (map)WFM::Args(1);
}

y2milestone ("starting yast_inf_finish");
y2debug("func=%1", func);
y2debug("param=%1", param);

if (func == "Info")
{
    return (any)$[
	"steps" : 1,
	// progress step title
	"title" : _("Writing YaST Configuration..."),
	"when" : [ `installation, `update, `autoinst ],
    ];
}
else if (func == "Write")
{
    // write boot information for linuxrc
    // collect data for linuxrc, will be written to /etc/yast.inf
    map<string,string> linuxrc = $[];

    // always do hard reboot to ensure that all stuff is initializes
    // correctly. but no reboot message form linuxrc.
    linuxrc["Root"] = "reboot";
    linuxrc["RebootMsg"] = "0";

    if (LoadKexec())
	linuxrc["Root"] = "kexec";

    // Override linuxrc settings in autoinst mode
    if ( Mode::autoinst () )
    {
        if (AutoinstConfig::ForceBoot )
        {
            linuxrc["Root"] = "reboot";
        }
        else if (AutoinstConfig::RebootMsg)
        {
            linuxrc["RebootMsg"] = "1";
        }
        else if (AutoinstConfig::Halt)
        {
            linuxrc["Root"] = "halt";
        }
    }

    if (linuxrc["Root"]:"" == "kexec")
    {
    	// flag for inst_finish -> kerel was successful loaded by kexec
    	string cmd = sformat ("touch \"%1/kexec_done\"", Directory::vardir);
    	// call command
    	WFM::Execute(.local.bash_output, cmd);
	if (! UI::TextMode()) 
	{
	    y2milestone ("Printing message about loading kernel via kexec");
	    SCR::Write (.dev.tty.stderr,
		_("
**************************************************************

Loading installed kernel using kexec.

Trying to load installed kernel via kexec instead of rebooting
Please, wait.

**************************************************************
		")
	    );
	}
    }

    // FATE #304940: Change YaST2-Module for s390 Disk adaptors from
    // hwconfig scheme to udev-scheme
    if (Arch::s390 ()) {
	string reipl_client = "reipl_finish";

	if (WFM::ClientExists (reipl_client)) {
	    boolean changed = (boolean) WFM::call (reipl_client);
	    if (changed == true) {
		linuxrc["Root"] = "halt";
	    }
	} else {
	    y2error ("No such client: %1", reipl_client);
	}
    }

    linuxrc["Language"] = Language::language;
    linuxrc["Keytable"] = Keyboard::keymap;

    Linuxrc::WriteYaSTInf (linuxrc);

    // --------------------------------------------------------------
    // Copy blinux configuration

    if (Linuxrc::braille ())
    {
        InjectFile ("/etc/suse-blinux.conf");
    }
}
else
{
    y2error ("unknown function: %1", func);
    ret = nil;
}

y2debug("ret=%1", ret);
y2milestone("yast_inf_finish finished");
return ret;


} /* EOF */

ACC SHELL 2018