ACC SHELL

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

/**
 * File:
 *      bootloader.ycp
 *
 * Module:
 *      Bootloader installation and configuration
 *
 * Summary:
 *      Main file of bootloader configuration
 *
 * Authors:
 *      Jiri Srain <jsrain@suse.cz>
 *
 * $Id: bootloader.ycp 58289 2009-08-06 11:50:12Z juhliarik $
 *
 */
{
    textdomain "bootloader";

    import "BootCommon";
    import "Bootloader";
    import "CommandLine";
    import "Mode";
    import "RichText";

    include "bootloader/routines/wizards.ycp";

// --------------------------------------------------------------------------
// --------------------------------- cmd-line handlers

    /**
      * CommandLine handler for running GUI
      * @return boolean true if settings were saved
      */
    define boolean GuiHandler () ``{
        symbol ret = nil;
	ret = BootloaderSequence ();

        if (ret == `abort || ret == `back || ret == `nil)
            return false;
        return true;
    }

    /**
     * Print summary of basic options
     * @param options a list of parameters passed as args
     * @return boolean false
     */
    define boolean BootloaderSummaryHandler (map options ) ``{
        CommandLine::Print (RichText::Rich2Plain(
            "<br>"+mergestring (Bootloader::Summary (), "<br>")));
        return false; // do not call Write...
    }

    /**
     * Modify the boot loader section
     * @param section string the section name
     * @param key string the key to modify
     * @param value string the value to set
     * @return boolean true on success
     */
    define boolean BootloaderModifySection (string section,
	string key, string value)
    {
	if (section == nil)
	{
	    BootCommon::globals[key] = value;
	    return true;
	}
	else
	{ 
	    // change value in section specified by name in 'section'
	    integer i = 0;
	    while (i < size(BootCommon::sections)) {
	        if (BootCommon::sections[i, "name"]:"" == section) {
		    BootCommon::sections[i, key] = value;
		    BootCommon::sections[i, "__changed"] = true;
		    return true;
		}
	        i = i + 1;
	    };

	    // command line error report, %1 is section name
	    CommandLine::Print (sformat (_("Section %1 not found."),
					 section));
	    return false;
	}
	return false;
    }

    /**
     * Set specified option in specified section
     * @param options a list of parameters passed as args
     * @return boolean true on success
     */
    define boolean BootloaderSetHandler (map options) ``{
	string section = (string)(options["section"]:nil);
	string option = (string)(options["option"]:nil);
	any value = options["value"]:nil;
	if (value == nil)
	{
	    // command line error report
	    CommandLine::Print (_("Value was not specified."));
	    return false;
	}
	return BootloaderModifySection (section, option, (string)value);
    }

    /**
     * Delete specified option in specified section
     * @param options a list of parameters passed as args
     * @return boolean true on success
     */
    define boolean BootloaderDeleteHandler (map options) ``{
	string section = (string)(options["section"]:nil);
	if (! haskey (options, "option"))
	{
	    // remove section specified by name in 'section'
	    integer i = 0;
	    while (i < size(BootCommon::sections)) {
	        if (BootCommon::sections[i, "name"]:"" == section) {
		    BootCommon::sections = remove(BootCommon::sections, i);
		    return true;
		}
	        i = i + 1;
	    };

	    // command line error report, %1 is section name
	    CommandLine::Print (sformat (_("Section %1 not found."),
					 section));
	    return false;
	}
	string option = (string)(options["option"]:nil);
	return BootloaderModifySection (section, option, nil);
    }

    /**
     * Add a new bootloader section with specified name
     * @param options a list of parameters passed as args
     * @return boolean true on success
     */
    define boolean BootloaderAddHandler (map options) ``{
	if (! CommandLine::Interactive())
	    CommandLine::Error(_("Add option is available only in commandline interactive mode"));
	string section = (string)(options["section"]:nil);
	if (section == nil)
	{
	    // command line error report
	    CommandLine::Print (_("Section name must be specified."));
	    return false;
	}
	BootCommon::sections = add (BootCommon::sections,
	    $[
		"name" : section
	    ]);
    }

    /**
     * Print the value of specified option of specified section
     * @param options a list of parameters passed as args
     * @return boolean true on success
     */
    define boolean BootloaderPrintHandler (map options) ``{
	string section = (string)(options["section"]:nil);
	string option = (string)(options["option"]:nil);
	if (option == nil)
	{
	    // command line error report
	    CommandLine::Print (_("Option was not specified."));
	    return false;
	}
	any value = nil;
	if (section == nil)
	{
	    value = BootCommon::globals[option]:nil;
	}
	else
	{
	    // change value in section specified by name in 'section'
	    integer i = 0;
	    while (i < size(BootCommon::sections) && value == nil) {
	        if (BootCommon::sections[i, "name"]:"" == section) {
		    value = BootCommon::sections[i, option]:nil;
		}
	        i = i + 1;
	    };
	}
	if (value == nil)
	    // command line error report
	    CommandLine::Print (_("Specified option does not exist."));
	else
	    // command line, %1 is the value of bootloader option
	    CommandLine::Print (sformat (_("Value: %1"), value));
	return false;
    }

    /* the command line description map */
    map cmdline = $[
	"id"		: "bootloader",
	// command line help text for Bootloader module
	"help"		: _("Boot loader configuration module"),
	"guihandler"	: GuiHandler,
	"initialize"	: Bootloader::Read,
	"finish"	: Bootloader::Write,
	"actions"	: $[
	    "summary"	: $[
		"handler"	: BootloaderSummaryHandler,
		// command line help text for summary action
		"help"		: _("Configuration summary of boot loader")
	    ],
	    "delete"	: $[
		"handler"	: BootloaderDeleteHandler,
		// command line help text for delete action
		"help"		: _("Delete a global option or option of a section"),
	    ],
	    "set"	: $[
		"handler"	: BootloaderSetHandler,
		// command line help text for set action
		"help"		: _("Set a global option or option of a section"),
	    ],
	    "add"	: $[
		"handler"	: BootloaderAddHandler,
		// command line help text for add action
		"help"		: _("Add a new section - please use interactive mode"),
	    ],
	    "print"	: $[
		"handler"	: BootloaderPrintHandler,
		// command line help text for print action
		"help"		: _("Print value of specified option"),
	    ],
	],
        "options"	: $[
	    "section"	: $[
		// command line help text for an option
		"help"		: _("The name of the section"),
		"type"		: "string",
            ],
	    "option"	: $[
		// command line help text for an option
		"help"		: _("The key of the option"),
		"type"		: "string",
            ],
	    "value"	: $[
		// command line help text for an option
		"help"		: _("The value of the option"),
		"type"		: "string",
            ],
	],
        "mappings"	: $[
            "summary"		: [],
	    "delete"		: [ "section", "option" ],
	    "set"		: [ "section", "option", "value" ],
	    "add"		: [ "section" ],
	    "print"		: [ "section", "option" ],
	],
    ];

    y2milestone ("Starting bootloader configuration module");
    boolean skip_io = false;
    integer i = 0;
    while (i < size ((list)WFM::Args()))
    {
	if (.noio == WFM::Args (i) || ".noio" == WFM::Args (i))
	{
	    skip_io = true;
	}
	i = i + 1;
    }

    any ret = CommandLine::Run (cmdline);
//    boolean ret = GuiHandler ();

    y2milestone ("Finishing bootloader configuration module");
    return ret;
}

ACC SHELL 2018