#!/bin/sh -efu

need_deps='rpmlib\(PayloadIsLzma\).*'
bad_deps_4x='rpmlib\(PayloadIsLzma\).*
rpmlib\(PosttransFiletriggers\).*'
bad_deps_5x='rpmlib\(SetVersions\).*'

# check for unacceptable policy requirements
check_policyreq()
{
	local f="$1" && shift || return 1
	local rc=0
	local bad

	case "${GB_REPO_NAME-}" in
		4.*|school)
		if bad=$(printf %s "$rpm_requires" |cut -d' ' -f1 |egrep -x "$bad_deps_4x"); then
			FileError "forbidden requires: $(oneliner "$bad")" "$f"
			rc=1
		fi
		;;
		*)
		if ! printf %s "$rpm_requires" |cut -d' ' -f1 |egrep -qsx "$need_deps"; then
			FileError "missing mandatory requires: $(oneliner "$need_deps")" "$f"
			rc=1
		fi
		;;
	esac

	case "${GB_REPO_NAME-}" in
		4.0|4.1|5.0|5.1|p5)
		if bad=$(printf %s "$rpm_requires" |cut -d' ' -f1 |egrep -x "$bad_deps_5x"); then
			FileError "forbidden requires: $(oneliner "$bad")" "$f"
			rc=1
		fi
		;;
	esac

	return $rc
}

run_check() {
	if ! check_policyreq "$1"; then
		CheckError 'package dependencies violation'
		return 1
	fi
}
