#!/bin/sh
#	program:	basedomain
#	release:	1.5.0
#	input:		one domain name on the command line.
#	output:		the domain below this one (this is a subdomain of it)
#			is sent to stdout, or "ERROR" if a problem occurs.
#			Trying to get the basedomain of "." is handled as
#			an error.
#			Usage printed to stderr, too, if usage error occurs.
#	example:	"cse.nau.edu." -> "nau.edu."
#	exit value:	0 if nothing goes wrong, 1 if something did.
#
# Copyright (C) 1993-2000 Paul A. Balyoz <pab@domtools.com>
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#

AWK=/usr/local/domtools/lib/basedomain.awk

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

echo $1 | awk -f $AWK
status=$?
if test $status -ne 0; then
	echo 'ERROR'
	exit 1
fi

exit $status
