#!/bin/bash

pwd=$PWD
ln -s $PWD/lib/jsdk2.1/webpages/WEB-INF/servlets bin


echo "This will install the online auction database."
echo "We preassume that you have updated the settings in $PWD/src/Configure.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:$CLASSPATH
export CLASSPATH=$PWD/lib/mail.jar:$PWD/lib/activation.jar:$PWD/lib/classes111.zip:$PWD/lib/classes.zip:$PWD/lib/server.jar:$PWD/lib/servlet.jar:$CLASSPATH
jikes -d $PWD/bin $PWD/src/*.java

echo "done"
cp $PWD/src/properties $PWD/bin/properties

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

