#!/usr/bin/sh
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# bos720 src/bos/usr/bin/cdat/smit/cdat_remove_node.sh 1.2 
#  
# Licensed Materials - Property of IBM 
#  
# COPYRIGHT International Business Machines Corp. 2010,2011 
# All Rights Reserved 
#  
# US Government Users Restricted Rights - Use, duplication or 
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 
#  
# IBM_PROLOG_END_TAG 
# @(#)41    1.2  src/bos/usr/bin/cdat/smit/cdat_remove_node.sh, cdat, bos720 7/14/11 17:22:50
# This command removes the specified line in the specified node file
# If first flag is -s, it also suppress access to the specified node
#

CAT=cdat.cat
PATH=/bin:/sbin:/usr/bin:/usr/sbin
SUPP=""

usage() {
echo "Usage: $0 [-r|-s] -f <node file> -t <type> -l <node>"
	exit 1
}

[ "$1" != "-r" -a "$1" != "-s" ] && usage
[ "$1" = "-s" ] && SUPP="y"
shift

[ $# -ne 6 ] && usage

FILE="/tmp/cdat_remove_node$$"

grep "${4}:${6}$" "$2" 2>&1 1>/dev/null
[ $? -ne 0 ] && dspmsg -s 11 $CAT 1 "Selected hostname not found\n" && exit 1
grep -v "${4}:${6}$" "$2" > $FILE
REP=$?
if [ $REP -gt 1 ]
then
	rm $FILE
	exit $REP
fi
cp $FILE "$2"
[ $? -ne 0 ] && exit $?
rm $FILE

if [ -n "$SUPP" ]
then
	cdat access -d -n ${4}:`echo ${6} | sed -e 's/ *#.*$//'`
	REP=$?
	# smit exec_mode is "i"
	echo ""
	/usr/bin/dspmsg -s 11 cdat.cat 3 "Type enter to continue.\n"
	/usr/bin/line
	exit $REP
fi
