#!/bin/sh

set -e

if [ -n "$AUTOPKGTEST_TMP" ]; then
        TMP=`mktemp -q -d -p $AUTOPKGTEST_TMP`
else
        TMP=`mktemp -q -d`
fi
SOURCE_TREE=`pwd`

libreoffice --headless --convert-to tex $SOURCE_TREE/src/distro/doc/user-manual.odt -o $TMP/user-manual.tex 2>&1 | tee $TMP/convert-to.log

# sanity check. did we actually use the filter? There's none other upstream, but...
if grep -q "using filter : org.openoffice.da.writer2latex" $TMP/convert-to.log; then
	exit 0
else
	echo "Error: Did not use writer2latex, something's wrong."
	exit 1
fi

# ends up needing superabular (that's why we depend on texlive-latex-extra), but
# doesn't work in sid, see https://tex.stackexchange.com/questions/750538/supertabular-became-wrong-in-texlive-2025-06-02
#cp -v $SOURCE_TREE/src/distro/doc/w2llogo.png $TMP
#cd $TMP
#pdflatex user-manual.tex
