#!/bin/sh

JAR_LOC=/usr/lib/luna/java

GetClasspath()
{
	CP=
	for i in `ls /usr/lib/luna/java` ; do
		if [ "$CP" == "" ] ; then
			CP="$JAR_LOC/$i"
		else
			CP="$CP:$JAR_LOC/$i"
		fi
	done
	echo $CP
}

nocursor
cd /var/luna/data
        
CLASSPATH=$(GetClasspath)

if grep -qs "ARM-Versatile" /proc/cpuinfo ; then
  export PLATFORMCLASS=HostLinuxQemu
else
  export PLATFORMCLASS=HostLinuxCastle
fi

export TZID=`date +%Z`
VMARGS="-classpath $CLASSPATH -DPLATFORMCLASS=$PLATFORMCLASS -DtimeZoneId=$TZID -ms -Xoomreport=/var/javaoom/oom.$$.txt -Djava.util.logging.config.file=/etc/logging.properties"

JAVAARGS=""
#JAVAARGS=
MAINCLASS=com.palm.datamigration.DataMigration

if tty > /dev/null && pidof java > /dev/null; then
  echo "--------------------------------------------------------------------"
  echo "** WARNING: detected java process `pidof java` already running **"
  echo
  echo "** Not going to start this data migration **"
  echo "--------------------------------------------------------------------"
  exit 0
fi

# create named pipe to send PmUpdater progress
mknod /tmp/progress p

# Launch PmUpdater, which shows indeterminate progress.  Each write to
# /tmp/progress causes PmUpdater to increment the progress by 5%.
PmUpdater -progress /tmp/progress &

exec /usr/bin/javahy $VMARGS $MAINCLASS $JAVAARGS "$*"

# delete pipe
rm /tmp/progress