#!/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: off 1416 2007-12-28 12:36:01Z v13 $
#
# Description
#
#	Check whether a path exists
#

NAME="exist"
VERSION="$PACKAGE_VERSION"
DESC="Check whether a path exists"
LICENSE="$PACKAGE_LICENSE"
COPYRIGHT="$PACKAGE_COPYRIGHT"
CONTACT="$PACKAGE_BUGREPORT"

# Display help
do_help()
{
	cat << _END
Configuration options:
	DIR		The path to check. If / is used then look for the
			parent directory of DESTDIR
_END
}

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

	return 0
}

# Do backup
do_run()
{
	if [ "x$ABORT" = "x1" ] ; then
		return 0
	fi

	if [ "x$DIR" = "x/" ] ; then
		DIR1=$(dirname "$DESTDIR0")
	else
		DIR1="$DIR"
	fi

	h_msg 13 "Check whether $DIR1 exists"
	if test -e "$DIR1"  ; then
		h_msg 10 "$DIR1 exists"
		ret=0
	else
		h_msg 2 "$DIR1 doesn't exist"
		ret=3
	fi

	return $ret
}

