#!/bin/bash
#
# kuwatcher helper function: umount all nfs share from a server
#
# __copy1__
# __copy2__
#
CMD=${CMD:-"$0"}
DEBUG=${DEBUG:-"false"}

[ -z $1 ] && {
	echo "usage: $0 servername" >&2
	exit 255
}

state=0
retrytime=5	# secs

for fs in `grep "^${1}:" /etc/fstab | sed -e 's/[ ,	].*//'`
do
	grep -q "^$fs " /proc/mounts || {
		logger -s -t $CMD "ignore $fs (not mounted)"
		continue
	}
	umount $fs || {
		logger -s -t $CMD "failed to umount $fs .. retry in $retrytime secs .."
		sleep $retrytime
		umount -l $fs	# lazy umount, bypass busy filesystem state
	}
	if [ $? == 0 ]
	then
		logger -s -t $CMD "umounted $fs"
	else
		state=$?
		logger -s -t $CMD "error $state umounting $fs"
	fi
done
exit $state
