# globals
typeset -g \
	STAGE_GENTOO_ARCH \
	STAGE_GENTOO_MACHINE \
	STAGE_GENTOO_NAME \
	STAGE_GENTOO_BRANCH \
	STAGE_PORTAGE_TS
typeset -g -A STAGE_OVERLAY_REVNO

[[ -n $STAGE_GENTOO_NAME ]] || die 'STAGE_GENTOO_NAME needs to be set'
if [[ -z $STAGE_GENTOO_ARCH ]]; then
	case $STAGE_GENTOO_NAME in
		(latest-stage3-i[456]86*)
			STAGE_GENTOO_ARCH=x86;;
		(latest-stage3-amd64*)
			STAGE_GENTOO_ARCH=amd64;;
		(*)
			die 'STAGE_GENTOO_ARCH needs to be set for' $STAGE_GENTOO_NAME
	esac
fi

if [[ -z $STAGE_GENTOO_MACHINE ]]; then
	case $STAGE_GENTOO_NAME in
		(latest-stage3-i486*)
			STAGE_GENTOO_MACHINE=i486;;
		(latest-stage3-i586*)
			STAGE_GENTOO_MACHINE=i586;;
		(latest-stage3-i686*)
			STAGE_GENTOO_MACHINE=i686;;
		(latest-stage3-amd64*)
			STAGE_GENTOO_MACHINE=amd64;;
		(*)
			die 'STAGE_GENTOO_MACHINE needs to be set for' $STAGE_GENTOO_NAME
	esac
fi

: ${STAGE_GENTOO_BRANCH:=stable}
: ${STAGE_PORTAGE_TS:=${$(</usr/portage/metadata/timestamp.x)[1]}}

local overlay
for overlay in ccx-{bootstrap,packages,pypi} vserver-overlay; do
	if ! (($+STAGE_OVERLAY_REVNO[$overlay])); then
		STAGE_OVERLAY_REVNO[$overlay]=$(bzr revno $FSB_OVERLAY_BASE/$overlay) || \
		die "could not determine the revision of $FSB_OVERLAY_BASE/$overlay"
	fi
done