#!BOURNESHELL
#	program:	issubdom
#	input:		a possible subdomain name and a domain name.
#	output:		"true" if first arg is subdomain of second,
#			"false" if not.
#			If the two are identical, output is "false".
#			"ERROR" is output if an error occurred.
#	exit value:	0 if "true", 1 if "false", 2 if error occurred.

if test $# -ne 2; then
	echo "usage: $0 sub.dom.ain. dom.ain." >&2
	echo 'ERROR'
	exit 2
fi

subdom=$1
dom=$2

# If subdom has dom on it's right side and subdom is not exactly equal to dom,
# then return "true" else "false".
# This is a case-less compare (ignores upper/lower case differences).

echo $subdom | grep -i $dom\$ > /dev/null
if test $? -eq 0; then
	echo $subdom | grep -i \^$dom\$ > /dev/null
	if test $? -ne 0; then
		echo "true"
		exit 0
	else
		echo "false"
		exit 1
	fi
else
	echo "false"
	exit 1
fi

echo 'ERROR'
exit 2
