#!/bin/bash

pwd=$PWD

echo "This will install [01;32mOAD[m - the [01;32mO[mnline [01;32mA[muction [01;32mD[matabase brought to you by [01;31mHANS[m"
echo "Current directory is $PWD"
echo "We also presume that you have updated the settings in $PWD/src/Config.java as we shall be compiling it now"

# Create tables in database
echo "Presumably you will be using an Oracle Database with an account in which the files will go."
echo -n "So enter the username: "
read dbuid
echo -n "Password: "
stty -echo
read dbpass
stty echo
echo -n "Creating tables ... "
# Use loginid and password given !
echo "---------------------------------------------------------------------------------------" >> $PWD/tmp/install.log
echo "            T A B L E S    I N S E R T E D    I N T O      D A T A B A S E             " >> $PWD/tmp/install.log
echo "---------------------------------------------------------------------------------------" >> $PWD/tmp/install.log
sqlplus "$dbuid/$dbpass" < $PWD/dat/maketable.sql >> $PWD/tmp/install.log
echo "done"

# Insert sysad password in database
# echo "Presumably you will be the sysad of the database."
# echo -n "So choose a password: "
#stty -echo
# read sysadpass
# stty echo
#echo "insert into passwords values('sysad', '$sysadpass');" >> $PWD/tmp/insert_sysad_passwd.sql
#echo -n "Inserting password ... "
#echo "---------------------------------------------------------------------------------------" >> $PWD/tmp/install.log
#echo "            P A S S W O R D    I N S E R T E D    I N T O      D A T A B A S E         " >> $PWD/tmp/install.log
#echo "---------------------------------------------------------------------------------------" >> $PWD/tmp/install.log
#sqlplus "$dbuid/$dbpass" < $PWD/tmp/insert_sysad_passwd.sql >> $PWD/tmp/install.log
#echo "done"
#echo -n "Cleaning temporary password file ... "
#rm -rf $PWD/tmp/insert_sysad_passwd.sql
#echo "done"

# Compile the source
#echo -n "Compiling sources ... "
#export CLASSPATH=$PWD/bin/class:$CLASSPATH
#javac -d $PWD/bin/class $PWD/src/java/*.java
#echo "done"
#cp $PWD/src/java/servlet.properties $PWD/bin/class/tejas/servlet.properties

# Prepare the shell script start.sh
#echo -n "Creating start script ... "
#echo "#!/bin/bash" >> $PWD/bin/scripts/start.sh
#echo "export CLASSPATH=\$CLASSPATH:$PWD/bin/class" >> $PWD/bin/scripts/start.sh
#echo "servletrunner -d $PWD/bin/class -r $PWD/bin/class -s $PWD/bin/class/tejas/servlet.properties -p \$1" >> $PWD/bin/scripts/start.sh
#chmod 700 $PWD/bin/scripts/start.sh
#echo "done"









