#!/bin/bash -e

# This file is maintained using git on
# http://mdcc.cx/git/wd/ad1810-stuff/

# based upon $ Id : debian-install-build,v 1.22 2007/01/18 18:45:31 vanbaal Exp $
# $ Source : /cvsroot/logreport/package/debian-install-build,v $, from 2001

# debian-install-build - quick and dirty script to install build environment
#      for debian package
#
# run e.g. as
#
# joostvb@nagy:~/cv...1810.com/packages/caspar% DIB_V=20030718 DIB_P=caspar \
#   DIB_TARDIR=~/cvs/topaz/ad1810.com/packages/caspar debian-install-build
#
# or as
#
#  joostvb@gelfand:~/cvs-sourceforge/logreport/package% DIB_V=20020214 \
#    DIB_P=lire DIB_TARDIR=../archive/ debian-install-build
#
# or as
#
#  joostvb@gelfand:~/cv...gelfand/debian/blackened% DIB_V=1.8.1 \
#    DIB_P=blackened DIB_TARDIR=/usr/local/src/blackened debian-install-build
#

#
# used for uruk, caspar and zoem
#

set -x

# V=`date +%y-%j`
# V=02-030

if test -z "$DIB_V"
then
    set +x
    echo >&2 "DIB_V should be set to version"
    exit 1
fi

V=$DIB_V # Version
P=${DIB_P:-mcl} # Package

set +x
echo >&2 "shouldn't you be using pbuilder(8)? it makes sure your build environment is clean.  you'll need root access.  set BUILDUSERID and BUILDUSERNAME to minimize root processes. use pbuilder-uml if you want to do everything as non-root"
echo >&2 "building $P"
set -x

TARDIR=${DIB_TARDIR:-../source}

set +x
echo >&2 "fetching tarball from $TARDIR"
set -x

S=$P-$V
B=${DIB_B:-/usr/local/src/debian/$P/$V} # Builddir

T=$S.tar.gz  # Tarball
test -d $B || mkdir -p $B

# zoem_06-080.orig.tar.gz
O=${P}_$V.orig.tar.gz

test -f $B/$O || cp $TARDIR/$T $B/$O
(
    cd $B
    test -d $S || tar zxf $O
    test -d $S/debian || mkdir $S/debian
)

#for f in debian/[^C]*
#do
#    test -f "$f" && cp "$f" $B/$S/debian
#done
cp -a debian/* $B/$S/debian

#for d in debian/po debian/patches debian/source
#do
#    if test -d $d
#    then
#        test -d $B/$S/$d || mkdir $B/$S/$d
#        cp $d/* $B/$S/$d
#    fi
#done

set +x

cat <<EOT
You might like to run 'pbuilder' in $B/$S now or 'fruitbuild-single' (see
git/uruk-pkg/debian.log)  or 'debuild -us -uc' (or stick with plain old
dpkg-buildpackage -rfakeroot [-ejoe@example.com] [-uc -us] && lintian
../*.changes) and check the .deb by running debc afterwards.  Be sure to peek
at the .diff.gz too.

NB: if you use po-ized debconf, do not forget to run podebconf-report-po at
about 1 week before uploading to the archive!
EOT