#!/bin/bash
#
# kuwatcher helper function: mount 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

for fs in `grep "^${1}:" /etc/fstab | sed -e 's/[ ,	].*//'`
do
	# 2013.10.16 in /proc/mounts we can have trailing slash, too (12.04 change?)
	egrep -q "^$fs |^$fs/ " /proc/mounts && {
		$DEBUG && logger -s -t $CMD "ignore $fs (already mounted)"
		continue
	}
	if mount $fs
	then
		logger -s -t $CMD "mounted $fs"
	else
		state=$?
		logger -s -t $CMD "error $state mounting $fs"
	fi
done
exit $state
