#!/bin/bash

PBUILD_BASE=/var/cache/pbuilder/

set -e
if [ -z "$DIST" ] ; then
    DIST=sid
fi

DIR=$PBUILD_BASE/base-"${DIST}".cow

if [ ! -d $DIR ]; then
    echo "no such directory: $DIR"
    echo "usage: DIST=(dist) $0 (debbuild args)"
    exit 1
fi

case "$DIST" in
sid)
    ;;
*)
    EXTRA="--debian-etch-workaround"
    ;;
esac

pdebuild --buildresult .. --pbuilder cowbuilder \
    --debbuildopts "-i\.git -I.git $*" -- --basepath ${DIR} ${EXTRA}

rm ../*_source.changes

