ACC SHELL

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

/**
 * Module:		bootloader_proposal.ycp
 *
 * $Id: bootloader_proposal.ycp 61958 2010-05-06 11:15:42Z juhliarik $
 *
 * Author:		Klaus Kaempf <kkaempf@suse.de>
 *
 * Purpose:		Proposal function dispatcher - bootloader.
 *
 *			See also file proposal-API.txt for details.
 */
{
    textdomain "bootloader";

    import "Arch";
    import "BootCommon";
    import "Bootloader";
    import "Storage";
    import "Mode";
    import "BootSupportCheck";

    include "bootloader/routines/wizards.ycp";

    string func  = (string)WFM::Args(0);
    map    param = (map)WFM::Args(1);
    map<string,any>    ret   = $[];

    // This will be called every time we enter the proposal widget. Here we can
    // return cached data, but when force_reset is set, we must create a new
    // proposal based on freshly discovered data (ie. from Storage:: and
    // perl-Bootloader (etc.?)).
    if ( func == "MakeProposal" )
    {
	boolean force_reset      = param["force_reset"     ]:false;
	boolean language_changed = param["language_changed"]:false;

	// use the cache if possible
	    // if not asked to recreate and we have a cached proposal and
	if (false
	    && !force_reset
	    && Bootloader::cached_proposal != nil

	    // has the configuration been changed?
	    && Bootloader::cached_settings == Bootloader::Export()

	    // has the partitioning been changed?
	    // This is correct as long as the proposal is only dependent on the
	    // settings in Storage. AFAICT all information relevant to a
	    // proposal in yast2-bootloader comes from yast2-storage. Even the
	    // information from perl-Bootloader only depends on the settings in
	    // Storage or libstorage. So this should be OK. At this point all
	    // changes relevant to the yast2-bootloader settings are made
	    // through Storage, so the change time of Storage data should be
	    // sufficient.
	    && BootCommon::cached_settings_base_data_change_time == Storage::GetTargetChangeTime())


	  // FIXME: has the software selection changed?: esp. has the
	  // Xen pattern been activated ? then we'd have to make the
	  // proposal again.



	{
	    y2milestone("Using cached proposal");
	    return Bootloader::cached_proposal;
	}

	if (force_reset && !Mode::autoinst ())
	{
	    // force re-calculation of bootloader proposal
	    // this deletes any internally cached values, a new proposal will
	    // not be partially based on old data now any more
	    y2milestone ("Recalculation of bootloader configuration forced");
	    Bootloader::Reset ();
	}

	if (! Bootloader::proposed_cfg_changed && ! Mode::autoinst ())
	{
	    y2milestone ("Cfg not changed before, recreating");
	    Bootloader::ResetEx (false);
	    BootCommon::setLoaderType (nil);
	}

	if (Bootloader::getLoaderType () == "grub")
	{
	    import "BootGRUB";
            // merge_level == `main means: merge only the "default" key(s?) of
            // a "foreign" grub configuration from a different configuration
            // into our configuration
	    BootGRUB::merge_level = `main;
	    Bootloader::Propose ();

	    
	    BootGRUB::merge_level = `none;

	    ret["links"] = [
		"enable_boot_mbr", "disable_boot_mbr",
		"enable_boot_root", "disable_boot_root",
		"enable_boot_boot", "disable_boot_boot",
	    ];
	}
	else
	{
	    Bootloader::Propose ();
	}
	// to make sure packages will get installed
	BootCommon::setLoaderType (BootCommon::getLoaderType (false));

	ret["raw_proposal"] = Bootloader::Summary ();


	if (Bootloader::getLoaderType () == "grub")
	{
	    integer max_end = 128;

	    if (BootSupportCheck::EndOfBootOrRootPartition() > max_end * 1073741824)
	    {
		ret = add (ret, "warning_level", `warning);
		// warning text in the summary richtext
		ret = add (ret, "warning",
			   sformat(_("The bootloader is installed on a partition that does not lie entirely below %1 GB. The system might not boot."), max_end));
	    }
	}

	if (Bootloader::getLoaderType () == "grub")
	{
	    import "BootGRUB";
	    if (BootGRUB::CheckDeviceMap())
	    {
		ret = (map<string,any>) union (ret, 
			$[
	    		    "warning_level" : `blocker,
	    		    "warning" :
	    		    ret["warning"]:"" +
	    		       _("Configure a valid boot loader location before continuing.<br/>
The device map includes more than 8 devices and the boot device is out of range.
The range is limited by BIOS to the first 8 devices."),
	        	]
	         );
	    }
	}

	//F#300779 - Install diskless client (NFS-root) 
	//kokso:  bootloader will not be installed
        string device = BootCommon::getBootDisk();
        if (device == "/dev/nfs")
        {

           y2milestone("bootlader_proposal::MakeProposal -> Boot partition is nfs type, bootloader will not be installed.");
           y2milestone("Type of BootPartitionDevice: %1", device);
           return ret;

        }
        y2milestone("Type of BootPartitionDevice: %1", device);

	//F#300779 - end

	if (Bootloader::getLoaderType () == "")
        {
            y2error ("No bootloader selected");
            ret = add (ret, "warning_level", `error);
	    // warning text in the summary richtext
            ret = add (ret, "warning",
		       _("No boot loader is selected for installation. Your system might not be bootable."));
        }

	if (Bootloader::getLoaderType () == "lilo")
        {
            y2error ("LILO bootloader selected");
            ret = add (ret, "warning_level", `error);
	    // warning text in the summary richtext
            ret = add (ret, "warning",
		       _("The LILO is not supported now."));
        }


	if (! BootCommon::BootloaderInstallable ())
	{
	    ret = $[
		"warning_level" : `error,
		// error in the proposal
		"warning" : _("Because of the partitioning, the bootloader cannot be installed properly"),
	    ];
	}
	else if (Bootloader::getLoaderType () == "ppc")
	{
	    if (Arch::board_chrp ())
	    {
	        if (BootCommon::globals["activate"]:"false" == "false")
		{
		    ret = (map<string,any>)
		      union(ret,
			    $[
			      "warning_level" : `error,
			      "warning" :
			      _("The selected boot path will not be activated for your installation. Your system may not be bootable."),
		    ]);
		}
	    }

            if (Arch::board_mac_new()) {

	    	if ( BootCommon::loader_device == "" ) {
	    		ret = (map<string,any>)union (ret, $[
	    			"warning_level" : `blocker,
	    			"warning" :
	    			    ret["warning"]:"" +
	    			    _("Configure a valid boot loader location before continuing.<br>
In case that no selection can be made it may be necessary to create a small primary Apple HFS partition."),
	        		]
	            );
	        }
	    }


	    if (Arch::board_iseries()) {
	      // FIXME: handle consistency test for iseries configuration
	      // currently: none
	      y2debug("No consistency check implemented for iSeries boot configuration");
	    }
	    else {
	    	// FIXME: better eliminate use of loader_device in the
	    	// future, no one knows what it is for
	    	if ( BootCommon::loader_device == "" ) {
	    		ret = (map<string,any>)union (ret, $[
	    			"warning_level" : `blocker,
	    			"warning" :
	    			    ret["warning"]:"" +
	    			    _("Configure a valid boot loader location before continuing.<br>
In case that no selection can be made it may be necessary to create a PReP Boot partition."),
	        		]
	            );
	        }
	    }
	}

	if (!BootSupportCheck::SystemSupported())
	{
		ret = (map<string,any>)
		      union(ret,
			    $[
			      "warning_level" : `error,
			      "warning" :  BootSupportCheck::StringProblems(),
			      "raw_proposal" : Bootloader::Summary (),
		    ]);

	}

	// cache the values
	Bootloader::cached_settings = Bootloader::Export();
	BootCommon::cached_settings_base_data_change_time = Storage::GetTargetChangeTime();
	Bootloader::cached_proposal = ret;
    }
    // This is a request to start some dialog and interact with the user to set
    // up the Bootloader setting. Called when the user presses the link to set
    // up the Bootloader.
    else if ( func == "AskUser" )
    {

	any chosen_id = param["chosen_id"]:nil;
	symbol result = `next;
	y2milestone("Bootloader wanted to change with id %1", chosen_id);

	// enable boot from MBR
	if (chosen_id == "enable_boot_mbr") 
	{
	    y2milestone("Boot from MBR enabled by a single-click");
	    BootCommon::globals["boot_mbr"] = "true";
	    Bootloader::proposed_cfg_changed = true;
	}

	// disable boot from MBR
	else if (chosen_id == "disable_boot_mbr") 
	{
	    y2milestone("Boot from MBR disabled by a single-click");
	    BootCommon::globals["boot_mbr"] = "false";
	    Bootloader::proposed_cfg_changed = true;
	}
	// enable boot from /boot
	else if (chosen_id == "enable_boot_boot") 
	{
	    y2milestone("Boot from /boot enabled by a single-click");
	    BootCommon::globals["boot_boot"] = "true";
	    Bootloader::proposed_cfg_changed = true;
	}

	// disable boot from /boot
	else if (chosen_id == "disable_boot_boot") 
	{
	    y2milestone("Boot from /boot disabled by a single-click");
	    BootCommon::globals["boot_boot"] = "false";
	    Bootloader::proposed_cfg_changed = true;
	}

	// enable boot from /
	else if (chosen_id == "enable_boot_root") 
	{
	    y2milestone("Boot from / enabled by a single-click");
	    BootCommon::globals["boot_root"] = "true";
	    Bootloader::proposed_cfg_changed = true;
	}

	// disable boot from /
	else if (chosen_id == "disable_boot_root") 
	{
	    y2milestone("Boot from / disabled by a single-click");
	    BootCommon::globals["boot_root"] = "false";
	    Bootloader::proposed_cfg_changed = true;
	}	
	else
	{
	    boolean has_next = param["has_next"]:false;

	    map settings = Bootloader::Export ();
	    // don't ask for abort confirm if nothing was changed (#29496)
	    BootCommon::changed = false;
	    result = BootloaderAutoSequence ();
	    // set to true, simply because must be saved during installation
	    BootCommon::changed = true;
	    if (result != `next)
		Bootloader::Import ((map<string,any>)settings);
	    else
		Bootloader::proposed_cfg_changed = true;
	}
	// Fill return map
	ret["workflow_sequence"] = result;
    }
    // This describes the "active" parts of the Bootloader proposal section.
    else if ( func == "Description" )
    {
	// Fill return map.
	//
	// Static values do just nicely here, no need to call a function.

	ret =
	    $[
		// proposal part - bootloader label
	      "rich_text_title"	:	_("Booting"),
		// menubutton entry
	      "menu_title"	:	_("&Booting"),
	      "id"		:	"bootloader_stuff"
	    ];
    }
    // Before the system is installed there is no place to write to yet. This
    // code is not called. The bootloader will be installed later during
    // inst_finish.
    else if (func == "Write")
    {
	boolean succ = Bootloader::Write ();
	ret =
	    $[
		"success"	:	succ
	    ];
    }

    return ret;
}

ACC SHELL 2018