#!/bin/sh -efu

licenses_dir=/usr/share/distro-licenses

# check for valid license international text
check_license_text_all()
{
	local rc=0 f="$1" && shift || return 1
	local license_all
	local orig_license_all

	# 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_all="$check_work_dir/license.all.html"

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

	orig_license_all="$licenses_dir/$license/license.all.html"

	if ! cmp -s "$license_all" "$orig_license_all"; then
		CheckError "distro license '$license' error for license.all.html component"
		rc=1
	fi

	return $rc
}

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