#!/bin/bash

. ./param_bash.ini

clear
if [ "$FTP_SERVER" == "" ] ; then
    INFORM "The parameter FTP_SERVER is not defined"
    INFORM "Do you want me to find the best ftp for you?"
    CONFIRM
    if [ "$?" = "0" ] ; then
        bash check_best_ftp
        . ./param_bash.ini
    else
       ERROR "Set the parameter FTP_SERVER in param_bash.ini and rerun this step"
    fi
    if [ "$FTP_SERVER" == "" ] ; then
        ERROR "No FTP_SERVER where found in param_bash.ini file please set the parameter and rerun this step" "$0"
    fi
fi

test $FTP_TEMPL_DB
if [ "$?" != "0" ] ; then
        ERROR "Unsupported OS" "$0"
fi
if [ "$FTP_TEMPL_DB" = "NA" ] ; then
        ERROR "DB Installation is not supported on this platform" "$0"
fi

START "Download Oracle DB" "$0"

echo -n "Please enter the target download directory name [$IKIT_FTP_DIR]: "
read ans
if [ "$ans" != "" ] ; then
	IKIT_FTP_DIR=$ans
fi
	
if [ ! -d $IKIT_FTP_DIR ] ; then	
	ERROR "Directory $IKIT_FTP_DIR does not exist" "$0"
fi
Update_params "IKIT_FTP_DIR" "${IKIT_FTP_DIR}"

echo -n "Please enter you email [$MAIL]: "
read ans

if [ "$ans" != "" ] ; then
	MAIL=$ans
fi
Update_params "MAIL" "${MAIL}"

bash -f main_ftp_proc.bash "$FTP_TEMPL_DB" "db" "$IKIT_FTP_DIR" "$MAIL"
echo "The ftp now runs, please wait."
INFORM "When the ftp will be finished, e-mail will be sent to preliminary mentioned "
INFORM "address and the empty file ROSETTA_DB_FTP_COMPLETED will be created in the current directory."
echo ""

DONE "Please check the FTP additional log files in the $IKIT_DIR/log directory" "$0"
