/**
 * File:	clients/runlevel_auto.ycp
 * Package:	Configuration of Runlevel
 * Summary:	Client for autoinstallation
 * Authors:	nashif@suse.de
 *
 * $Id: runlevel_auto.ycp 21806 2005-02-21 17:01:04Z mlazar $
 *
 * This is a client for autoinstallation. It takes its arguments,
 * goes through the configuration and return the setting.
 * Does not do any changes to the configuration.
 */

/**
 * @param function to execute
 * @param map/list of RunlevelEd settings
 * @return map edited settings, Summary or boolean on success depending on called function
 * @example map mm = $[ "FAIL_DELAY" : "77" ];
 * @example map ret = WFM::CallFunction ("RunlevelEd_auto", [ "Summary", mm ]);
 */

{
textdomain "runlevel";

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

import "RunlevelEd";
import "Progress";
import "Wizard";
import "Sequencer";

include "runlevel/wizard.ycp";

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

/* 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);
}
y2debug("func=%1", func);
y2debug("param=%1", param);



// We take data from underlying system
// RunlevelEd::Read ();


/* Import Data*/
if(func == "Import") {
    boolean po = Progress::set(false); 
    RunlevelEd::Read (); 
    ret = RunlevelEd::Import(param); 
    Progress::set(po); 
}
/* Create a  summary*/
else if(func == "Summary") {
	ret = RunlevelEd::Summary();
}
/* Reset configuration */
else if (func == "Reset") {
	RunlevelEd::Import($[]);
	ret = $[];
}
/* Change configuration (run AutoSequence) */
else if (func == "Change") {
    if (!RunlevelEd::GetModified()) {
        RunlevelEd::runlevels = (list<string>) SCR::Read (.init.scripts.runlevel_list);
	if (0 == size (RunlevelEd::runlevels))
	{
            RunlevelEd::runlevels = ["0", "1", "2", "3", "5", "6", "S", ];
	}

	//..
        RunlevelEd::default = (string) SCR::Read (.init.scripts.default_runlevel);
    }
    ret = RunlevelAutoSequence();
}
/* Read Configuration  */
else if (func == "Read") {
    boolean po = Progress::set(false);
    ret = RunlevelEd::Read();
    Progress::set(po);
}
/* Return actual state */
else if (func == "Export") {
	ret = RunlevelEd::Export();
}
else if (func == "Packages") {
	ret = $[];
}
/* Write givven settings */
else if (func == "Write") {
    boolean po = Progress::set(false);
    ret = RunlevelEd::Write();
    Progress::set(po);
}
else if (func == "SetModified") {
    ret = RunlevelEd::SetModified ();
}
else if (func == "GetModified") {
    ret = RunlevelEd::GetModified ();
}
/* Unknown function */
else {
	y2error("Unknown function: %1", func);
	ret = false;
}

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

return ret;

/* EOF */
}
