# Script that installs DataEngineServer on Arm devices
# CrossControl AB 2018
# Daniel Nisses-Gagnér

#!/bin/sh
VERSION=3.1.3.30
INSTALLATION_SUCCESS=0

# Check if any in-parameter is set, otherwize use VERSION!
if [ -z "$1" ]; then
  VERSION=$VERSION
else
  VERSION=$1
fi

echo "Installing DataEngineServer for ARM runtime 3.1.3.30 on unit"
sudo tar -xf DataEngineServer_ARM_runtime_3.1.3.30.tar.gz -C /

INSTALLATION_SUCCESS=0

# Check that installation is succesful
if [ ! -f /opt/bin/dataengineserverApp ]
then
	echo "file /opt/bin/dataengineserverApp missing"
	INSTALLATION_SUCCESS=1
	exit $INSTALLATION_SUCCESS
fi

if [ ! -f /opt/lib/libsapcore.so.3.1.3 ]
then
	echo "file /opt/lib/libsapcore.so.3.1.3  missing"
	INSTALLATION_SUCCESS=1
	exit $INSTALLATION_SUCCESS
fi

if [ ! -f /opt/lib/libsapcore.so ]
then
	echo "file /opt/lib/libsapcore.so missing"
	INSTALLATION_SUCCESS=1
	exit $INSTALLATION_SUCCESS
fi

if [ ! -f /opt/lib/libadmincore.so ]
then
        echo "file /opt/lib/libadmincore.so missing"
        INSTALLATION_SUCCESS=1
        exit $INSTALLATION_SUCCESS
fi

if [ ! -f /opt/etc/init.d/StartupDataEngineServer ]
then
	echo "file /opt/etc/init.d/StartupDataEngineServer missing"
	INSTALLATION_SUCCESS=1
	exit $INSTALLATION_SUCCESS
fi

if [ ! -f /opt/etc/rc3.d/S17StartupDataEngineServer ]
then
	echo "file /opt/etc/rc3.d/S17StartupDataEngineServer missing"
	INSTALLATION_SUCCESS=1
	exit $INSTALLATION_SUCCESS
fi

if [ ! -f /opt/etc/rc6.d/S38StartupDataEngineServer ]
then
	echo "file /opt/etc/rc6.d/S38StartupDataEngineServer" missing
	INSTALLATION_SUCCESS=1
	exit $INSTALLATION_SUCCESS
fi

if [ ! -f /opt/etc/rc0.d/S38StartupDataEngineServer ]
then
	echo "file /opt/etc/rc0.d/S38StartupDataEngineServer" missing
	INSTALLATION_SUCCESS=1
	exit $INSTALLATION_SUCCESS
fi

ldconfig -C /opt/etc/ld.so.cache

# Create a stamp to indicate installed package
if [ ! -d /opt/packages ]; then
	mkdir /opt/packages
fi
touch /opt/packages/DataEngineServer_ARM_runtime_3.1.3.30 

echo "Installation of DataEngineServer for ARM runtime 3.1.3.30 on unit successfull and will auto-start after reboot."

exit $INSTALLATION_SUCCESS

