#! /bin/ksh -p
#
# ident "@(#)cmd_chk_globaldev.ksh	1.1	03/01/23 SMI"
#
# Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#

#####################################################
#
# cmd_chk_globaldev <type> <mount_point>|<special_device>
#
#	<type> is:
#
#		fs			# mount_point
#		device			# special_device
#
#	Possible exit codes are the same as the result codes from
#	is_globalfs_okay() and is_globalcspecial_okay() (depending
#	on given "type").
#
#####################################################

#####################################################
#
# Constant Globals
#
#####################################################

# Program name
typeset -r PROG=${0##*/}

# Set the PATH
typeset -r SC_BINDIR=/usr/cluster/bin
typeset -r SC_BINDIRS=${SC_BINDIR}:/usr/cluster/lib/sc
PATH=${SC_BINDIRS}:/bin:/usr/bin:/sbin:/usr/sbin; export PATH

# I18N
typeset -x TEXTDOMAIN=TEXT_DOMAIN
typeset -x TEXTDOMAINDIR=/usr/cluster/lib/locale

#####################################################
#
# print_usage()
#
#	Print usage message to stderr
#
#####################################################
print_usage()
{
	echo "$(gettext 'usage'):  ${PROG} fs|device <mount_point>|<special_device>" >&2
}

#####################################################
#
# Main
#
#####################################################
main()
{
	typeset type=${1}
	typeset globaldev=${2}

	typeset mydir

	#
	# "mydir" is the directory from which this script is run.
	# Make sure that it is set with an absolute path;  and, remove
	# trailing dots.
	#
	mydir=$(dirname $0)
	if [[ "${mydir}" != /* ]]; then
		mydir=$(/usr/bin/pwd)/${mydir}
	fi
	while [[ "${mydir##*/}" = "." ]]
	do
		mydir=$(dirname ${mydir})
	done             

	#
	# scinstall_common is expected to be in the same directory as
	# this program.
	#
	. ${mydir}/scinstall_common
	if [[ $? -ne 0 ]]; then
		printf "$(gettext '%s:  Unable to load \"%s\"')\n" "${PROG}" "${${mydir}/scinstall_common}" >&2  
		return 10
	fi

	case ${type} in
	fs)	# file system
		is_globalfs_okay "${globaldev}" 3
		return $?
		;;

	device)	# special device
		is_globalcspecial_okay "${globaldev}" 3
		return $?
		;;

	*)	# usage error
		print_usage
		return 10
		;;
	esac

	print_usage
	return 10
}

	main $*
	exit $?
