#!/bin/sh -efu

. gb-sh-functions

arch="$1"; shift
[ -s plan/arepo-add-$arch -o -s plan/arepo-rm-$arch ] || exit 0
arch_to=${arch%%-*}

acomp=${GB_AREPO_COMPONENT_NAME:-$GB_REPO_FLAVOUR}

. gb-sh-tmpdir
cd "$tmpdir"

# dump unmets, assuming that the only relevant $GB_TMP_REPO_DIR component is "$GB_REPO_FLAVOUR"
cat > sources.list << EOF
rpm file:$GB_TMP_REPO_DIR $arch_to $GB_REPO_FLAVOUR
rpm file:$GB_TMP_REPO_DIR noarch $GB_REPO_FLAVOUR
rpm file:$GB_AREPO_DIR $arch $acomp
EOF
sed -e "s/@arch@/$arch_from/" "$GB_REPO_SOURCES" >>"sources.list"
sed -e "s/@arch@/$arch_from/" "$GB_REPO_SELF_SOURCES" >>"sources.list"
unmets ${GB_APT_CACHE_LIMIT:+-l $GB_APT_CACHE_LIMIT} -s sources.list > unmets

if [ -s unmets ]; then
	echo "  $arch: NEW unmet dependencies detected:"
	cat unmets
	#stamp_echo >&2 "[$arch] dependencies check FAILED"
	exit 1
fi

stamp_echo >&2 "[$arch] dependencies check OK"
