#!/bin/sh

# Specify where the database resides:
# MySQL client, hostname, user and password of the server
MYSQL=/usr/local/mysql/bin/mysql
HOST=myhost.mydb.net
USER=myuser
PASSWORD=mypswd
# the database name
DB=RIPE
LOG=DBmake.$$.log


# Directory where the object files reside
OBJDIR=/space/RIPE/snapshot
UNZIP1='gzip -cd'

# RIPE.CURRENTSERIAL
CURRENTSERIAL=`cat ${OBJDIR}/RIPE.CURRENTSERIAL` 

# Name of the properties 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 "RIPE.CURRENTSERIAL=" ${CURRENTSERIAL}
echo "Logging results in $LOG"
echo "***************************"
echo
echo "Accept and continue(Y/N)? (Default No)"

read ANS dummy

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

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


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

