#!/bin/sh
set -e

# Skip while creating the reference chroot.
if [ "$PIUPARTS_PHASE" = "" ]; then
	exit 0
fi

log_debug() {
	echo "Debug: piuparts exception for package $PIUPARTS_OBJECTS"
}

# packages to upgrade early
EARLY=

if [ "$PIUPARTS_DISTRIBUTION_NEXT" = "squeeze" ]; then

	if dpkg-query -s "octave3.0" >/dev/null 2>&1
	then
		#696377
		EARLY="$EARLY libblas3gf liblapack3gf"
	fi

	case ${PIUPARTS_OBJECTS%%=*} in
		libapt-rpm-pkg-dev)
			# libapt-rpm-pkg-dev no longer exists in squeeze
			# causing some packages to be "kept back"
			EARLY="$EARLY libreadline5-dev"
			;;
		python-pydoctor)
			# work around #696376: "/usr/sbin/update-python-modules: /usr/bin/python: bad interpreter: No such file or directory"
			EARLY="$EARLY python-pydoctor"
			;;
	esac

fi

if [ -n "$EARLY" ]; then
	log_debug
	echo "Upgrading early: ${EARLY# }"
	apt-get update
	apt-get -y install $EARLY
fi
