/**
 * File:
 *      bootloader/ppc/prep.ycp
 *
 * Module:
 *      Bootloader installation and configuration
 *
 * Summary:
 *      include containing specific functions for iSeries configuration
 *      and installation
 *
 * Authors:
 *      Jiri Srain <jsrain@suse.cz>
 *
 * $Id: prep.ycp 19973 2004-10-27 07:50:12Z jsrain $
 *
 */

{
    textdomain "bootloader";

    import "Kernel";
    import "Installation";
    import "Mode";

    import "BootCommon";

    include "bootloader/ppc/misc.ycp";
    include "bootloader/routines/popups.ycp";

    /**
      * Propose bootloader settings
      * @param initial boolean true if doing initial proposal
      */
    global define void PRePPropose (boolean initial) ``{
	if (BootCommon::was_proposed)
	{
	    return;
	}

        if ( ! (size (prep_boot_partitions) > 0 ||
            (prep_boot_partition != "" && prep_boot_partition != "/dev/null")))
        {
            BootCommon::activate = false;
	    prep_boot_partition = "/dev/null";
        }
	else
	{
	    BootCommon::activate = true;
	}
    }

    /**
      * Read the board-type-specific settings
      * @return boolean true on success
      */
    global define boolean PRePRead () ``{
	prep_boot_partition = (string)
	    lookup_value (BootCommon::globals, "boot", "");
	BootCommon::activate
	    = prep_boot_partition != "" && prep_boot_partition != "/dev/null";
	return true;
    }

    /**
      * Update the board-type-specific settings
      * @return boolean true on success
      */
    global define boolean PRePUpdate () ``{
	return true;
    }

    /**
      * Save the board-type-specific settings
      * @return boolean true on success
      */
    global define boolean PRePSave () ``{
	BootCommon::globals = modifySection (BootCommon::globals, "boot",
	    prep_boot_partition);
	return true;
    }

    /**
      * retuen the board-type-specific part of summary
      * @return a list of summary strings
      */
    global define list<string> PRePSummary () ``{
	list<string> ret = [];
	if ((! Mode::config ()) && 0 == size (prep_boot_partitions))
	{
	    ret = [
		// summary part
		_("There is no 41 PReP boot partition. You cannot boot from the hard disk."),
	    ];
	}
	else if ( BootCommon::activate == false )
	{
	    ret = [
		// summary part
		_("No boot configuration. Configure booting manually."),
	    ];
	}
	else
	{
	    ret = [
		// summary part
		_("The zImage.prep from CD1/boot must be written to a 41 PReP boot partition."),
	    ];
	}
	return ret;
    }

    /**
      * Install the board-type-specific part of bootloader
      * @param requires_initrd boolean true if initrd is required
      * @return boolean true on success
      */
    global define boolean PRePWrite (boolean requires_initrd) ``{
        if (! BootCommon::activate)
            return true;
	// the PReP boot file (the kernel) is not in k_deflt.rpm
	// FIXME: this is one of the crudest hacks (cf #9718)
	WFM::Execute (.local.bash, "/bin/cp -pv " + Installation::sourcedir
	    + "/boot/mvlinuz-prep* /boot/zImage.prep");
	WFM::Execute (.local.bash, "/bin/cp -pv " + Installation::sourcedir
	    + "/boot/install-prep* /boot/zImage.initrd.prep");
	return true;
    }

    /**
      * Initialize attributes of the board type
      */
    global define void PRePInit () ``{
	y2milestone ("Initializing PReP attributes");
	prep_only_active = true;
	prep_only_iseries_vd = false;
	prep_only_primary = true;
	prep_same_disk_as_root = false;
	table_items = [ "__prep_location" ];
    }

}
