build 2.41 KB
#!/bin/sh
# Usage:
# - define exp_srcpkg to the expected source package name
# - define srcdir to $(dirname $0)
# - source this

current_testing=buster

if [ -z "$exp_srcpkg" ]
then
	echo "Do not call this script directly, use the build-thunderbird or build-firefox scripts"
	exit 1
fi

srcpkg=$(dpkg-parsechangelog -S Source 2> /dev/null)

if [ -z "$srcpkg" ]
then
	echo "This script is only meant to be run from a Debian source directory"
	exit 1
fi

# Check that package matches called script
if [ "$srcpkg" != $exp_srcpkg ]
then
	echo This script is only meant to be run from a $exp_srcpkg Debian source directory
	exit 1
fi

# Get package version
version=$(dpkg-parsechangelog -S Version)
mainversion=${version%%.*}
mainversion=${mainversion#*:}

quilt pop -a

# drop any previous hypra patch list
sed -i -e '/^# hypra/,$d' debian/patches/series

# drop any previous hypra changelog
case $version in
	*+hypra*)
		version=${version%+hypra*}
		sed -i -e "1,/^$/d" -e "1,/^$/d" -e "1,/^$/d" debian/changelog
		;;
	*) ;;
esac

# check for patch series file
if [ ! -f "$srcdir/series-$mainversion" ]
then
	echo We need to update the patch series to version $mainversion
	exit 2
fi

dist=$(dpkg-parsechangelog -S Distribution)

# start new changelog entry
dch --newversion $version+hypra$(cat "$srcdir/version") "Hypra-patched upload"

# start patch series
echo "# hypra" >> debian/patches/series

# feed patches
for i in $(cat "$srcdir/series-$mainversion")
do
	# Avoid commented patches
	case $i in
		\#*) continue ;;
		*) ;;
	esac

	cp -f "$srcdir/patches-$mainversion/$i" debian/patches/
	echo "$i" >> debian/patches/series
	dch "$(head -n 1 "debian/patches/$i")"
done

# Drop spurious distribution name bits
case $dist in
	*-security)
		dist=${dist%-security}
		;;
	*)
		;;
esac

builddist=$dist
case $dist in
	unstable)
		# We want to build unstable in a testing chroot
		builddist=$current_testing
		;;
	*)
		;;
esac

dch -r -D $dist ""

# create or update pbuilder chroot
basetgz=/var/cache/pbuilder/base-$builddist.tgz
if [ ! -f $basetgz ]
then
	if ! sudo pbuilder create --distribution $builddist --basetgz $basetgz --othermirror "deb http://security.debian.org/debian-security $builddist/updates main" ; then
		echo "couldn't create chroot"
		exit 1
	fi
else
	if ! sudo pbuilder update --basetgz $basetgz ; then
		echo "couldn't update chroot"
		exit 1
	fi
fi

DEB_BUILD_OPTIONS="nocheck noddebs parallel=64" pdebuild --debbuildopts -B -- --basetgz "$basetgz"