f3820b9
#!/bin/sh
f3820b9
f3820b9
# Based on Enrico's snippet for using pdflatex for building PDFs, except we're
f3820b9
# switching to pregenerating the docs for the SRPM so that we don't get
f3820b9
# different contents when we build on multiple build machines and architectures
f3820b9
# (timestamps and IDs change, and even some of the compressed content looks
f3820b9
# different).  The filename and checksum are used to verify that the PDF always
f3820b9
# matches the doc which was used to generate it, and we flag an error if that
f3820b9
# isn't the case.
f3820b9
f3820b9
create() {
f3820b9
	pushd "$1" > /dev/null
f3820b9
	touch "$2".ind
f3820b9
	pdflatex "$2"
f3820b9
	test ! -e "$2".idx || makeindex ${3:+-s "$3".ist} "$2".idx
f3820b9
	pdflatex "$2"
f3820b9
	pdflatex "$2"
f3820b9
	sum=`sha1sum "$2".tex | sed 's,[[:blank:]].*,,g'`
f3820b9
	sed -ri \
f3820b9
		-e 's|^/ID \[<.{32}> <.{32}>\]|/ID [<'"$1/$2"'> <'"$sum"'>]|g' \
f3820b9
		"$2".pdf
f3820b9
	popd > /dev/null
f3820b9
}
f3820b9
f3820b9
check() {
f3820b9
	pushd "$1" > /dev/null
f3820b9
	sum=`sha1sum "$2".tex | sed 's, .*,,g'`
f3820b9
	id=`sed -rn -e '/^\/ID \[<[^>]*> <[^>]*>\]/p' "$2".pdf`
f3820b9
	filename=`echo "$id" | sed -r 's|^.*\[<([^>]*)> <([^>]*)>\].*|\1|g'`
f3820b9
	checksum=`echo "$id" | sed -r 's|^.*\[<([^>]*)> <([^>]*)>\].*|\2|g'`
f3820b9
	echo $filename
f3820b9
	echo $checksum $sum
f3820b9
	popd > /dev/null
f3820b9
	test "$filename" = "$1/$2" && test "$checksum" = "$sum"
f3820b9
}
f3820b9
f3820b9
mode=$1
f3820b9
case $mode in
f3820b9
	create)
f3820b9
	while read subdir doc style ; do
f3820b9
		if ! create $subdir $doc $style ; then
f3820b9
			exit 1
f3820b9
		fi
f3820b9
	done
f3820b9
	;;
f3820b9
	check)
f3820b9
	while read subdir doc style ; do
f3820b9
		if ! check $subdir $doc $style ; then
f3820b9
			exit 1
f3820b9
		fi
f3820b9
	done
f3820b9
	;;
f3820b9
esac
f3820b9
f3820b9
exit 0