#!/bin/sh
set -e

case "$PIUPARTS_DISTRIBUTION" in
	squeeze*) ;;
	*) exit 0 ;;
esac

case "$PIUPARTS_DISTRIBUTION_NEXT" in
	lenny*|squeeze*) exit 0 ;;
esac

test "$(dpkg --print-architecture)" = "amd64" || exit 0

go=

case ${PIUPARTS_OBJECTS%%=*} in
	ia32-libs|ia32-libs-gtk)  go=yes ;;
	lib32nss-mdns)  go=yes ;;
	*)
		dpkg-query -s "ia32-libs" >/dev/null 2>&1 || exit 0
		;;
esac

case ${PIUPARTS_OBJECTS} in
	*=None)  go=yes ;;
esac

case ${PIUPARTS_OBJECTS%%=*} in
	*wine*)  go=yes ;;
	education-thin-client-server|education-workstation)  go=yes ;;
	playonlinux)  go=yes ;;
esac

test -n "$go" || exit 0

echo "Enabling foreign architecture i386 for $PIUPARTS_OBJECTS"
apt-get update
apt-get -y install apt dpkg
dpkg --add-architecture i386
