#!/bin/sh -efu

licenses_dir=/usr/share/distro-licenses

# check for valid license russian text
check_license_text_ru()
{
	local rc=0 f="$1" && shift || return 1
	local license_ru
	local orig_license_ru

	# Do not check not supported distro types
	[ "$distro_type" == iso ] || return 0

	# Do not run without distro license
	[ -n "$license" ] || return 1

	if [ ! -d "$licenses_dir/$license" ]; then
		FileError "distro license directory for '$license' not found"
		return 1
	fi

	license_ru="$check_work_dir/license.ru.html"

	if ! isoinfo -i "$f" -R -f | grep -q "^/license.ru.html$"; then
		FileError 'license.ru.html not found'
		return 1
	fi
	isoinfo -i "$f" -R -x "/license.ru.html" >"$license_ru"

	orig_license_ru="$licenses_dir/$license/license.ru.html"

	if ! cmp -s "$license_ru" "$orig_license_ru"; then
		CheckError "distro license '$license' error for license.ru.html component"
		rc=1
	fi

	return $rc
}

run_check() {
	if ! check_license_text_ru "$1"; then
		CheckError 'unacceptable russian license text'
		return 1
	fi
}
