#! /bin/bash
cyflexlogevent -t generic -m 1 -m "script" -m "$0" 

# This command starts the external data manager program into execution
# for ONGA data for Cummins sites.
#
# Usage: start_onga_load configuration_file
#
# Author: Andrew Anker
# 
# History
#   08/24/16 - Andrew Anker - Initial release.

# This requires 1 command line argument, an existing configuration file.
if (( $# != 1 )); then
   echo This program requires one command line argument, the spec file.
   exit 1
fi
if [ ! -e $1 ]; then
   echo The command line argument must be an existing file.
   exit 1
fi

# Make sure that Java is in the environment.
test "$JAVA_HOME" = ""
if (($? == 0 )); then
   . ~/.bash_profile
fi

# Set up class path for Java.
BASE=/cyflex/specfilegui
export CLASSPATH=$BASE/ExternalDataManager.jar:$BASE/specfilegui.jar:/cyflex/specfilegui.3rdparty/ojdbc.jar

stop_onga_loading $1

# Actually execute the program.
export JAVA_HOME=/cyflex/java_jdk
PATH=$JAVA_HOME/bin:$PATH
java -DPropertiesFile=$1 \
   com.cybermetrix.cyflex.extdatman.ExternalDataManager >> /data/errors/onga_loading.`date +"%y%m%d"` 2>&1 &
