/* Copyright (c) Oracle Corporation 1992, 1996.  All Rights Reserved */
/***************************************************************************
  NAME
    netc30.ins

  DESCRIPTION
    This script performs the installation tasks for the Win32 SQL*Net
    product.

  OWNER
    Etna Flores

  MODIFIED   DD-MMM-YY  Reason

  kpotter     3/98       version update for 805 EE
   dstiefel  05-Aug-96  Update for net30
   dstiefel  22-Feb-96  Merge NT/95
   ljiang    9/95       Modified for Easy Configuration
   dlau      07-AUG-95  Modified for SQLNET 2.2
 **************************************************************************/
{
  {
    if (doit)
    {
      /*
       * Just checking -- temporary fix for O8 beta 1  22-AUG-96
       */
    }
  }
  [ 'UNBOUND_VARIABLE: doit = TRUE; ]

  if (platform() == "nt") {
    execute("%installer_home%\services.vrf");
  }

  if (doit)
  {
    ins_ratchet = "8.0.5.0.0";

/* OCSM Compliance */
  {
    Win32_register_OCSM_product();
  }
  [
    'default: win32_ocsm_register_product();
  ]


  /* Register the groups in the map file and specify which should get
     copied over under the three OCSM installation modes. */
  win32_register_ocsm_group(deinstl,    'MAXMODE);
  win32_register_ocsm_group(tns,        'MAXMODE);
  win32_register_ocsm_group(ostns,      'MAXMODE);
  win32_register_ocsm_group(sample,     'MAXMODE);
  win32_register_ocsm_group(templates,  'MAXMODE);
  win32_register_ocsm_group(docs,       'MAXMODE);
  win32_register_ocsm_group(tnsapi,     'MAXMODE);
  win32_register_ocsm_group(msb,        'MAXMODE);

  win32_register_ocsm_group(deinstl,    'MEDMODE);
  win32_register_ocsm_group(tns,        'MEDMODE);
  win32_register_ocsm_group(ostns,      'MEDMODE);
  win32_register_ocsm_group(sample,     'MEDMODE);
  win32_register_ocsm_group(templates,  'MEDMODE);
  win32_register_ocsm_group(docs,       'MEDMODE);
  win32_register_ocsm_group(tnsapi,     'MEDMODE);
  win32_register_ocsm_group(msb,        'MEDMODE);

  win32_register_ocsm_group(deinstl,    'MINMODE);
  win32_register_ocsm_group(tns,        'MINMODE);
  win32_register_ocsm_group(ostns,      'MINMODE);
  win32_register_ocsm_group(sample,     'MINMODE);
  win32_register_ocsm_group(templates,  'MINMODE);
  win32_register_ocsm_group(docs,       'MINMODE);
  win32_register_ocsm_group(tnsapi,     'MINMODE);
  win32_register_ocsm_group(msb,        'MINMODE);


  /* Register product variables or keys created in the Windows registry by this INS script. */
  /* Associated with calls to: modify(...) later on in the code.                            */

  /* First, define the key and subkey. */
  okey    = "HKEY_LOCAL_MACHINE";
  osubkey = "SOFTWARE\ORACLE";

  win32_register_key(okey, osubkey, "NET80",   'REPLICATE);

/* end OCSM Compliance */

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

    /* INSTALLATION OF PRODUCT DEPENDENCIES */
    install(w32rsf80);

    /************* CONNECTION TO V7 DATABASE IN CURRENT HOME ******************************************/
    /* Install SQLNet AddOn v2.3.4 if PO7 7.3.3 or 7.3.4 RDBMS exists without a SQLNet AddOn (Server) */
    /* The rgstd_234 flag is defined in the netc80.vrf script and set to true when a                  */
    /* po7 rdbms database exists on the user's machine without a SQLNet AddOn (Server)                */
    /**************************************************************************************************/

    if (not(rgstd_234) && rgstd_734)
    {
                install(w32netclt23);
    }


    /**************************************************************************************************/

    /* Install the adapters whose flags have been set to TRUE in the .vrf script */
    if (install_tcp)
      install(tcp_prod);
    if (install_spx)
      install(spx_prod);
    if (install_nmp)                   /* In this release this always gets installed */
      install(nmp_prod);
    if (install_appc)                  /* In this release this never gets installed */
      install(appc_prod);

    /* FILE COPYING FOR NET8 CLIENT */
    ui_product(product_label);

    ui_action(instantiate(net2_install_tns));

      /* sqlnet_in_use is a boolean which it true until the copy(tns) command is succesful. */
      /* This is how we allow the user to stop services and/or applications using sqlnet and continue installing */
      sqlnet_in_use = TRUE;
      while(sqlnet_in_use)
      {
         write_error_occured = FALSE;
         { copy(tns); }
         [  'WRITE_ERROR:
            {
               /* If in silent mode signal an error to avoid an infinite loop. */
               if(silent_mode)
                  signal('CANCEL, app_prompt);

               information_dialog(instantiate(app_prompt), app_content, app_help);
               write_error_occured = TRUE;
               continue();
            }
         ]
         if(not(write_error_occured))
         {
            sqlnet_in_use = FALSE;
         }
      }

      if(platform() == "nt")
      {
         /* sqlnet_in_use is a boolean which it true until the copy(tns) command is succesful. */
         /* This is how we allow the user to stop services and/or applications using sqlnet and continue installing */
         sqlnet_in_use = TRUE;
         while(sqlnet_in_use)
         {
            write_error_occured = FALSE;
            { copy(ostns, "nt"); }
            [  'WRITE_ERROR:
               {
                  /* If in silent mode signal an error to avoid an infinite loop. */
                  if(silent_mode)
                     signal('CANCEL, app_prompt);

                  information_dialog(instantiate(app_prompt), app_content, app_help);
                  write_error_occured = TRUE;
                  continue();
               }
            ]
            if(not(write_error_occured))
            {
               sqlnet_in_use = FALSE;
            }
         }
      }
      else /* win95 */
      {
         /* sqlnet_in_use is a boolean which it true until the copy(tns) command is succesful. */
         /* This is how we allow the user to stop services and/or applications using sqlnet and continue installing */
         sqlnet_in_use = TRUE;
         while(sqlnet_in_use)
         {
            write_error_occured = FALSE;
            { copy(ostns, "95"); }
            [  'WRITE_ERROR:
               {
                  /* If in silent mode signal an error to avoid an infinite loop. */
                  if(silent_mode)
                     signal('CANCEL, app_prompt);

                  information_dialog(instantiate(app_prompt), app_content, app_help);
                  write_error_occured = TRUE;
                  continue();
               }
            ]
            if(not(write_error_occured))
            {
               sqlnet_in_use = FALSE;
            }
         }
      }


    tmp_path = explode("%ORACLE_HOME%", "\");

    oracle_home_drive = first(tmp_path);

    tmp_oracle_home = rest(tmp_path);

    new_oracle_home = implode(tmp_oracle_home, "\");

    ui_action(instantiate(net2_install_script));
    copy(deinstl, nls_abbreviation);

    ui_action(instantiate(net2_install_message));
    copy(msb, nls_abbreviation);

    ui_action(instantiate(net2_install_sample));
    copy(sample);

    /*** Config file detection and preservation ***/
    /* This code will first determine if tnsnames.ora and sqlnet.ora files exist
       from a sqlnet 2.x installation (in \O_home\network\admin).  If so, then if
       the same files don't exist at \O_home\net80\admin, then the files are copied
       to \O_home\net80\admin.  This way, *any* existing configuration files will
       be reside in ..\net80\admin before the copy statement.  By setting the variable
       overwrite_mode to 'NEVER before the copy statement, we ensure that the installer
       will never overwrite existing configuartion information. */

    old_tnsnames_file = instantiate("%ORACLE_HOME%\NETWORK\ADMIN\TNSNAMES.ORA");
    tnsnames_file = instantiate("%ORACLE_HOME%\NET80\ADMIN\TNSNAMES.ORA");
    old_sqlnet_file = instantiate("%ORACLE_HOME%\NETWORK\ADMIN\SQLNET.ORA");
    sqlnet_file = instantiate("%ORACLE_HOME%\NET80\ADMIN\SQLNET.ORA");

    {
     if(exists(old_tnsnames_file))
       if(not(exists(tnsnames_file)))
         copy_file(old_tnsnames_file, tnsnames_file);
    }
     [
      'DEFAULT: continue();
     ]

    {
     if(exists(old_sqlnet_file))
       if(not(exists(sqlnet_file)))
         copy_file(old_sqlnet_file, sqlnet_file);
    }
     [
      'DEFAULT: continue();
     ]

    /* At this point, any existing config files reside in ..\net80\admin */
    overwrite_mode = 'NEVER;
    copy(templates, "sqlnet");
    /* Now determine whether we are in a custom database situation (if we are running the db assistant
       then we are by definition).  If so, copy the special tnsnames.ora file which lacks two key
       entries (the db assistant will fill them in).  We will also do this in the migration situation,
       expecting the dbmig assistant to fill in the entries. */
    if (run_db_builder || run_db_migration)
       copy(templates, "tnscus");
    else
       copy(templates, "tnsnames");
    overwrite_mode = 'ALWAYS;

    ui_action(instantiate(net2_install_tnsapi));
    copy(tnsapi);

        copy(docs);

    change_directory("%ORACLE_HOME%");
/*
    move_file("%ORACLE_HOME%\NET80\NETCW\JDK102.EXE", "%ORACLE_HOME%\JDK102.EXE");
    {
     spawn("jdk102.exe -o");
    }
    remove_file("%ORACLE_HOME%\JDK102.EXE");
*/

    if (platform() == "win95")
    {
      move_file("%ORACLE_HOME%\net80\CFG\NT.PRD","%ORACLE_HOME%\net80\CFG\WIN95.PRD");
    }
    ['DEFAULT: continue(); ]

    if (platform() == "nt")
    {
      /* SERVICE INSTALLATION OCCURS HERE */
      /* If service already exists, delete it first. */
      {
       winnt_delete_service("Oracle%ORACLE_HOME_SERVICE%ClientCache80");
      }
       [
        'SERVICE_DOES_NOT_EXIST, 'INVALID_SERVICE_NAME, 'PERMISSION_DENIED, 'OS_ERROR : continue();
       ]

      /* Now create the service, which is Manual start and not initially started. */
      {
       winnt_create_service("%ORACLE_HOME%\BIN\ONRSD80.EXE",
                            "Oracle%ORACLE_HOME_SERVICE%ClientCache80");
      }
       [
        'PERMISSION_DENIED, 'OS_ERROR,
        'INVALID_SERVICE_NAME: signal('FAILURE, netc80_newservice_fail);
        'ALREADY_EXISTS, 'SERVICE_ALREADY_EXISTS: continue();
       ]

      /* modify registry to set message file path */
      ui_action(instantiate(modifying_config));
          modify("NET80", "%ORACLE_HOME%\NET80",ora_config,product_filename(current_product));

    } /* NT */
   else /* Win 95 */
    {
     /* set NET80 here in the registry */

     modify("NET80","%oracle_home%\net80", ora_config, (product_filename(current_product)));
    } /* Win 95 */

    /* Register Product and Dependencies */

    ui_action(instantiate(net2_register));
    register(current_product);
    if (member(selected_products,current_product))
      reference(current_product);

    if (registered("w32rsf80"))
      reference(w32rsf80, current_product);
    if (registered("w32tcp80"))
      reference(w32tcp80, current_product);
    if (registered("w32spx80"))
      reference(w32spx80, current_product);
    if (registered("w32nmp80"))
      reference(w32nmp80, current_product);
    if (platform() == "nt")
       if (registered("w32appc80"))
         reference(w32appc80, current_product);
  }
}
