#
# This script is run from the top level scripts.  You can rely on
# the following environment variables being set:
#
#    $BARRYTARBALL  - relative path to the release source tarball (bz2)
#    $BARRYTARBASE  - basename of the source tarball (bz2)
#    $BARRYBUILDDIR - directory where results are stored
#

set -e

rm -rf /tmp/barrychroots
mkdir -p /tmp/barrychroots

#
# Build the DEB's
#
function do_ubuntu() {
	./save.sh "/tmp/barrychroots/$1" "$2" "$3" \
		./chroot.sh cdfrey /var/chroot/$1 \
			"$BARRYTARBALL make-deb.sh" \
			/var/chroot/$1/home/cdfrey/barrychroot/results \
			/tmp/barrychroots/$1 \
			cdfrey \
		./make-deb.sh "$BARRYTARBASE" \
			"fakeroot -- debian/rules binary os22-binary"
}

do_ubuntu ubuntu1004 $BARRYBUILDDIR/ubuntu1004 ubuntu1004
chown -R cdfrey:cdfrey $BARRYBUILDDIR


#
# Build the Fedora RPM's
#
function do_fedora() {
	./save.sh "/tmp/barrychroots/$1" "$2" "$3" \
		./chroot.sh cdfrey /var/chroot/$1 \
			"$BARRYTARBALL make-rpm.sh" \
			/var/chroot/$1/home/cdfrey/rpmbuild/binarybuild/results \
			/tmp/barrychroots/$1 \
			cdfrey \
		./make-rpm.sh \
			"$BARRYTARBASE" rpm/barry.spec \
			"$4" \
			/home/cdfrey \
			/home/cdfrey/rpmbuild/binarybuild
}

#
# RPM options:
#	--with gui
#	--with desktop
#	--with opensync
#	--with opensync4x
#
# fedora14 has a bug in ligcal's pkgconfig... need to edit
# its /usr/lib/pkgconfig/libgcal.pc file manually to work around it
# for now
#do_fedora fedora14 build/fedora14 f14 "rpmbuild --target i386 -ba barry.spec --with gui --with opensync --with desktop"
do_fedora fedora13 $BARRYBUILDDIR/fedora13 f13 \
	"rpmbuild --target i386 -ba barry.spec --with gui --with opensync --with desktop"
do_fedora fedora12 $BARRYBUILDDIR/fedora12 f12 \
	"rpmbuild --target i386 -ba barry.spec --with gui --with opensync --with desktop"
do_fedora fedora11 $BARRYBUILDDIR/fedora11 f11 \
	"rpmbuild --target i386 -ba barry.spec --with gui --with opensync"
chown -R cdfrey:cdfrey $BARRYBUILDDIR

#
# Cleanup
#
rm -rf /tmp/barrychroots

