#!/bin/bash

. ./param_bash.ini

if [ ! -w /etc/passwd ] ; then
   ERROR "Please run the script as root user only" "ikit_2_6"
fi
##########create /<mount>/oradata directory incase of ALL or DB_ONLY#####################
if [ "$INST_TYPE" = "DB_ONLY" -o "$INST_TYPE" = "ALL" ] ; then 
    echo ""
    INFORM "Rosetta DB files can be installed on three different locations,"
    INFORM "one for archiving, one for logs and system files and one for data files"
    echo ""
    role=( archving sysandredo datafiles )
    rolename=( IKIT_DB_ARCH_DIR IKIT_DB_SYS_DIR IKIT_DB_DATA_DIR )
    count=0
    for disk in ${IKIT_DB_ARCH_DIR} ${IKIT_DB_SYS_DIR} ${IKIT_DB_DATA_DIR}
    do
        echo -n "Please enter the database disk location for ${role[$count]} [$disk]: "
        read ans
	if [ "$ans" != "" ] ; then	
            Update_params "${rolename[$count]}" "${ans}"	
            eval ${rolename[$count]}=${ans}
	fi
        let count++
    done
    for disk in ${IKIT_DB_ARCH_DIR} ${IKIT_DB_SYS_DIR} ${IKIT_DB_DATA_DIR}
    do 
	if [ ! -d ${disk}/oradata ] ; then
            mkdir -p ${disk}/oradata
            chown $ORACLE_USER:$ORACLE_GROUP ${disk}/oradata
            if [ -d ${disk}/oradata ] ; then
                INFORM "Directory ${disk}/oradata was created successfully"
            fi
	else
            INFORM "Directory ${disk}/oradata already exists"
	fi
    done
fi
########################creating /exlibris/tmp#################################
if [ ! -d ${TMP} ] ; then
    mkdir -p ${TMP}
    chmod 777 ${TMP} > /dev/null 2>&1
    if [ -d ${TMP} ] ; then
        INFORM "Directory ${TMP} successfully created."
    fi
else
    chmod 777 ${TMP} > /dev/null 2>&1
    INFORM "Directory ${TMP} already exist."
fi
########################creating /exlibris/startup#############################
if [ ! -d ${BASE}/startup ] ; then
    mkdir -p ${BASE}/startup
    chown ${ORACLE_USER}:${ORACLE_GROUP} ${BASE}/startup > /dev/null 2>&1
    if [ -d ${TMP} ] ; then
        INFORM "Directory ${BASE}/startup successfully created."
    fi
else
    chmod 755 ${BASE}/startup > /dev/null 2>&1
    INFORM "Directory ${BASE}/startup already exist."
fi
########################creating /exlibris/app#################################
if [ ! -d ${BASE}/app ] ; then
    mkdir -p ${BASE}/app
    chown ${ORACLE_USER}:${ORACLE_GROUP} ${BASE}/app > /dev/null 2>&1
    if [ -d ${BASE}/app ] ; then
        INFORM "Directory ${BASE}/app successfully created."
    fi
else
    INFORM "Directory ${BASE}/app already exist."
fi
########################creating /exlibris/app/oracle##########################
if [ ! -d ${BASE}/app/oracle ] ; then
    mkdir -p ${BASE}/app/oracle
    chown ${ORACLE_USER}:${ORACLE_GROUP} ${ORACLE_BASE} > /dev/null 2>&1
    if [ -d ${ORACLE_BASE} ] ; then
        INFORM "Directory ${ORACLE_BASE} successfully created."
    fi
else
    INFORM "Directory ${BASE}/app/oracle already exist."
fi
########################creating /exlibris/app/oracle/product##################
if [ ! -d ${BASE}/app/oracle/product ] ; then
    mkdir -p ${BASE}/app/oracle/product
    chown ${ORACLE_USER}:${ORACLE_GROUP} ${ORACLE_BASE}/product > /dev/null 2>&1
    if [ -d ${ORACLE_BASE}/product ] ; then
        INFORM "Directory ${ORACLE_BASE}/product successfully created."
    fi
else
    INFORM "Directory ${BASE}/app/oracle/product already exist."
fi
########################creating oratab directory##################
if [ ! -f $ORATAB ] ; then
    if [ "$OS" = "SunOS" ] ; then
        mkdir -p /var/opt/oracle > /dev/null 2>&1
    fi
    touch $ORATAB
    chown $ORACLE_USER:$ORACLE_GROUP  $ORATAB > /dev/null 2>&1
else
    chown $ORACLE_USER:$ORACLE_GROUP $ORATAB >  /dev/null 2>&1
fi
if [ ! -f $ORAINST ] ; then
    touch $ORAINST
fi
chown $ORACLE_USER:$ORACLE_GROUP $ORAINST >  /dev/null 2>&1

chmod -R 777 $IKIT_FTP_DIR >> $gen_log 2>&1
chmod -R 777 $IKIT_DIR >> $gen_log 2>&1
if [ -f /tmp/is_user ] ; then 
	rm -f /tmp/is_user > /dev/null 2>&1
fi
exit 0      
###############################################################################:
