#!/bin/bash

. ./param_bash.ini

clear
START "Create required directories as root user" "ikit_2_6"

if [ ! -w /etc/passwd ] ; then
   ERROR "Please run the script as root user only" "ikit_2_6"
fi
PROMPT_FOR_INST_TYPE()
{
    echo -n "Insert Installation type [ ALL, SW_ONLY, DB_ONLY ]:"
    read ans
    if [ "$ans" != "ALL" -a "$ans" != "SW_ONLY" -a "$ans" != "DB_ONLY" ] ; then
        INFORM "Invalid choice..."
        INFORM "Please insert one of the above: ALL, SW_ONLY, DB_ONLY"
        PROMPT_FOR_INST_TYPE
    else
        INST_TYPE=$ans
        Update_params "INST_TYPE" "$ans"
    fi
}

INFORM "This step will create required directories"
INFORM "choose the installation type from the following:"
INFORM "ALL - will create all required directories (ALL IN ONE installation)"
INFORM "SW_ONLY - will create required directories for Rosetta SW and Oracle client (Data Base on remote machine)"
INFORM "DB_ONLY - will create required directories for Oracle client and DB (Rosetta on remote machine)"
PROMPT_FOR_INST_TYPE
if [ "${INST_TYPE}" = "SW_ONLY" ] ; then
    INFORM "Do You want to use default Oracle Users/Passwd?"
    CONFIRM
    if [ "$?" = "1" ] ; then
        INFORM "Do you want me to read the installation parameters from def.dat file?"
        CONFIRM
        if [ "$?" == "0" ] ; then
                export FILE_INPUT="Y"
        fi
        Update_params "PROMPT_FOR_ORA_PASS" "Y"
        if [ "$FILE_INPUT" == "Y" ] ; then
            EXL_ADMIN_PASSWD=`cat def.dat | grep EXL_ADMIN_PASSWD | cut -d'"' -f2`
            EXL_PASSWD=`cat def.dat | grep EXL_PASSWD | cut -d'"' -f2`
            CTXSYS_PASSWD=`cat def.dat | grep CTXSYS_PASSWD | cut -d'"' -f2`
        else
            echo -n "Insert Oracle EXL_ADNIN Passwd [ EXL_ADMIN ]: "
            read ans
            if [ "$ans" != "" ] ; then
                EXL_ADMIN_PASSWD=$ans
            else
                EXL_ADMIN_PASSWD=EXL_ADMIN
            fi
            echo -n "Insert Oracle EXL Passwd [ EXL ]: "
            read ans
            if [ "$ans" != "" ] ; then
                EXL_PASSWD=$ans
            else
                EXL_PASSWD=EXL
            fi
            echo -n "Insert Oracle CTXSYS Passwd [ CTXSYS ]: "
            read ans
            if [ "$ans" != "" ] ; then
                CTXSYS_PASSWD=$ans
            else
                CTXSYS_PASSWD=CTXSYS
            fi
        fi
        Update_params "EXL_ADMIN_PASSWD" "$EXL_ADMIN_PASSWD"
        Update_params "EXL_PASSWD" "$EXL_PASSWD"
        Update_params "CTXSYS_PASSWD" "$CTXSYS_PASSWD"
    fi
fi

if [ "${INST_TYPE}" != "DB_ONLY" ] ; then 
    bash create_dps_dirs.sh
    bash create_oracle_dirs.sh
fi

if [ "${INST_TYPE}" = "DB_ONLY" ] ; then 
    bash create_oracle_dirs.sh
fi

if [ "$?" != "0" ] ; then
    ERROR "Failed during creation of required directories" "ikit_2_6"
else
    INFORM "chmod 777 to $IKIT_DIR"
    chmod -R 777 $IKIT_DIR > /dev/null 2>&1
    DONE "The directories have been created in the disk /exlibris" "ikit_2_6"
fi
###############################################################################
