#!/usr/bin/bash

export PATH=@MINGW_PREFIX@/bin:$PATH
echo ">>> Running mktexlsr"
@MINGW_PREFIX@/bin/mktexlsr
echo ">>> Running mtxrun (this might take a while)"
cd @MINGW_PREFIX@/etc/texmf
@MINGW_PREFIX@/bin/mtxrun --generate >/dev/null
cd -
# We need to remove directory "." from luatex cache to avoid absurd
# behaviour.
for item in @MINGW_PREFIX@/var/lib/texmf/luatex-cache/context/*/trees/*.lua; do
    if grep -F '["root"]="."' "$item" >/dev/null; then
        rm -f "$item" "${item%.lua}.luc"
    fi
done
