# vim: ft=zsh noet sw=4 ts=4 sts=4

confz_PORTAGE_GPG_DIR_check() {
	defvar makeconf /etc/portage/make.conf
	checkvars makeconf gpgdir
	[[ -e $vars[makeconf] ]] || \
		die "make.conf not found at ${(qqq)vars[makeconf]}"

	local gpgdir
	gpgdir=$(portageq envvar PORTAGE_GPG_DIR) || die portageq failed

	if [[ -z $gpgdir ]]; then
		fail_reason="PORTAGE_GPG_DIR not set"
		return 1
	elif [[ $gpgdir != $vars[gpgdir] ]]; then
		die "PORTAGE_GPG_DIR set to different value from ${(qqq)vars[gpgdir]}"
	else
		return 0
	fi
}

confz_PORTAGE_GPG_DIR_do() {
	print -r - >>$vars[makeconf] PORTAGE_GPG_DIR="${(qqq)vars[gpgdir]}"
}


confz_FEATURES_check() {
	defvar makeconf /etc/portage/make.conf
	checkvars makeconf feature
	[[ -e $vars[makeconf] ]] || \
		die "make.conf not found at ${(qqq)vars[makeconf]}"

	local f
	local -a features
	features=( $(portageq envvar FEATURES) ) || die portageq failed

	for f in $features; do
		[[ $f == $vars[feature] ]] && return 0
	done
	fail_reason="FEATURES=$vars[feature] not set"
	return 1
}

confz_FEATURES_do() {
	print -r - >>$vars[makeconf] FEATURES=\""\$FEATURES $vars[feature]"\"
}


confz_webrsync-gpg_check() {
	defvar gpgdir $site_script_dir/webrsync-gpg/gnupg
	require PORTAGE_GPG_DIR :makeconf :gpgdir
	require FEATURES :makeconf feature=webrsync-gpg
}