/* Copyright (c) Oracle Corporation 1995.  All Rights Reserved */

/*******************************************************************************
  NAME
    toolsins.usr - External script for Tools Products' Installation scripts

  DESCRIPTION
    This external script is a Library of Routines (like Functions/Procedures).
    Each Routine is a block of code that is being used by more than one
    Installer script.  Each routine is uniquely identified by a global variable
    that needs to be set by the product script calling this script, and a roman
    numeral (for ease of locating the desired Routine).

    Following is a list of all the routines in this Library:
    I.     REGISTER_REFERENCE_PRODUCT
         Register, and Reference the product
         (used in all ins scripts)
    II.   REFERENCE_COMPONENTS of the PARENT
          (used by Parent scripts only)
    III.     INSTALL_COMPONENTS
         Install all the components of the PARENT
         (used by Parent scripts only)
    IV. CREATE_BOOKSHELVES
         Create Bookshelves for Online Docs
    V.  INSTALL_DEPENDENCIES
          Install dependencies based on the dependency_list created.
          (Generally only used by parent scripts)
    VI.   INSTALL_REQUIRED_COMPONENTS
         Currently only used by the Developer - Demos product
         to install all of the product dependencies.
    VII.  MODIFY_ENVIRONMENT
         Modify Registry/CONFIG.ORA for product DEMOS variables

  OWNER
    Amanda Shenon

  MODIFIED    MM/DD/YY    REASON
  aharriso  01/02/96    Added FILE_NOT_FOUND handler for TRANSLATE in Win32 scripts.
  aharriso  08/29/95    Added install_dependencies.
   rbansal  08/07/95    Created
********************************************************************************/

