#!/bin/ksh
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# bos720 src/bos/usr/lib/nim/methods/rofs_helper.sh 1.1 
#  
# Licensed Materials - Property of IBM 
#  
# Restricted Materials of IBM 
#  
# COPYRIGHT International Business Machines Corp. 2006 
# 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 

# set parameters from command line
while getopts f:v x
do
	case ${x} in

		f)		# replace local file with nfs mount
				file="${OPTARG}"
				;;

		v)		# verbose mode (for debugging)
				set -x
				for i in $(typeset +f)
				do
					typeset -ft $i
				done
				;;

		\?)		# unknown option
				exit 1
				;;
	esac
done

rc=0
file_bk="/tmp/file.$$"
# anything to replace?
if `/usr/bin/ls ${file} >/dev/null 2>&1`; then
	# unmount may be necessary
	/usr/sbin/unmount ${file} 2>/dev/null

	# remove original file(s)
	/usr/bin/mv ${file} ${file_bk} 2>dev/null

	# create mount
	mkdir -p ${file}

	# mount file as listed in /etc/filesystems
	if /usr/sbin/mount ${file}; then
		/usr/bin/rm ${file_bk} 2>dev/null
	else
		/usr/bin/mv ${file_bk} ${file} 2>dev/null
		rc=1
	fi
else
	rc=1
fi

exit $rc
