#!/bin/bash

INSTALLDIR=`pwd`/MIPRED2006

function install_everything {
	mkdir -p ${INSTALLDIR}/bayes
	tar xzf datasets.tar.gz -C ${INSTALLDIR}/
	tar xzf libsvm-2.82.tar.gz -C ${INSTALLDIR}/
	tar xzf Statistics-Descriptive-2.6.tar.gz -C ${INSTALLDIR}/
	tar xzf Statistics-ROC-0.01.tar.gz -C ${INSTALLDIR}/
	tar xzf scripts.tar.gz -C ${INSTALLDIR}/
	unzip -d ${INSTALLDIR}/bayes lnxbayes.zip
	unzip -d ${INSTALLDIR}/bayes lnxtable.zip

	cd ${INSTALLDIR}/libsvm-2.82
	make

	cd ${INSTALLDIR}/Statistics-Descriptive-2.6
	perl Makefile.PL
	make test

	cd ${INSTALLDIR}/Statistics-ROC-0.01
	perl Makefile.PL
	make test

	cd ${INSTALLDIR}
	sed -e 's/\/home\/stanley\/myHome\/bin/libsvm-2.82/g' grid.py > grid.py.temp
	mv grid.py.temp grid.py
}

if [ ! -e ${INSTALLDIR} ]
then
	install_everything
fi

PATH=$PATH:${INSTALLDIR}/libsvm-2.82:${INSTALLDIR}/bayes:
PERL5LIB=${INSTALLDIR}/Statistics-Descriptive-2.6/blib/lib:${INSTALLDIR}/Statistics-ROC-0.01/blib/lib
export PATH PERL5LIB

cd ${INSTALLDIR}
mv Backup/* .
rm -rf Backup/

./3SVM-workflow.bash
./SVM-workflow.bash
