#!/bin/sh
#
# @(#)install.sh	1.2 11/2/93 10:43:34 - Elan Computer Group, Inc. (c) 1993
#
# Sample shell script code for installing Licenser Server (elmd)
# in /etc/rc.local and installing license key.
#
#	THIS CODE IS MEANT AS A SAMPLE ONLY AND IS UNSUPPORTED
#

ROOT=/usr/local/product
ELMADMIN=${ROOT}/bin/elmadmin
ELMDIR=${ROOT}/lib/elm
ELMD=${ROOT}/bin/elmd
ELMLOG=${ROOT}/lib/logs/elm.log
ELMRSV=${ROOT}/lib/elm/reserve
RC_LOCAL=/etc/rc.local

#
# replace stdin in file ($1) with the token $2
#
replace()
{
	TMP=/tmp/elm$$.tmp
	FILE=$1
	TOKEN=$2
	sed "/${TOKEN}-START/,/${TOKEN}-END/d" < $FILE > $TMP
	echo "# ${TOKEN}-START: Don't remove this line -- it's used by avinstall" >> $TMP
	echo "# If you want to make changes by hand, place entries outside START/END pair." >> $TMP
	cat >> $TMP
	echo "# ${TOKEN}-END: Don't remove this line -- it's used by avinstall" >> $TMP
	rm -f ${FILE}.bak
	cp ${FILE} ${FILE}.bak
	cp $TMP $FILE
	rm -f $TMP
}

licenseKey()
{
	if [ ! -f "$ELMADMIN" ]; then
		echo $ELMADMIN not found
		exit 1
	fi

	if [ ! -d $ELMDIR ]; then
		mkdir $ELMDIR
		chmod 755 $ELMDIR
	fi

	echo "You must contact COMPANY via telephone or FAX with your"
	echo '"server code" (printed below) to obtain a license "key".'
	echo ''
	echo 'Note: Licenses are not transferable to different servers.'
	echo 'If this machine will only hold Avalon Publisher temporarily,'
	echo 'please let the COMPANY support person know this when you read the'
	echo 'code so that you can be given a temporary (tranferable) key.'
	echo ''
	echo "COMPANY's telephone number and FAX are:"
	echo '        Telephone:  415-555-1234'
	echo '        Facsimile:  415-555-1234'
	echo ''

	if $ELMADMIN -e ${ELMDIR} -c ; then
		:
	else
		echo ""
		echo "Your License key has not been installed."
		echo ""
		echo "You may install it at a later time by running:"
		echo "		./avinstall"
		echo "and selecting"
		echo "	Install Avalon Publisher license key."
		echo ""
	fi
}

daemon()
{
	if [ ! -f "$ELMD" ]; then
		echo "$ELMD not found."
		exit 1
	fi

	COMMAND="$ELMD -m 0.2m -r $ELMRSV -l $ELMLOG"

	echo "$COMMAND" | replace $RC_LOCAL ELMD

	echo ""
	echo "Elan License Manager installed in $RC_LOCAL"
	echo ""

	#
	# Start it too
	#
	eval $COMMAND
}

daemon
licenseKey
#
# End of sample shell code.
#
