/* Copyright (c) Oracle Corporation 1992.  All Rights Reserved */

/**************************************************************************** 
  NAME
    rdbms71.ins - Windows V3 installation script for the Personal
		  Oracle7 RDBMS.

  DESCRIPTION
    This script installs the Personal Oracle7 RDBMS by copying the appropriate
    files and optionally creating a new database by using a "seed" database.

  OWNER
    Tony Rodgers

  MODIFIED    DD-MMM-YY Reason
   LMurphy     11/29/94 - modified NT RDBMS script for Personal Oracle7
   syau        07/01/94 - 7.1.3
    HA!        04/28/94 - 7.1.2 and 3.0.10.2
   Hartenstine 04/20/93 - WIN_NT: Adapt to Windows NT
    Colello    10/09/92 - DESKTOP: copy demo and doc files AND add
			     DBA_AUTHORIZATION
    trodgers  01-APR-92 Created.
*****************************************************************************/
{
  /************************************************************************** 
	    Start main logic...                               
   **************************************************************************/
  if (doit)
    {
      ins_ratchet = "7.1.4.1.0C";

      execute("%installer_home%\windows.ins");

      install(winrsf70);
      install(winrsf71);
      install(win32rsf71);
      install(windbhlp71);

      ui_product(product_label);             

      permit_retry_operations = TRUE;        

/*
      if (registered("winrdbms70"))          
      {
	if (upgrade)
	{
	  ui_action(instantiate(moving_files));       
	  permit_retry_operations = FALSE;

	  ora_files = files("%RDBMS70%\*.ora");
	  while (not(empty(ora_files)))
	  {
	    ora_file = file_name(first(ora_files));
	    { move_file("%RDBMS70%\%ora_file%","%RDBMS71%\%ora_file%"); }
	    [ 'WRITE_ERROR, 'PERMISSION_DENIED, 'OS_ERROR:
	      signal('FAILURE, "Upgrade terminated. Can't move database and log files from %RDBMS70% to %RDBMS71% (identical filenames).");
	    ]
	    ora_files = rest(ora_files);
	  }
	  permit_retry_operations = TRUE;

	}
	copy(deinstl70);
      }
*/

      ui_action(instantiate(installing_scripts));
      copy(deinstl);

      ui_action(instantiate(installing_executables));    
      copy(exec);
      copy(bin);
      copy(doc);

      ui_action(instantiate(installing_dlls));
      copy(dll, nls_abbreviation);
      {
      if (bundle_name == P_O7_E)
	enterprise_install = TRUE;
      else
        enterprise_install = FALSE;
      }
      [ 'UNBOUND_VARIABLE: enterprise_install = FALSE; ]
      if (enterprise_install)
	dll_opt = "DYW";
      if (not(enterprise_install))
        dll_opt = "DNW";
      copy(dllopt, dll_opt);

/* LMurphy - version check files going into Windows system directory */
      destination = first(group_files(sys));
      source = implode(list(product_home, product_location(current_product),
				file_name(destination)), "\");
      pathify(source);
      source_version = windows_file_version(source);
      {
	if ((not(exists(destination))) ||
		(windows_earlier_version(destination,source_version)))
		signal('FILE_NOT_FOUND);
      }
      [ 
	'FILE_NOT_FOUND: continue();
	'DEFAULT: copy_file(source, destination);
      ]

      if (update_sndevnts)
	copy(drv);

      ui_action(instantiate(installing_oci));
      copy(oci);


      ui_action(instantiate(installing_admin));
      copy(ini);
      copy(dbs);      
      copy(admin);

      ui_action(instantiate(installing_msg));
      copy(msg, nls_abbreviation);
	 
      ui_action(instantiate(installing_msg));
      copy(plmsg, nls_abbreviation);     

      if (set_rdbms71)
      {
	ui_action(instantiate(modifying_config));
	modify("RDBMS71",rdbms71,ora_config, "Oracle");
      }

      if (set_rdbms71_poracle)
      {
	ui_action(instantiate(modifying_config));
	modify("RDBMS71_PORACLE",rdbms71_poracle,ora_config, "Oracle");
      }

      if (set_rdbms71_control)
      {
	ui_action(instantiate(modifying_config));
	modify("RDBMS71_CONTROL",rdbms71_control,ora_config, "Oracle");
      }
      if (set_rdbms71_archive)
      {
	ui_action(instantiate(modifying_config));
	modify("RDBMS71_ARCHIVE",rdbms71_archive,ora_config, "Oracle");
      }
      if (set_vs10)
      {
	ui_action(instantiate(modifying_config));
	modify("VS10",vs10,ora_config,"Oracle");
      }
      if (set_local)
      {
	ui_action(instantiate(modifying_config));
	modify("LOCAL",local,ora_config,"Oracle");
      }
      if (set_sqlnet_dbname)
      {
	ui_action(instantiate(modifying_config));
	modify("SQLNET DBNAME oracle7",sqlnet_dbname,ora_config,"Oracle");
      }
      if (set_plsql21)
      {
	ui_action(instantiate(modifying_config));
	modify("PLSQL21",plsql21,ora_config,"Oracle");
      }

/* create vs10.ini */
     modify("DEFAULTSRV",defaultsrv,vs10_ini,"CONFIGURATION_DETAILS");
     modify("DEFAULTCONFIG",defaultconfig,vs10_ini,"CONFIGURATION_DETAILS");
     modify("HOST",host,vs10_ini,"LOGON");
     modify("DFT_TBLSPACE",dft_tblspace,vs10_ini,"UMAN");
     modify("TMP_TBLSPACE",tmp_tblspace,vs10_ini,"UMAN");

     if (set_password)
     {
	ui_action(instantiate(setting_password));
	permit_retry_operations = FALSE;

/* Start Password Manager */
	{
		spawn("%ORACLE_HOME%\bin\vsdpw.exe PASSWORD=%dba_password%", 'MINIMIZE);
	}
	[ 'NO_RESPONSE: continue();
	  'INVALID_FILE_NAME, 'OS_ERROR: information_dialog(pwm_err);
	]
      }



      if (install_seed_database)
      {
	ui_action(instantiate(installing_seed));
	copy(plseed);

	/* Set password bypass when starting database */
	modify("DBA_AUTHORIZATION","bypass",ora_config,"Oracle");
	
	/* Startup Database by running a script on SQL*DBA */    
	ui_action(instantiate(starting_up));
	sqldba_run = TRUE;

	{
	spawn("%ORACLE_HOME%\bin\sqldba16.exe COMMAND=@%ORACLE_HOME%\DBS\install2.sql", 'MINIMIZE);
	}
	[ 'NO_RESPONSE: continue();
	  'INVALID_FILE_NAME, 'OS_ERROR: 
	  {
		sqldba_run = FALSE;
		information_dialog(sqldba_err);
	  }
	]
/* Check for errors in build.log */	
	err_seen = FALSE;
	{
	ora_err = translate("ORA", "%RDBMS71%\TRACE\build.log", "-");
	err_seen=TRUE;
	information_dialog(sqldba_fail);	
	}
	[
	 'UNBOUND_ENVIRONMENT_VARIABLE: continue();
	 'OS_ERROR, 'READ_ERROR, 'INVALID_FILE_NAME, 'DEFAULT:
	 {
		err_seen=TRUE;
		information_dialog(no_build_log);
	 }
	]
	{
	if (not(err_seen))
	{
		dba_err = translate("DBA", "%RDBMS71%\TRACE\build.log", "-");
		err_seen=TRUE;
		information_dialog(sqldba_fail);	
	}
	}
	[
	 'UNBOUND_ENVIRONMENT_VARIABLE: continue();
	 'OS_ERROR, 'READ_ERROR, 'INVALID_FILE_NAME:
	 {
		err_seen=TRUE;
		information_dialog(no_build_log);
	 }
	]
	{
	if (not(err_seen))
	{
		inst_err = translate("INST", "%RDBMS71%\TRACE\build.log", "-");
		err_seen=TRUE;
		information_dialog(sqldba_fail);	
	}
	}
	[
	 'UNBOUND_ENVIRONMENT_VARIABLE: continue();
	 'OS_ERROR, 'READ_ERROR, 'INVALID_FILE_NAME:
		information_dialog(no_build_log);
	]
	if (sqldba_run)
	{
		p7inst_var = "killicon";
		ora_shutdown = execute("%curr_dir%\p7inst.vrf");
	}
	modify("DBA_AUTHORIZATION","",ora_config,"Oracle");
        permit_retry_operations = TRUE;	
      }
      
      ui_action(instantiate(registering));
	register(current_product, comment);
      if (member(selected_products,current_product))
	reference(current_product);

      reference(winrsf70, current_product);
      reference(winrsf71, current_product);
      reference(win32rsf71, current_product);
      { reference(windbhlp71, current_product); }
      [ 'UNREGISTERED_PRODUCT: continue(); ]

      permit_retry_operations = FALSE;
    }
}
