cd ${COMPILE_DIRECTORY} &&
default_install  &&

# move old local to new local, can eventually get rid of this
if [ -d "/usr/share/texmf-local" ]; then
  mv ${INSTALL_ROOT}/usr/share/texmf-local ${INSTALL_ROOT}/usr/local/share/texmf
fi &&

ln -svf mf ${INSTALL_ROOT}/usr/bin/mf-nowin &&

# don't create aleph files
sed -i -e '/aleph/d' ${INSTALL_ROOT}/usr/share/texmf/web2c/fmtutil.cnf &&

# remove luatex stuff from config file if not enabled
if ! depends_is_enabled $SPELL lua51; then
  sed -i -e '/luatex/d' ${INSTALL_ROOT}/usr/share/texmf/web2c/fmtutil.cnf
fi &&

# create symlinks to latex, pdflatex, etc
${INSTALL_ROOT}/usr/bin/texlinks -f ${INSTALL_ROOT}/usr/share/texmf/web2c/fmtutil.cnf ${INSTALL_ROOT}/usr/bin &&

# update filename db & create all formats
mktexlsr &&
fmtutil-sys --cnffile ${INSTALL_ROOT}/usr/share/texmf/web2c/fmtutil.cnf --fmtdir ${INSTALL_ROOT}/usr/share/texmf/web2c --all &&

# allow fontconfig to see latex fonts 
install -Cv ${SPELL_DIRECTORY}/09-texlive-fonts.conf ${INSTALL_ROOT}/etc/fonts/conf.avail &&
ln -fs ${INSTALL_ROOT}/etc/fonts/conf.avail/09-texlive-fonts.conf ${INSTALL_ROOT}/etc/fonts/conf.d &&
fc-cache -fsv && 

if is_depends_enabled $SPELL lua ; then 
  # update filename db & create formats for context
  mtxrun --generate &&
  # generate fonts for luatex & context
  OSFONTDIR="${INSTALL_ROOT}/usr/share/texmf-dist/fonts/;${INSTALL_ROOT}/usr/share/texmf/fonts/;${INSTALL_ROOT}/usr/local/share/texmf/fonts" mtxrun --script fonts --reload 
fi &&

# updmap is broken without an install of TexLive::TLUtils
# This comes with the installer, which we don't use, one source:
# ftp://tug.org/texlive/historic/2012/tlnet-final/tlpkg/
# Now, there happens to be a copy here, too ... just using it.
# Rationale for the hack here: This spell installs updmap, so it should
# damn well also ensure that this tool can run.
# Proper use would install tlpkg, which we don't use, just for that lib.
mkdir -p "$INSTALL_ROOT/usr/share/tlpkg" &&
cp -vr "$SOURCE_DIRECTORY/texk/tests/TeXLive"  "$INSTALL_ROOT/usr/share/tlpkg"
