#!/bin/bash
# vim: ts=4 sw=4 ai noet
# $Id$
#
# Copyright (C) 2008, Robert Nelson. Licensed under GPLv2.
# By Robert Nelson.
#

test -n "$DEBUG_EXEC" && set -x

TOOLDIR=/usr/share/vzpkg2

. ${TOOLDIR}/apt-functions

log4 Started $0 $*

log4 Creating /var/cache/apt/archives and /var/cache/apt/archives/partial
mkdir -p $VE_ROOT/var/cache/apt/archives
mkdir -p $VE_ROOT/var/cache/apt/archives/partial

file=`find_template_config_file $OS_SET.list` || \
	abort "List of packages for $OS_SET not found!"

includes=`echo \`sed -ne '/.*[^-]$/s/$/,/p' $file \` | sed -e 's/ //g' -e 's/,$//'`
excludes=`echo \`sed -ne '/.*-$/s/-$/,/p' $file \` | sed -e 's/ //g' -e 's/,$//'`

test -n "$includes" && includes="--include=$includes"
test -n "$excludes" && excludes="--exclude=$excludes"

read_vzpkg_conf

debootstrap $includes $excludes --arch $OS_ARCH $OS_VER $VE_ROOT $APT_MIRROR
rc=$?

exit $rc
