Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 108 lines (97 sloc) 2.8 KB
#!/bin/bash
# Copyright (c) Paul Tagliamonte <paultag@ubuntu.com>, 2012, under the terms
# and conditions of the Expat license.
DIST="sid"
VARIANT="default"
SBUILD=/var/sbuild
if [ "x$SBUILD_COMMAND" == "x" ]; then
if [ ! -e debian/changelog ]; then
echo "E: No debian/changelog. Run from inside your source tree."
exit 3
fi
else
echo "I: Not checking if we're in the source tree."
fi
if [ "x$1" != "x" ]; then
VARIANT=$1
fi
if [ "x$2" != "x" ]; then
DIST=$2
fi
if [ -e $SBUILD/$DIST.lock ]; then
if [ "x$SB_BREAK_WAIT" != "x" ]; then
echo "E: Not waiting for the lock to be released."
echo "E: Because of SB_BREAK_WAIT."
echo "E: Failing out."
exit 10
fi
PID=`cat $SBUILD/$DIST.lock`
echo "W: We *must* wait for the finish of PID $PID"
echo "W: Blocking execution until this file is removed."
if [ -e $SBUILD/$DIST.wait ]; then
ps --no-header `cat $SBUILD/$DIST.wait` > /dev/null
RET=$?
if [ $RET -eq 0 ]; then
echo "E: Someone else is waiting. Bombing out."
exit 2
else
echo "I: Somone else was waiting, but their PID is gone."
fi
fi
echo $$ > $SBUILD/$DIST.wait
while [ -e $SBUILD/$DIST.lock ]; do
sleep 1
done
echo "I: Dropping out of lock. Purging wait."
rm $SBUILD/$DIST.wait
fi
echo "I: Aquiring lock"
echo $$ > $SBUILD/$DIST.lock
CURRENT=$(readlink $SBUILD/$DIST)
CPUCOUNT=`cat /proc/cpuinfo | grep "^processor" | wc -l`
# We set up the name like:
# dist-variant
# such as "sid-clang" is cool.
#echo "I: We're currently $CURRENT."
if [ "x$CURRENT" == "x$DIST-$VARIANT" ]; then
echo "I: This matches the desired setup. No action."
else
if [ -e $SBUILD/$DIST.d/$DIST-$VARIANT ]; then
echo "I: Re-setting $DIST symlink."
rm $SBUILD/$DIST
ln -s $SBUILD/$DIST.d/$DIST-$VARIANT $SBUILD/$DIST
else
echo "E: No such dist! Looking in $SBUILD/$DIST.d/$DIST-$VARIANT."
rm $SBUILD/$DIST.lock
exit 1
fi
fi
echo "I: "
echo "I: Dist: $DIST"
echo "I: Variant: $VARIANT"
echo "I: CPUs (-j): $CPUCOUNT"
echo "I: "
RET=0
if [ "x$SBUILD_COMMAND" == "x" ]; then
sb-prehook $VARIANT $DIST
if [ "x$SBUILD_DSC" == "x" ]; then
CHANGELOG="$(dpkg-parsechangelog)"
SOURCE="$(echo "$CHANGELOG" | grep Source | sed s/Source:\ //g)"
VERSION="$(echo "$CHANGELOG" | grep Version | sed s/Version:\ //g)"
DSC=${SOURCE}_${VERSION}.dsc
echo "I: Building source"
dpkg-buildpackage -us -uc -sa -S
cd ..
else
DSC=$SBUILD_DSC
fi
sbuild -v --source -A -d $DIST -j $CPUCOUNT $DSC $SB_SBUILD_OPTS
RET=$?
cd -
sb-posthook $VARIANT $DIST
else
$SBUILD_COMMAND $DIST
fi
echo "I: Releasing lock"
rm $SBUILD/$DIST.lock
exit $RET