#!/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
#
#

NAME="rpm"
VERSION="$PACKAGE_VERSION"
DESC="Backup RPM database"
LICENSE="$PACKAGE_LICENSE"
COPYRIGHT="$PACKAGE_COPYRIGHT"
CONTACT="$PACKAGE_BUGREPORT"

# Display help
do_help()
{
	cat << _END
Backup debian dpkg package list. This way the system can be easily restored.

Configuration options:
	DESTDIR			Where to store the backup (required)
	DESTFILE		The filename to use.
_END
}

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

	return 0
}

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

	if ! test -d /var/lib/rpm ; then
		h_error "/var/lib/rpm doesn't exist"
		return 1
	fi

	if [ -z "$DESTFILE" ] ; then
		DESTFILE="rpm"
	fi

	h_transform "$DESTFILE"
	FN="$DESTDIR/$R"

	h_msg -n 6 "Storing rpm database to $FN.gz..."
	$GTAR -zcf "$FN.tgz" -C /var/lib --exclude '__db.*' rpm/
	h_msg 6 " done"

	return 0
}

