/**
 * File:
 *      bootloader_auto.ycp
 *
 * Module:
 *      Bootloader installation and configuration
 *
 * Summary:
 *      Bootloader autoinstallation preparation
 *
 * Authors:
 *      Jiri Srain <jsrain@suse.cz>
 *
 * $Id: bootloader_auto.ycp 20561 2004-12-15 12:14:06Z jsrain $
 *
 */
{
    textdomain "bootloader";

    y2milestone("----------------------------------------");
    y2milestone("bootloader auto started");

    import "Bootloader";
    import "BootCommon";
    import "Initrd";
    import "Progress";
    import "Mode";

    include "bootloader/routines/routines.ycp";
    include "bootloader/routines/autoinstall.ycp";

    boolean progress_orig = Progress::set (false);


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

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

    if(func == "Import")
    {
	ret = Bootloader::Import(AI2Export ((map<string,any>)param));
    }
    /**
      * Create a summary
      * return string
      */
    else if(func == "Summary") {
	ret = "<UL>"
            + mergestring (maplist (string l, Bootloader::Summary(),
		``("<LI>" + l)),
		"\n")
            + "</UL>";
    }
    /**
      * did configuration changed
      * return boolean
      */
    else if (func == "GetModified") {
	ret =  BootCommon::changed;
    }
    /**
     * set configuration as changed
     * return boolean
     */
    else if (func == "SetModified") {
        BootCommon::changed = true;
        ret = true;
    }
    /**
      * Reset configuration
      * return map or list
      */
    else if (func == "Reset") {
	Bootloader::Reset();
	ret =  ($[]);
    }
    /**
      * Change configuration
      * return symbol (i.e. `finish || `accept || `next || `cancel || `abort)
      */
    else if (func == "Change") {
	ret = Bootloader::BootloaderAutoSequence ();
	return ret;
    }
    /**
      * Return configuration data
      * return map or list
      */
    else if (func == "Export") {
	ret = Export2AI ((map<string,any>)Bootloader::Export());
    }
    /**
      * Write configuration data
      * return boolean
      */
    else if (func == "Write") {
	ret = Bootloader::Write();
    }
    else if (func == "Read") {
	Initrd::Read ();
	ret = Bootloader::Read();
    }
    /* unknown function */
    else {
	y2error("unknown function: %1", func);
	ret =  false;
    }
    Progress::set (progress_orig);

    y2debug("ret=%1", ret);
    y2milestone("bootloader_auto finished");
    y2milestone("----------------------------------------");

    return ret;

/* EOF */

}
