#!/bin/sh
set -e

# Return a non-zero error code to have piuparts skip testing an
# uninstallable (or otherwise untestable) package.

# Packages in main don't qualify for "external services out of our
# control". They only qualify for "utterly broken" once on archive.d.o.
# There are very few exceptions to this rule:
# - usrmerge, which is one-way.
# - localepurge, which seems hard to undo without a complete --reinstall.

skip_test()
{
	echo "Skipping piuparts test: $*"
	exit 1
}

fail_test()
{
	echo "Failing piuparts test: $*"
	exit 2
}

skip_always()
{
	skip_test "$@"
}

skip_distupgrade()
{
	if [ "$PIUPARTS_TEST" = "distupgrade" ]; then
		skip_test "$@"
	fi
}


# * For uninstallable *broken* packages we usually run the normal
#   installation+purge tests (which will fail and get the package marked
#   as bugged) and only skip the distupgrade tests since there is no point
#   in upgrading something that could not be installed as a start.
#   Automatically marking the upgrade logs as bugged would also be more
#   difficult, since the bug is in some *old* version.
# * For packages requiring *external resources* not available in piuparts
#   we usually skip the failing initial install, too, since that is
#   *not a bug* in the package.

case ${PIUPARTS_OBJECTS%%=*}@${PIUPARTS_DISTRIBUTION} in
	acgvision-agent@squeeze)
		# removed after squeeze
		skip_distupgrade "#688231: modifies conffiles: /etc/acgvision/agent.ini"
		;;
	arden@jessie)
		if [ "$(dpkg --print-architecture)" = "i386" ]; then
			skip_distupgrade "arch:all package no longer installable in stretch/i386"
		fi
		;;
	blootbot@lenny)
		skip_distupgrade "#502753: fails to install: prompts without using debconf"
		;;
	bugzilla3@lenny)
		# fixed in squeeze, removed after squeeze, excluded from squeeze-lts
		skip_distupgrade "was excluded from squeeze-lts"
		;;
	chef-solr@wheezy|\
	chef-expander@wheezy|\
	chef-server-api@wheezy)
		skip_distupgrade "#681573: chef-solr: fails to install if policy-rc.d forbids to start services"
		;;
	cpushare@wheezy)
		# removed after wheezy
		skip_distupgrade "#689885: Ships a folder in /var/run or /var/lock"
		;;
	dict-stardic@lenny)
		# removed after lenny
		skip_distupgrade "#523770: must use invoke-rc.d"
		;;
	distributed-net@lenny|\
	distributed-net@squeeze)
		skip_distupgrade "#655922: noninteractive install: postinst loops infinitely"
		;;
	dnscache-run@lenny)
		skip_distupgrade "#664848: breaks dns resolution in chroot"
		;;
	docbookwiki@lenny)
		# removed after lenny
		skip_distupgrade "unconditionally uses mysql-client during purge"
		;;
	drupal6-trans-ru@squeeze)
		# removed after squeeze
		skip_distupgrade "#689252: installs files in /usr/share/drupal6/profiles which is a symlink in the drupal package"
		;;
	dynare-matlab@squeeze)
		skip_distupgrade "requires a matlab installation"
		;;
	dynare-matlab@*|\
	matlab-gdf@*|\
	matlab-support@*)
		skip_always "requires a matlab installation"
		;;
	firebird2.0-classic@lenny)
		# removed after lenny
		skip_distupgrade "#574220: package purge (after dependencies removal) fails"
		;;
	fossology@squeeze|\
	fossology-agents@squeeze|\
	fossology-agents-single@squeeze|\
	fossology-scheduler@squeeze|\
	fossology-web@squeeze|\
	fossology-web-single@squeeze)
		skip_distupgrade "#595593: fails to install"
		;;
	gclcvs@squeeze)
		# removed after squeeze
		skip_distupgrade "modifies conffiles: /etc/default/gclcvs"
		;;
	geordi@lenny)
		# removed after lenny
		skip_distupgrade "modifies conffiles: /etc/geordi/irc-config"
		;;
	ldap2dns@lenny)
		skip_distupgrade "#671671: fails to install"
		;;
	libpam-rsa@lenny)
		# removed after lenny
		skip_distupgrade "modifies conffiles: /etc/security/pam_rsa.conf"
		;;
	libpils0@lenny|\
	libpils-dev@lenny|\
	libstonith0@lenny|\
	libstonith-dev@lenny)
		skip_distupgrade "#702055: transitional packages uninstallable in lenny"
		;;
	localepurge@*)
		skip_distupgrade "requires a full --reinstall to restore disappeared files"
		;;
	mailreader@lenny)
		# removed after lenny
		skip_distupgrade "modifies conffiles: /var/lib/mailreader/ads/debian/ad.cfg, /etc/mailreader/{main,server}.cfg"
		;;
	mediamate@lenny)
		# removed after lenny
		skip_distupgrade "#574228: package purge (after dependencies removal) fails"
		;;
	mhc@lenny)
		skip_distupgrade "#696231: fails to install: emacs-package-install failure"
		;;
	mini-buildd-bld@squeeze|\
	mini-buildd-rep@squeeze)
		skip_distupgrade "#632955, #656746: time limit exceeded during install"
		fail_test "#632955, #656746: time limit exceeded during install"
		;;
	multex-bin@lenny)
		skip_distupgrade "#668791: fails to install: The format file of 'multex' is NOT built successfully."
		;;
	nautilus-dropbox@wheezy)
		skip_distupgrade "#770402: downloads awfully slow, hangs during installation"
		;;
	nessusd@lenny|\
	harden-remoteaudit@lenny)
		# removed after lenny
		skip_distupgrade "nessusd: modifies conffiles: /etc/nessus/nessusd.conf"
		;;
	openvas-server@squeeze|\
	harden-remoteaudit@squeeze|\
	openvas-server-dev@squeeze)
		# removed after squeeze
		skip_distupgrade "#688379: openvas-server: modifies conffiles: /etc/openvas/openvasd.conf"
		;;
	pdbv@lenny)
		# removed after lenny
		skip_distupgrade "modifies conffiles: /etc/pdbv/pdbvrc"
		;;
	poker-web@squeeze)
		# removed after squeeze
		skip_distupgrade "#698533: modifies a shipped file: /usr/share/poker-web/currency_one.php"
		;;
	python-milter@lenny|\
	spf-milter-python@lenny)
		skip_always "virus signatures in python-milter may trigger the firewall"
		;;
	python-poker-stats@squeeze)
		# removed after squeeze
		skip_distupgrade "#608646: cronjob exits with error after package removal"
		;;
	rt3.6-rtfm@lenny)
		# removed after lenny
		skip_distupgrade "fails to purge: rt3.6-rtfm.postrm: ucf: not found"
		;;
	rt3.8-rtfm@squeeze)
		# removed after squeeze
		skip_distupgrade "fails to purge: rt3.8-rtfm.postrm: ucf: not found"
		;;
	runit-run@lenny)
		skip_distupgrade "#542157: fails to install"
		;;
	sdic-eijiro@lenny)
		skip_distupgrade "requires a dictionary CD"
		;;
	sdic-eijiro@*)
		skip_always "requires a dictionary CD"
		;;
	steam@jessie)
		skip_distupgrade "#772598: cannot preseed licence acceptance"
		;;
	sun-java5-doc@lenny|\
	sun-java6-doc@lenny)
		skip_distupgrade "#709967: fails to install: download location no longer available"
		;;
	trn@lenny)
		skip_distupgrade "fails to install: prompts without using debconf"
		;;
	ttf-root-installer@lenny)
		skip_always "fails to install: download location disappeared"
		;;
	usrmerge@*)
		skip_always "performs piuparts-unfriendy filesystem layout changes"
		;;
	xul-ext-compactheader@wheezy)
		if [ "$(apt-cache show xul-ext-compactheader | sed -n '/^Version:/s/^Version: //p')" = "2.0.5-1" ]; then
			skip_distupgrade "#837387: uninstallable in wheezy with icedove (>= 1:45)"
		fi
		;;
	xul-ext-compactheader@jessie)
		if [ "$(apt-cache show xul-ext-compactheader | sed -n '/^Version:/s/^Version: //p')" = "2.0.8-1" ]; then
			skip_distupgrade "#837387: uninstallable in jessie with icedove (>= 1:45)"
		fi
		;;
esac
