#!/bin/sh
set -ve

name=bash
version=$(
    schroot -c "$1-sbuild" -- apt-cache showsrc "$name" | \
	sed -n 's/^Version: \(.*\)$/\1/ p' | (
	version='~~~'
	while read -r newversion; do
	    if dpkg --compare-versions "$newversion" '>' "$version"; then
		version=$newversion
	    fi
	done
	if [ "$version" = '~~~' ]; then
	    echo "No version of $name found." >&2
	    exit 1
	fi
	echo "$version"
	)
)
daversion=${version}debathena4

sbuildhack "$@" "${name}_$daversion.dsc"
