#!/bin/sh
# Script that installs Firebird on XA
# Jesper Melin, maximatecc 

VERSION=2.5.2.26540
INSTALLATION_SUCCESS=0

echo "Installing firebird2.5-superclassic_${VERSION}.tar.gz on unit "

echo -ne "Extracting archive... "

tar -xzf ./firebird2.5-superclassic_${VERSION}_arm.tar.gz -C / &
pid=$! # Process Id of the previous running command

spin='-\|/'

i=0
while kill -0 $pid 2>/dev/null
do
  i=$(( (i+1) %4 ))
  printf "\rExtracting archive... ${spin:$i:1}"
  sleep .1
done

printf "\rExtracting archive...  \n"

# Check that installation is succesful
if [ ! -f /opt/etc/firebird/2.5/aliases.conf ]
then
	echo "file /opt/etc/firebird/2.5/aliases.conf" missing
	INSTALLATION_SUCCESS=1
	exit $INSTALLATION_SUCCESS
fi

if [ ! -f /opt/etc/firebird/2.5/fbintl.conf ]
then
	echo "file /opt/etc/firebird/2.5/fbintl.conf" missing
	INSTALLATION_SUCCESS=1
	exit $INSTALLATION_SUCCESS
fi

if [ ! -f /opt/etc/firebird/2.5/fbtrace.conf ]
then
	echo "file /opt/etc/firebird/2.5/fbtrace.conf" missing
	INSTALLATION_SUCCESS=1
	exit $INSTALLATION_SUCCESS
fi

if [ ! -f /opt/etc/firebird/2.5/firebird.conf ]
then
	echo "file /opt/etc/firebird/2.5/firebird.conf" missing
	INSTALLATION_SUCCESS=1
	exit $INSTALLATION_SUCCESS
fi

if [ ! -f /opt/mtcc/db/fbdb_fs ]
then
	echo "file /opt/mtcc/db/fbdb_fs" missing
	INSTALLATION_SUCCESS=1
	exit $INSTALLATION_SUCCESS
fi


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


if [ ! -f /opt/usr/bin/fbstat ]
then
	echo "file /opt/usr/bin/fbstat" missing
	INSTALLATION_SUCCESS=1
	exit $INSTALLATION_SUCCESS
fi

if [ ! -f /opt/usr/bin/fbtracemgr ]
then
	echo "file /opt/usr/bin/fbtracemgr" missing
	INSTALLATION_SUCCESS=1
	exit $INSTALLATION_SUCCESS
fi

if [ ! -f /opt/usr/bin/gdef   ]
then
	echo "file /opt/usr/bin/gdef  " missing
	INSTALLATION_SUCCESS=1
	exit $INSTALLATION_SUCCESS
fi

if [ ! -f /opt/usr/bin/gpre ]
then
	echo "file /opt/usr/bin/gpre" missing
	INSTALLATION_SUCCESS=1
	exit $INSTALLATION_SUCCESS
fi

if [ ! -f /opt/usr/bin/isql-fb ]
then
	echo "file /opt/usr/bin/isql-fb" missing
	INSTALLATION_SUCCESS=1
	exit $INSTALLATION_SUCCESS
fi

if [ ! -f /opt/usr/bin/qli ]
then
	echo "file /opt/usr/bin/qli" missing
	INSTALLATION_SUCCESS=1
	exit $INSTALLATION_SUCCESS
fi

if [ ! -f /opt/usr/bin/fbsvcmgr ]
then
	echo "file /opt/usr/bin/fbsvcmgr" missing
	INSTALLATION_SUCCESS=1
	exit $INSTALLATION_SUCCESS
fi

if [ ! -f /opt/usr/bin/gbak ]
then
	echo "file /opt/usr/bin/gbak" missing
	INSTALLATION_SUCCESS=1
	exit $INSTALLATION_SUCCESS
fi

if [ ! -f /opt/usr/bin/gfix ]
then
	echo "file /opt/usr/bin/gfix" missing
	INSTALLATION_SUCCESS=1
	exit $INSTALLATION_SUCCESS
fi

if [ ! -f /opt/usr/bin/gsec ]
then
	echo "file /opt/usr/bin/gsec" missing
	INSTALLATION_SUCCESS=1
	exit $INSTALLATION_SUCCESS
fi

if [ ! -f /opt/usr/bin/nbackup ]
then
	echo "file /opt/usr/bin/nbackup" missing
	INSTALLATION_SUCCESS=1
	exit $INSTALLATION_SUCCESS
fi


if [ ! -f /opt/usr/sbin/fbguard ]
then
	echo "file /opt/usr/sbin/fbguard" missing
	INSTALLATION_SUCCESS=1
	exit $INSTALLATION_SUCCESS
fi

if [ ! -f /opt/usr/sbin/fb_lock_print ]
then
	echo "file /opt/usr/sbin/fb_lock_print" missing
	INSTALLATION_SUCCESS=1
	exit $INSTALLATION_SUCCESS
fi

if [ ! -f /opt/usr/sbin/fb_smp_server ]
then
	echo "file /opt/usr/sbin/fb_smp_server" missing
	INSTALLATION_SUCCESS=1
	exit $INSTALLATION_SUCCESS
fi

if [ ! -f /opt/usr/share/firebird/2.5/de_DE.msg ]
then
	echo "file /opt/usr/share/firebird/2.5/de_DE.msg" missing
	INSTALLATION_SUCCESS=1
	exit $INSTALLATION_SUCCESS
fi

if [ ! -f /opt/usr/share/firebird/2.5/firebird.msg ]
then
	echo "file /opt/usr/share/firebird/2.5/firebird.msg" missing
	INSTALLATION_SUCCESS=1
	exit $INSTALLATION_SUCCESS
fi

if [ ! -f /opt/usr/share/firebird/2.5/fr_FR.msg ]
then
	echo "file /opt/usr/share/firebird/2.5/fr_FR.msg" missing
	INSTALLATION_SUCCESS=1
	exit $INSTALLATION_SUCCESS
fi

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

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

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

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

# Update the library cache
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/firebird2.5-superclassic_${VERSION}_arm

exit $INSTALLATION_SUCCESS