{
/********************************************************************
I.        Register, and Reference the product
*********************************************************************/
    if (EXECUTE_SCRIPT == "REGISTER_REFERENCE_PRODUCT")
    {
        /*******************
        Register the product
        ********************/
        ui_product(instantiate(display_product_label));
        ui_action(instantiate(install_register));
        register(current_product);

        /********************
        Reference the product
        *********************/
        reference(current_product);

        remove(delold);                                                      /* remove any outdated files if install was successful */

        return(0);
    }
/********************************************************************/

/********************************************************************
II.        Reference all the components of the PARENT
*********************************************************************/
    if (EXECUTE_SCRIPT == "REFERENCE_COMPONENTS")
    {
        if(parent_in_control)
        {
            /*********************
            Reference child products
            **********************/
            while(not(empty(child_products_to_reference)))
            {
                current_child_to_reference = first(child_products_to_reference);
                if (operating_system == "nt")
                {
                   if ((osVer == "3.51") && (current_child_to_reference == "w32frunw60"))
                   {
                      child_products_to_reference = rest(child_products_to_reference);
                   }
                   else
                   {
                      {reference(current_child_to_reference,product_parent(current_child_to_reference));}
                      ['UNREGISTERED_PRODUCT: continue();]
                      child_products_to_reference = rest(child_products_to_reference);
                   }
                }
                else
                {
                   {reference(current_child_to_reference,product_parent(current_child_to_reference));}
                   ['UNREGISTERED_PRODUCT: continue();]
                   child_products_to_reference = rest(child_products_to_reference);
                }
            }
        }
       return(0);
    }

/********************************************************************/

/********************************************************************
III.        Install all the components of the PARENT
*********************************************************************/
    if (EXECUTE_SCRIPT == "INSTALL_COMPONENTS")
    {
        if(parent_in_control)
        {
            /*********************
            Install child products
            **********************/
            ui_product(instantiate(display_product_label));
            while(not(empty(child_products_to_install)))
            {
                install(first(child_products_to_install));
                child_products_to_install = rest(child_products_to_install);
            }
            /*********************/
        }
        else
        {
            while(not(empty(selected_components_list)))
            {
                install(first(selected_components_list));
                selected_components_list = rest(selected_components_list);
            }
        }

        return(0);
    }

/********************************************************************/

/********************************************************************
IV.    Create Bookshelves for online Doc(s)
*********************************************************************/
    if (EXECUTE_SCRIPT == "CREATE_BOOKSHELVES")
    {
        {
            space_char = " ";
            quote_mark = quotation_mark;
            modify_bookshelves = FALSE;
            revised_bookshelves_list = list();
            {BOOK_LOC = translate("OB22", ora_config, "BOOK22");}
            [
                'UNBOUND_ENVIRONMENT_VARIABLE, 'FILE_NOT_FOUND:
                {BOOK_LOC = translate("OB22", ora_config, "BRUN22");}
                [
                    'UNBOUND_ENVIRONMENT_VARIABLE, 'FILE_NOT_FOUND:
                    {BOOK_LOC = translate("OB22", ora_config, "Oracle");}
                    ['UNBOUND_ENVIRONMENT_VARIABLE, 'FILE_NOT_FOUND: signal('UNBOUND_ENVIRONMENT_VARIABLE);]
                ]
            ]
            prefs_file = "%BOOK_LOC%%dir_separator%prefs.ora";
            if(not(exists(prefs_file)))
                prefs_file = "%BOOK_LOC%%dir_separator%prefs.new";

            {
                bookshelves_var = translate("hr.bookshelves", prefs_file, " =");    /* get hr.bookshelves variable from prefs_file, " =" means ignore spaces before =, but spaces after = are significant */
                bookshelves_list = explode(bookshelves_var, ")(,");
                while(not(empty(bookshelves_list)))                                    /* re-populate a new list after removing the leading space */
                {
                    extract(bookshelves_list, space_char);
                    next_bookshelf = first(bookshelves_list);
                    next_bookshelf = replace(next_bookshelf, " %quote_mark%", "%quote_mark%");     /* remove the leading space */
                    add(revised_bookshelves_list, next_bookshelf);
                    bookshelves_list = rest(bookshelves_list);
                }

                if(not(member(revised_bookshelves_list, bookshelf_var)))            /* do not add the bookshelf string if it's already there */
                {
                    add(revised_bookshelves_list, bookshelf_var);

                    bookshelves_var = implode(revised_bookshelves_list, ", ");
                    shelves_var = " (%bookshelves_var%)";
                    modify_bookshelves = TRUE;
                }

                if(modify_bookshelves)
                    modify("hr.bookshelves ", shelves_var, prefs_file);
            }
            ['UNBOUND_ENVIRONMENT_VARIABLE, 'FILE_NOT_FOUND: modify("hr.bookshelves ", bookshelf_var, prefs_file);]

            modify(bs_prefs_ora_var, bs_var, prefs_file);
            modify(id_prefs_ora_var, id_var, prefs_file);
        }
        ['UNBOUND_ENVIRONMENT_VARIABLE, 'INVALID_FILE_NAME, 'FILE_NOT_FOUND: continue();]

        return(0);
    }
/********************************************************************/

/********************************************************************
V.     INSTALL_DEPENDENCIES
          Install dependencies based on the dependency_list created.
*********************************************************************/
    if (EXECUTE_SCRIPT == "INSTALL_DEPENDENCIES")
    {
        ui_product(instantiate(display_product_label));
        while(not(empty(install_dependency_list)))
        {
            next_dependency = first(install_dependency_list);
            install_dependency_list = rest(install_dependency_list);

            install(next_dependency);
        }
    }
/********************************************************************/

/********************************************************************
VI.     INSTALL_REQUIRED_COMPONENTS
          Install required component products based on the
          install_component_list created.
*********************************************************************/
    if (EXECUTE_SCRIPT == "INSTALL_REQUIRED_COMPONENTS")
    {
        ui_product(instantiate(display_product_label));
        while(not(empty(install_component_list)))
        {
            current_component = first(install_component_list);
            install_component_list = rest(install_component_list);

               install(current_component);
        }
    }
/********************************************************************/
/****************************** 10/10/95 ***********************************************
VII.    Modify REGISTRY/CONFIG.ORA for product DEMOS variables
    Following variables need to be set by the product scripts:
    ini_var (type STRING)
         Path variable in REGISTRY/CONFIG.ORA. For example, FORMS50_PATH for FORMS DEMOS.
    ini_path_list (type LIST)
         List of all the paths required for DEMOS. For example, %FORMS50%\PLSQLLIB
         for FORMS DEMOS
    section_heading (type STRING)
         Section Heading in REGISTRY/CONFIG.ORA
    implode_explode_delimiter (type STRING)
         Delimiter for implode/explode functions (set to ";" in USER.AVF). If any other
         value, needs to be set, for example, "," for REGISTERED_LIBRARIES variable
         in REGISTRY/CONFIG.ORA
    old_section_heading OPTIONAL (type STRING)
         if the section heading needs to be different than the previous release, set
         this variable to the section heading of the previous release
    1) Add ini_var variable in REGISTRY/CONFIG.ORA if it's not there already,
    2) Modify REGISTRY/CONFIG.ORA if ini_var is under old_section_heading to move it to
       appropriate section
    3) Modify ini_var variable in REGISTRY/CONFIG.ORA if it's already there, and doesn't
       have any/all of paths in ini_path_list
****************************************************************************************/


    if (EXECUTE_SCRIPT == "MODIFY_ENVIRONMENT")
    {
           temp_file = "%installer_home%%dir_separator%varfile.tmp"; /* create a temporary file, varfile.tmp, to write the INI variable(s) */
           if (not(exists(temp_file)))
              create_file(temp_file);
            {
            paths_in_ini_var = list();
            modify_ini_var = FALSE;
            ini_path_var = translate(ini_var,temp_file);           /* if ini_var found in temp_file, it means some other product has already populated it */
            paths_in_ini_var = explode(ini_path_var, implode_explode_delimiter);
            }

            [
               'OS_ERROR,'INVALID_FILE_NAME,
                'PERMISSION_DENIED,'UNBOUND_ENVIRONMENT_VARIABLE, 'FILE_NOT_FOUND:continue();
            ]
            {
                   ini_path_var = translate(ini_var, ora_config, section_heading);                  /* if ini_var found in ora_config, it means some other product has already populated it */
                   paths_in_ini_var = explode(ini_path_var, implode_explode_delimiter);
            }
            [
                'OS_ERROR,'INVALID_FILE_NAME,
                    'PERMISSION_DENIED,'UNBOUND_ENVIRONMENT_VARIABLE, 'FILE_NOT_FOUND:
                   {
                    if(OLD_SECTION_HEADING_EXISTS)
                    {
                           ini_path_var = translate(ini_var, ora_config, old_section_heading);
                           paths_in_ini_var = explode(ini_path_var, implode_explode_delimiter);
                        modify(ini_var, "", ora_config, old_section_heading);
                    }
                    else
                        signal('UNBOUND_ENVIRONMENT_VARIABLE);
            }
                [
                    'OS_ERROR,'INVALID_FILE_NAME,
                        'PERMISSION_DENIED,'UNBOUND_ENVIRONMENT_VARIABLE, 'FILE_NOT_FOUND:
                    continue();
            ]
        ]
        while(not(empty(ini_path_list)))
        {
            ini_path_to_add = first(ini_path_list);
            if(not(member(paths_in_ini_var, ini_path_to_add)))
            {
                modify_ini_var = TRUE;
                add(paths_in_ini_var, ini_path_to_add);                        /* ini_var does not have the required path, add it to ini_var */
            }

            ini_path_list = rest(ini_path_list);
        }

        if(modify_ini_var)
        {
            ini_path_var = implode(paths_in_ini_var, implode_explode_delimiter);
            modify(ini_var, ini_path_var, ora_config);                        /* write the variable to ora_config */
        }

        return(modify_ini_var);
    }
/*******************************************************************************************/
        /****************

    ***********************/
/************************************************************************************/

}

