#!/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 2 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, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
#
# $Id$
#
# Description
#
#

# The name of the backup script
NAME="dpkg"
# The version of the script
VERSION="$PACKAGE_VERSION"
# A short description of the script
DESC="Backup debian package lists"
# The license of this module
LICENSE="GPLv2"
# A copyright statement
COPYRIGHT="Copyright (c) 2006-2007 Stefanos Harhalakis"
# A contact email for bugreports etc
CONTACT="v13@v13.gr"

# 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.%D1%"
	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
}

