#!/bin/bash

# buildpackge using pbuilder.

# Prerequesite:
# builbot_make_orig_source run
# pbuilder setup.

# you need to setup sudo to allow the buildbot user to running pdebuild.
# you also need to allow sudo pbuilder update


# Result:
# hopfully a debian package...

set -e

VERSION=$(grep "PACKAGE_VERSION=" configure | cut -d"=" -f 2- | tr --delete "\'")

# check if we can skip pbuilder update -- we do it only once after an apt-get update
# for this we compare the time against the last modification of /var/lib/apt/lists
LAST_UPDATE=$(stat -c %Y /var/cache/pbuilder/base.tgz)
LISTS_TIMESTAMP=$(stat -c %Y /var/lib/apt/lists)
if [[ $LAST_UPDATE -lt $LISTS_TIMESTAMP ]]
then
	sudo /usr/sbin/pbuilder update
fi

( cd stagedir_debbuild/solarpowerlog-$VERSION && pdebuild --debbuildopts "-j2" )


