#!/bin/sh

# bundleTool
# David Corcoran <corcoran@linuxnet.com>
# MUSCLE <http://www.musclecard.com>
#

if [ x$DESTDIR = "x" ]
then
	DESTDIR=`pkg-config libmusclecard --variable=muscledropdir`
	DESTDIR=${DESTDIR:-/usr/local/pcsc/services}
fi

bundlename="slbCryptoflex.bundle"
libname="libcryptoflex"
dso_suffix="so"
targetname="slbCryptoflex"

hostType=`uname`
echo "Determining system type "
vFlag=0

case "$hostType" in
	SunOS) 		vFlag=1 
			hostType="Solaris";;
	Linux) 		vFlag=1
			hostType="Linux";;
	Darwin) 	vFlag=1
			hostType="MacOS";;
	*BSD*) 		vFlag=1
			hostType="BSD";;
	HPUX) 		vFlag=1
			dso_suffix="sl"
			hostType="HPUX";;
	Tru64) 		vFlag=1
			hostType="Tru64";;
	*)		vFlag=0;;
esac

if [ "$vFlag" = 1 ] 
then
	echo "Configuring for system: $hostType"
else
	echo "Couldn't determine system type"

	echo "Which of the following are you using ?"
	echo "	Linux"
	echo "	Solaris"
	echo "	Tru64"
	echo "	MacOS"
	echo "	HPUX"
	echo "	BSD"

	echo "Enter the value: "

	if read hostType
	then
		echo "Operating System"
	else
		echo "terminating"                                     
   	exit 0                                       
	fi

	case "$hostType" in
		Solaris) 	echo "Solaris";;
		Linux) 		echo "Linux";;
		MacOS) 		echo "MacOS";;
		BSD) 		echo "BSD";;
		HPUX) 		dso_suffix="sl"
				echo "HPUX";;
		Tru64) 		echo "Tru64";;
		*)		echo "Invalid OS Choice"
				exit 1;;
	esac
fi

echo "Writing service bundle for $targetname in $DESTDIR"
if [ ! -d $DESTDIR ]
then
	install -d -m 755 $DESTDIR
fi
cp -r src/$bundlename $DESTDIR
install -d -m 755 $DESTDIR/$bundlename/Contents/$hostType
install -s -m 644 src/.libs/$libname.$dso_suffix $DESTDIR/$bundlename/Contents/$hostType/$targetname
echo "Installation Successful"

