#!/bin/bash
#
# This file is part of vbackup.
#
# vbackup is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# vbackup is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with vbackup  If not, see <http://www.gnu.org/licenses/>.
#
# $Id: nfsmount 3393 2012-03-06 21:00:03Z v13 $
#
# Description
#	Mount an nfs share
#

NAME="nfsmount"
VERSION="$PACKAGE_VERSION"
DESC="Mount an NFS share"
LICENSE="$PACKAGE_LICENSE"
COPYRIGHT="$PACKAGE_COPYRIGHT"
CONTACT="$PACKAGE_BUGREPORT"

# Display help
do_help()
{
	cat << _END
Configuration options:
	NFSDIR		The full NFS path (required)
	MOUNTPOINT	Where to mount it (required)
	OPTIONS		Mount options, not including -o
_END
}

# Check configuration
# return: 0: ok, 1: error
do_check_conf()
{
	[ -z "$NFSDIR" ] && h_error "Missing NFSDIR" && return 2
	[ -z "$MOUNTPOINT" ] && h_error "Missing MOUNTPOINT" && return 2

	return 0
}

# Do backup
do_run()
{
	local	A

	if [ ! -z "$OPTIONS" ] ; then
		A="-o $OPTIONS"
	fi

	if mount -t nfs "$NFSDIR" "$MOUNTPOINT" $A ; then
		h_msg 6 "Mounted $MOUNTPOINT via NFS"
		R=0
	else
		h_msg 6 "Failed to mount $MOUNTPOINT via NFS"
		R=3
	fi

	return $R
}

