#!/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="dpkg"
VERSION="$PACKAGE_VERSION"
DESC="Backup debian package lists"
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 ! which dpkg > /dev/null 2>&1 ; then
		h_error "dpkg not found. Perhaps this is not a debian system?"
		return 1
	fi

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

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

	h_msg -n 6 "Storing dpkg selections to $FN.gz..."
	dpkg --get-selections '*' | gzip > "$FN.gz"
	h_msg 6 " done"

	return 0
}

