#!/bin/bash

# Script to install the EnTrak environment

#if [ "$(id -u)" != "0" ];
#then
#    echo "You need to be root to run this script (try sudo bash Installer.bash)"
#    exit 1
#fi

INSTALLDIR="/usr/local/ampps/www"

if [ ! -d $INSTALLDIR ];
then
    echo "Ampps does not seem to be installed at /usr/local "
    echo "it needs to be installed there before installing EnTrak"
    exit 1
fi

rm -f /tmp/ProjectsList.csv
if [ -f $INSTALLDIR"/EnTrak/EnTrak/ProjectsList.csv" ];
then
    cp /usr/local/ampps/www/EnTrak/EnTrak/ProjectsList.csv /tmp
fi

rm -rf /usr/local/ampps/www/EnTrak/EnTrak
if [ ! -d $INSTALLDIR"/EnTrak" ];
then
    mkdir $INSTALLDIR"/EnTrak/"
fi
cp -R EnTrak/EnTrak/ $INSTALLDIR
if [ -f "/tmp/ProjectsList.csv" ];
then
    cp /tmp/ProjectsList.csv $INSTALLDIR"/EnTrak/EnTrak/ProjectsList.csv"
fi


#chmod a+rw $INSTALLDIR"/EnTrak/EnTrak" $INSTALLDIR"/EnTrak/Outputs" $INSTALLDIR"/EnTrak/Inputs"
#chmod a+rw $INSTALLDIR"/EnTrak/EnTrak/2_Projects"
#chmod a+rw $INSTALLDIR"/EnTrak/EnTrak/4_ESView"
#chmod a+rw $INSTALLDIR"/EnTrak/EnTrak/Uploads"
#chmod a+rw $INSTALLDIR"/EnTrak/EnTrak/ProjectsList.csv"

# Make local applications
cd $INSTALLDIR"/EnTrak/EnTrak/2_Projects/Apps_src"
cd bax2csv
rm -rf obj bax2csv

# assume gcc is present on server
make
cp bax2csv ../../bax2csv

chmod a+rw -R $INSTALLDIR"/EnTrak"
























#
