// Symantec ScriptBlocking Authenticated File
// 93059BE3-B7E4-444D-80B3-6B944F702866


function Createtmpfolder()
{
	fso = WScript.CreateObject("Scripting.FileSystemObject")
	try
	{
		fso.CreateFolder("\\tmp");
	}
	catch(Exception)
	{
		WScript.echo("tmp directory already exists, using tmp ...");
	}

	fso=null;
}

function GetModuleFilePath()
{
	var WshShell = WScript.CreateObject("WScript.Shell");
	var str=WScript.ScriptFullName ;
	var ss=str.split("\\");
	var str1=ss[0]+"\\";

	for ( i=1 ; i<ss.length-1 ; i++)
	{
		str1=str1+ss[i]+"\\";
	}
	WshShell = null;
	return str1;
}

function GetRootPath()
{
	var WshShell = WScript.CreateObject("WScript.Shell");
	var str=WScript.ScriptFullName ;
	var ss=str.split("\\");
	var str1=ss[0];
	WshShell = null;
	return str1;
}

//public static void main(String str)
//{
// will be of help
//	WScript.echo ("Please enter your name:")
//	var name = WScript.StdIn.ReadLine();
//	WScript.echo("Hi " + name);

	Createtmpfolder();
	var szPath = GetModuleFilePath();

	var fso = WScript.CreateObject("Scripting.FileSystemObject");

	var f=fso.GetFolder(szPath);				

	var str = GetRootPath();

	var WshShell = WScript.CreateObject("WScript.Shell");


	var int = WshShell.run(f.ShortPath+"\\gnu\\bash.exe "+f.ShortPath+"\\stage1.sh",1,true);
		if (int == 21 )
		{
			WScript.echo("Floppy Creation Aborted");
			WScript.echo("Please refer to the README or the documentation for further instructions.");
		
			WshShell = null;
			fso = null;

			WScript.quit(0);
		}

		if (int == 11 )
		{
			WScript.echo("Floppy Creation Aborted");
			WScript.echo("Please refer to the README or the documentation for further instructions.");

			WshShell = null;
			fso = null;

			WScript.quit(0);
		}
		if (int == 12 )
		{
			WScript.echo("Currently OSI does not support CustomerXchange installation")
			WScript.echo("Please refer to the README or the documentation for further instructions.");

			WshShell = null;
			fso = null;

			WScript.quit(0);
		}
	 

		if (int == 0 )		
		{
     				if (str == "" )
				{		
					WScript.echo("Click OK to begin creation of the kickstart floppy");
					WScript.echo("This will take a few minutes...");
//					var raw = WshShell.run(f.ShortPath+"\\gnu\\fdimage.exe "+f.ShortPath+".\\boot.img  a:",1,true);
					var raw = WshShell.run(f.ShortPath+"\\gnu\\rawwritewin.exe --write --copies 1 --drive A: "+f.ShortPath+".\\boot.img",1,true);
				}
				else 
				{
					WScript.echo("Click OK to begin creation of the kickstart floppy");
					WScript.echo("This will take a few minutes...");
//					var raw = WshShell.run(f.shortPath+"\\gnu\\fdimage.exe .\\boot.img  a:",1,true);
					var raw = WshShell.run(f.ShortPath+"\\gnu\\rawwritewin.exe --write --copies 1 --drive A: .\\boot.img",1,true);
					
				}
			
			if ( raw !=0 )
			{
         			WScript.echo("Error while dumping floppy Image");
				WScript.echo("Please refer to the README or the documentation for further instructions.");
				var f1=fso.GetFile(szPath+"\\boot.img");
				f1.Delete();
	
				WshShell = null;
				fso = null;

				WScript.quit(0);
			}
		
			
			
			var f1=fso.GetFile(szPath+"\\boot.img");
			f1.Delete();
	
			try
			{
		 			fso.CopyFile(szPath+"ks.cfg", "A:\\");
					fso.CopyFile(szPath+"syslinux.cfg", "A:\\");
			}
			catch(Exception)
			{
				WScript.echo("Error writing to the floppy ");
				WScript.echo("Please refer to the README or the documentation for further instructions.");
				
				WshShell = null;
				fso = null;

				WScript.quit(0);
			}
       	 
			WScript.echo("RedHat installation floppy created successfully.");  
			WScript.echo("Insert the floppy generated , in the floppy drive of the target server for WEBppliance.");
			WScript.echo("Restart the target server after inserting the floppy for installation of Webppliance for Linux.");
			WScript.echo("Please refer to the README or the documentation for further instructions.");

			WshShell = null;
			fso = null;

			WScript.quit(0);

		}
		else
		{
			WScript.echo("*** Error while dumping floppy image. Exiting");
			WScript.echo("Please refer to the README or the documentation for further instructions.");

			WshShell = null;
			fso = null;

			WScript.quit(0);
	
		}

//}
