#!/bin/sh
#
#Company	Anabas,Inc.
#Author		Hong Zhou
#Date		6-13-01
#
#Description	This script will unjar the anabas sharedled_licensesdk_linux.jar
#	and install the package onto your computer
#

#ask for the install dir from the user
echo "Please select the install directory for the package [/opt/anabas/licensesdk]:"
read INSTALLDIR < /dev/tty

#make sure that INSTALLDIR is not empty, if yes, set to the default
if [ ${INSTALLDIR}x = x ]
then
	INSTALLDIR=/opt/anabas/licensesdk
fi

#try to create the install dir if not exists yet
if ! mkdir -p $INSTALLDIR
then
	echo "Could not make directory $INSTALLDIR, please check your previledge"
	exit 1
fi


#check if there is any java in the path
if ! java -version
then
	echo "No JDK installed in the system PATH, please check it and install later"
	exit 1
fi

#unjar the package into the destination dir
echo "begin to unpack the jar file now to install the package"
sleep 1
cp -f anabas_licensesdk.jar $INSTALLDIR
cd $INSTALLDIR
jar xvf anabas_licensesdk*.jar

#delete some window strange characters for executable files
chmod 755 ./configure.sh
./configure.sh

#delete uncessary window strange characters for management files
./bin/delete_returns ${INSTALLDIR}/tomcat/webapps/ROOT/management

#try to generate localized versions for the management systems
echo "begin to generate localized versions of the management files now"
sleep 1
export CLASSPATH=${INSTALLDIR}/tomcat/lib/anabastomcat.jar:$CLASSPATH
./bin/localization.pl -c g -v en_US -v zh_CN -v zh_TW -d ${INSTALLDIR}/tomcat/webapps/ROOT/management


#create the admin.sh on the fly
echo "#!/bin/sh" > ./bin/admin.sh
echo "export ANABAS_HOME=$INSTALLDIR" >> ./bin/admin.sh
echo '$ANABAS_HOME/bin/admin.pl $*' >> ./bin/admin.sh
chmod 755 ./bin/admin.sh

echo "Now clean the jar file"
rm -f anabas_licensesdk*.jar
