/**
 * File:
 *      modules/BootMILO.ycp
 *
 * Module:
 *      Bootloader installation and configuration
 *
 * Summary:
 *      Module containing specific functions for MILO configuration
 *      and installation
 *
 * Authors:
 *      Jiri Srain <jsrain@suse.cz>
 *      Klaus Kaempf <kkaempf@suse.de>
 *
 * $Id: BootMILO.ycp 20172 2004-11-04 13:06:16Z jsrain $
 *
 */

{
    module "BootMILO";

    textdomain "bootloader";

    import "Kernel";
    import "Storage";
    import "StorageControllers";
    import "BootCommon";
    import "Installation";

    include "bootloader/routines/popups.ycp";

// misc. functions

    /**
      * Empty summary dialog
      * @return symbol always `back
      */
    global define symbol runSummaryDialog () ``{
	displayNoSupportPopup ();
	return `back;
    }

// general functions

    /**
      * Propose bootloader settings
      */
    global define void Propose () ``{
	BootCommon::DetectDisks ();
    }

    /**
      * Read settings from disk
      * @return boolean true on success
      */
    global define boolean Read () ``{
	BootCommon::DetectDisks ();
	return true;
    }

    /**
      * Save all bootloader configuration files
      * @return boolean true if success
      */
    global define boolean Save () ``{
	return true;
    }

    /**
      * Display bootloader summary
      * @return a list of summary lines
      */
    global define list<string> Summary () ``{
	// summary
	return [_("Install MILO Boot Loader")];
    }

    /**
      * Update read settings to new version of configuration files
      */
    global define void Update () ``{
	y2milestone ("No update functionality implemented");
    }

    /**
      * Write bootloader settings to disk
      * @return boolean true on success
      */
    global define boolean Write () ``{
	string tmpfile = (string)SCR::Read (.target.tmpdir) + "boot.conf";
        string docmd = "/usr/lib/YaST2/bin/do"
	    + BootCommon::getLoaderType (false) + " / " + tmpfile;

        // prepare /tmp/boot.conf
        byteblock milo_buffer = (byteblock)
	    WFM::Read(.local.byte, Installation::sourcedir+ "/milo/boot.conf");
        SCR::Write(.target.byte, tmpfile, milo_buffer);
        // install milo in /boot
        SCR::Execute (.target.bash, docmd);
        // remove /tmp/boot.conf
        SCR::Execute (.target.remove, tmpfile);

        return true;
    }

    /**
      * Update bootlaoder configuration sequence
      * @param ws_data map of wizard sequencer data
      * @return map modified map of wizard sequencer data
      */
    global define map FixSequence (map ws_data) ``{
        map aliases = $[
	    "summary" : ``(BootMILO::runSummaryDialog ()),
        ];
        ws_data["aliases"] = aliases;
        return ws_data;
    }

    /**
      * Return map of provided functions
      * @return map map of functions (eg. $["write":``(BootLILO::Write ())])
      */
    global define map<string, any> GetFunctions () ``{
	return $[
	    "read"	: BootMILO::Read,
	    "propose"	: BootMILO::Propose,
	    "save"	: BootMILO::Save,
	    "summary"	: BootMILO::Summary,
	    "update"	: BootMILO::Update,
	    "write"	: BootMILO::Write ,
	    "sequence"	: BootMILO::FixSequence,
	];
    }


// end of mandatory functions
//----------------------------------------------------------------------------

}
