#!/bin/sh

# Specify where the database resides
MYSQL=/usr/local/mysql/bin/mysql
HOST=database.mysql.net
USER=user
PASSWORD=pswd
# the databse name
DB=RIPE
LOG=DBmake.$$.log


# Directory where the object files reside
OBJDIR=/tmp/obj_dir
UNZIP1='gzip -cd'

# Name of the porperties file
PROPERTIES=.properties

echo
echo "Starting to make a database"
echo "***************************"
echo 
echo "Database: ${DB}@${HOST}"
echo "User: $USER"
echo "Password: $PASSWORD"
echo ""
echo "Gzip=" ${UNZIP1}
echo "Objects in " ${OBJDIR}
echo "Properties=" ${PROPERTIES}
echo "Logging results in $LOG"
echo "***************************"
echo
echo "Accept and continue?"

read ANS dummy

if [ $ANS != 'Y' ] 
then
	exit;
fi

echo "OK"
export MYSQL HOST USER PASSWORD DB LOG OBJDIR UNZIP1 PROPERTIES


echo "*******************"`date`"******************" >$LOG
echo "Creating tables\n" >>$LOG
echo "Creating tables\n"

cd SQL; ./create.first-stage >>../$LOG; cd ..

echo `date`"\n" >>$LOG
echo "Loading tables - I pass\n" >>$LOG
echo "Loading tables - I pass\n"

./load1.sh 

echo `date`"\n" >>$LOG
echo "Making indexes\n" >>$LOG

cd SQL; ./create.second-stage >>../$LOG; cd ..

echo `date`"\n" >>$LOG
echo "Loading tables - II pass\n" >>$LOG

./load2.sh

echo `date`"\n" >>$LOG
echo "Making more indexes\n" >>$LOG

cd SQL; ./create.third-stage >>../$LOG; cd ..

echo "Finished "`date` >>$LOG

