#!/bin/sh -efu

. gb-sh-functions

fail_if_task_abort_requested

. gb-sh-tmpdir
. gb-sh-rpmhdrcache

for arch in $GB_ARCH noarch; do
	# Regen only if there are $arch packages.
	fgrep -qsx "$arch" plan/change-arch ||
		continue
	repodir="$GB_TMP_REPO_DIR/$arch"
	# Assume that the only relevant component is "$GB_REPO_FLAVOUR".
	gb-x-gen-ci $repodir/RPMS.$GB_REPO_FLAVOUR >$tmpdir/$arch-ci &&
		mv -f $tmpdir/$arch-ci $repodir/base/contents_index ||
		stamp_echo "[$arch] FAILED to create contents_index" >> "$tmpdir"/FAIL &
done

wait

# Fail if at least one arch failed.
if [ -s "$tmpdir"/FAIL ]; then
	cat >&2 "$tmpdir"/FAIL
	exit 1
fi

stamp_echo >&2 'created contents_index files'
