#!/bin/sh
set -e
set -x

# Needed to be able to reproduce the PDF output exactly.
SOURCE_DATE_EPOCH=`dpkg-parsechangelog -STimestamp`
export SOURCE_DATE_EPOCH

therion samples/morphing/sample1/thconfig.1

# Check the JPG and PDF output is the same as in the package sample, but we
# need to allow for the numeric part of the filename, which can change if more
# samples get added.

for ext in jpg pdf ; do
  matching=
  out=samples/morphing/sample1/cave1.$ext
  size=`wc -c < "$out"`
  for f in /usr/share/doc/therion-doc/samples.doc/*-cave1."$ext" ; do
    if [ `wc -c < "$f"` = "$size" ] && cmp "$f" "$out" ; then
      matching=$f
      break
    fi
  done
  if [ -z "$matching" ] ; then
    echo "'$out' not the same as any packaged sample"
    exit 1
  fi
done
