Rem  Copyright (c) Oracle Corporation 2014. All Rights Reserved.
Rem
Rem    NAME
Rem      ords_install_cdb.sql
Rem
Rem    DESCRIPTION
Rem      This script installs Oracle REST Data Services into a container database 
Rem      using catcon.pl (perl) script.
Rem     
Rem
Rem    NOTES
Rem      Do not invoke this script directly.  If you are doing a manual installation, use ords_manual_install.sql
Rem
Rem      Assumes the SYS user is connected to the root container (CDB$ROOT). 
Rem      Must be run locally to the database and the ORACLE_HOME environment variable must be set.
Rem
Rem    REQUIREMENTS
Rem      - Oracle Database 12.1 or later
Rem
Rem    Arguments:
Rem      1  : Default tablespace name for ORDS schema
Rem      2  : Temporary tablespace name for ORDS schema
Rem      3  : Default tablespace name for ORDS Public user
Rem      4  : Temporary tablespace name for ORDS Public user
Rem      5  : Path of ORDS log file 
Rem
Rem
Rem    MODIFIED   (MM/DD/YYYY)
Rem      epaglina   05/18/2015 Verifies that the user-specified 
Rem                            default/temporary tablespaces exist in
Rem                            the CDB and the PDBs including PDB$SEED.
Rem                            Uses catcon.pl (perl script) to execute
Rem                            ORDS install scripts for each container.
Rem

whenever sqlerror exit

set define '^'
set verify off
set serveroutput on

define ORDS_DATATBS  = '^1'
define ORDS_TEMPTBS  = '^2'
define PUB_DATATBS   = '^3'
define PUB_TEMPTBS   = '^4'
define LOGFOLDER     = '^5'

-- check if the default and temporary tablespace exist in the pdbs
prompt
prompt Verifying tablespaces for CDB$ROOT


@@ords_verify_tablespace.sql ^ORDS_DATATBS ^ORDS_TEMPTBS ^PUB_DATATBS ^PUB_TEMPTBS
@@ords_verify_pdbs_tablespaces.sql ^ORDS_DATATBS ^ORDS_TEMPTBS ^PUB_DATATBS ^PUB_TEMPTBS

-- check pdb$seed for the existence of the default and temporary tablespaces
prompt
prompt Verifying tablespaces for PDB$SEED
prompt
alter session set container=PDB$SEED;

@@ords_verify_tablespace.sql ^ORDS_DATATBS ^ORDS_TEMPTBS ^PUB_DATATBS ^PUB_TEMPTBS
alter session set container=CDB$ROOT;

set termout off
column :orcl_home new_value ORACLE_HOME NOPRINT
variable orcl_home varchar2(255)
set termout on


begin
    sys.dbms_system.get_env('ORACLE_HOME',:orcl_home);
    if length(:orcl_home) = 0 then
        raise_application_error (-20021, 'ERROR: Cannot install Oracle REST Data Services. ' || 
                                         'ORACLE_HOME environment variable must be set. ' ||
                                         'Refer to Oracle documentation on setting ORACLE_HOME environment variable.');
    end if;
end;
/

whenever sqlerror continue

set termout off
select :orcl_home from sys.dual;
set termout on

prompt
prompt *********************************************************
prompt * Installing Oracle REST Data Services into Oracle 12c CDB and its PDBs
prompt *********************************************************
prompt

host ^ORACLE_HOME/perl/bin/perl -I ^ORACLE_HOME/rdbms/admin ^ORACLE_HOME/rdbms/admin/catcon.pl  -l ^LOGFOLDER -b ords_install_cdb ords_install.sql --p^ORDS_DATATBS --p^ORDS_TEMPTBS --p^PUB_DATATBS --p^PUB_TEMPTBS --p^LOGFOLDER --p^6

prompt
prompt *********************************************************
prompt * Log files for each container can be found in ^LOGFOLDER ords_install_cdb*.log
prompt *********************************************************
prompt
