#!/bin/bash set -e set -u if [ "${1:-}" == "--binary-only" ]; then BINARY_ARCH="--binary-arch" BINARCH=1 shift else BINARCH=0 fi if ! which grep-dctrl > /dev/null; then echo "grep-dctrl not found. Maybe install dctrl-tools?" exit 1 fi if ! which changestool > /dev/null; then echo "changestool not found. Maybe install reprepro?" exit 1 fi gpgcat() { local f="$1" if egrep -q "^-----BEGIN PGP SIGNED MESSAGE-----" "$f"; then gpg < "$f" else cat "$f" fi } get_metadata() { local dsc="$1"; shift dsc="$(readlink -f "$dsc")" local origtar="$(dcmd --orig $dsc)" if ! [ -e "$origtar" ]; then echo >&2 "File $origtar not found" exit 1 fi local dirname="$(tar tzf $origtar | head -n1)" dirname="${dirname%%/}" local tmpdir="`mktemp -d`" pushd . >/dev/null cd "$tmpdir" dpkg-source -x "$dsc" > /dev/null cd "$dirname" local dist=$(dpkg-parsechangelog | grep-dctrl -n -s Distribution '') local ver=$(dpkg-parsechangelog | grep-dctrl -n -s Version '') popd >/dev/null rm -rf "$tmpdir" echo "$dist $ver" } DSC="${1:-}"; shift if [ -z "$DSC" ] || [ -z "$BINARCH" ]; then echo "Usage: $0 [--binary-arch] " >&2 exit 1; fi metadata="$(get_metadata "$DSC")" read dscdist debian_version <<< "$metadata" sourcepkg="$(gpgcat "$DSC" | grep-dctrl -n -s Source '')" if [ -z "${ARCH:-}" ]; then if [ "`uname -m`" = "x86_64" ]; then ARCH="amd64" elif [ "`uname -m`" = "i386" ] || [ "`uname -m`" = "i686" ]; then ARCH="i386" else echo >&2 "Do not know arch" exit 1 fi fi if [ -z "${DIST:-}" ]; then DIST=sid for d in lenny squeeze wheezy dapper hardy karmic lucid maverick natty oneiric precise; do if echo $debian_version | grep -q "$d" ; then DIST="$d" break fi done if command -v "sbuild-override-dist-$sourcepkg" >/dev/null 2>&1; then NEWDIST=$("sbuild-override-dist-$sourcepkg" "$DIST" "$DSC" "$ARCH") [ -z "$NEWDIST" ] || DIST="$NEWDIST" fi fi if [ "$DIST" = "SKIP" ] ;then echo "skipping build for $DSC because DIST is $DIST." exit 0 fi if [ "$BINARCH" = 1 ]; then extra="${EXTRA_ARGS:-}" else extra="${EXTRA_ARGS:-} -s --arch-all" fi sbuild --arch="$ARCH" --dist="$DIST" --apt-update $extra "$DSC" changesfile="${DSC%.dsc}_$ARCH.changes" if ! [ -e "$changesfile" ]; then echo >&2 "Expected file $changesfile does not exist" exit 1 fi changestool "$changesfile" setdistribution "$dscdist"