/**
 * File:
 *	Vendor.ycp
 *
 * Module:
 *	Vendor
 *
 * Summary:
 *	provide vendor/driver update disk functions
 *
 * $Id: Vendor.ycp 20297 2004-11-11 17:12:23Z arvin $
 *
 * Author:
 *	Klaus Kaempf <kkaempf@suse.de>
 *
 */
{
    module "Vendor";

    import "Installation";
    import "Directory";

    // --------------------------------------------------------------
    // driver update ?!

    /**
     * DriverUpdate
     * copy /update/* to target:/tmp/update/
     * !! can only be called in inst_finish !!
     */

    global define void DriverUpdate1 ()
    {
	list<string> updatefiles = (list<string>)WFM::Read (.local.dir, ["/update", []]);
	if (size (updatefiles) <= 0)
	    return;

	// clean up, just in case
	SCR::Execute(.target.bash, "/bin/rm -rf /tmp/update");

	// copy log file
	WFM::Execute(.local.bash, "l=/var/log/driverupdate.log ; [ -f $l ] && /bin/cat $l >>" + Installation::destdir + "$l");

	// copy all update files
	WFM::Execute(.local.bash, "/bin/cp -a /update " + Installation::destdir + "/tmp/update");

	// unpack update files and run update.post scripts
	SCR::Execute(.target.bash,
		     "cd / ; " +
		     "echo \"Installing driver update\" >> " + Directory::logdir + "/y2logRPM ; " +
		     "for i in /tmp/update/[0-9]*/install ; do " +
		     "    [ -f \"$i/update.tar.gz\" ] && /bin/tar -zxf \"$i/update.tar.gz\" ; " +
		     "    rpm -Uv $i/*.rpm 2 >> " + Directory::logdir + "/y2logRPM ; " +
		     "    [ -f \"$i/update.post\" ] && /bin/chmod +x \"$i/update.post\" && \"$i/update.post\" \"$i\" ; " +
		     "done");
    }

    global define void DriverUpdate2 ()
    {
	list<string> updatefiles = (list<string>)WFM::Read (.local.dir, ["/update", []]);
	if (size (updatefiles) <= 0)
	    return;

	// run update.post2 scripts
	SCR::Execute(.target.bash,
		     "cd / ; " +
		     "for i in /tmp/update/[0-9]*/install ; do " +
		     "    [ -f \"$i/update.post2\" ] && /bin/chmod +x \"$i/update.post2\" && \"$i/update.post2\" \"$i\" ; " +
		     "done");

	// remove driver update dir
	SCR::Execute(.target.bash, "/bin/rm -rf /tmp/update");
    }
}
