Skip to content
build 2.67 KiB
Newer Older
#!/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 thunderbird-patches/build-thunderbird or firefox-patches/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#*:}
# 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/ || exit 1
	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 ""

if [ -n "$ARCH" ]; then
  architecture_option="--architecture $ARCH"
  architecture_suffix="-$ARCH"
fi

# create or update pbuilder chroot
basetgz=/var/cache/pbuilder/base-${builddist}${architecture_suffix}.tgz
if [ ! -f $basetgz ]
then
	if ! sudo pbuilder create $architecture_option --distribution $builddist --basetgz $basetgz --othermirror "deb http://security.debian.org/debian-security $builddist/updates main" ; then
		echo "couldn't create chroot"
		exit 1
	fi
	if ! sudo pbuilder update $architecture_option --basetgz $basetgz ; then
		echo "couldn't update chroot"
		exit 1
	fi
DEB_BUILD_OPTIONS="nocheck noddebs $DEB_BUILD_OPTIONS" pdebuild $architecture_option --debbuildopts -B -- --basetgz "$basetgz"