#!/bin/sh -efu
#
# brp-verify-info - verify texinfo files.
#
# Copyright (C) 2009  Dmitry V. Levin <ldv@altlinux.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#

. /usr/lib/rpm/functions
ValidateBuildRoot

cd "$RPM_BUILD_ROOT"

INFODIR=$RPM_BUILD_ROOT/usr/share/info
[ -d "$INFODIR" ] || exit 0

RPM_VERIFY_INFO_METHOD="${RPM_VERIFY_INFO_METHOD## }"
RPM_VERIFY_INFO_METHOD="${RPM_VERIFY_INFO_METHOD%% }"
echo "Verifying info files in $INFODIR ($RPM_VERIFY_INFO_METHOD)"

strict=1
case "$RPM_VERIFY_INFO_METHOD" in
	false|no|none|off|skip) exit 0;;
	normal|strict) strict=1;;
	relaxed) strict=;;
	*) Fatal "Unrecognized verify info method: $RPM_VERIFY_INFO_METHOD";;
esac

install_info="$(PATH=/sbin:/usr/sbin:/bin:/usr/bin type -p install-info)"
[ -x "$install_info" ] ||
	Fatal 'install-info utility is not available'

rc=0
for f in $(find "$INFODIR" -xtype f); do
	t=${f##*/}
	t=${t%.gz}
	t=${t%.bz2}
	t=${t%.lzma}
	t=${t%.xz}
	case "$t" in
		 dir|*-[0-9]|*-[1-9][0-9]|*-[1-9][0-9][0-9])
			continue;;
	esac
	"$install_info" --test --dir-file=/dev/null --info-file="$f" |
		grep -qs '^test mode' || rc=1
done

[ -z "$strict" ] || exit $rc
