#!/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$
#
# Description
#	Mount a partition
#

NAME="mount"
VERSION="$PACKAGE_VERSION"
DESC="Mount a partition"
LICENSE="$PACKAGE_LICENSE"
COPYRIGHT="$PACKAGE_COPYRIGHT"
CONTACT="$PACKAGE_BUGREPORT"

# Display help
do_help()
{
	cat << _END
Configuration options:
	DEVICE		The device name
	MOUNTPOINT	Where to mount it (required)
	OPTIONS		Mount options, not including -o
	FSTYPE		Filesystem type

	If DEVICE is not defined an /etc/fstab entry must exist
_END
}

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

	return 0
}

# Do backup
do_run()
{
	local	A
	local	B
	local	C

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

	if [ ! -z "$FSTYPE" ] ; then
		B="-t $FSTYPE"
	fi

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

	if mount $A "$MOUNTPOINT" $B $C ; then
		R=0
		h_msg 6 "Mounted $MOUNTPOINT"
	else
		h_error "Failed to mount $MOUNTPOINT"
		R=3
	fi

	return $R
}

