#
# This is a strictly POSIX 1003.2 shell (Bourne shell) script 
# sketching the addition of LaTeX to the TeX Kernel system: kerTeX.
#
# No shebang, since there is a bootstrapping problem: this script has
# to run on whatever host the kerTeX system runs on.
# It has to be invoked with whatever Bourne shell like interpreter is
# present on the host.
#
# C) 2010-2011 Thierry Laronde <tlaronde@polynum.com>
# All rights reserved and absolutely no warranty! Use at your own 
# risks.
#
set -e

# Needed post action (build, apply, remove) routines.
#
pkg_post_build()
{
	pkg_log "Package $PKG_NAME.tar.gz created."
}

pkg_post_apply()
{
	pkg_log "Package $PKG_NAME installed."
}

pkg_post_remove()
{
	pkg_log "Package $PKG_NAME removed."
}

#==================== AUTOMATIC PROCESSING
# First include the pecularities of the TeX kernel system host.
#
. which_kertex

# Then we now how to find the library that defines routines and does
# some checks, argument processing and initializations. See the file
# directly for explanations.
#
. $KERTEX_BINDIR/lib/pkglib.sh

#==================== CUSTOM PROCESSING: we are in TMPDIR
#
# Note: we download directly the TFM. We could generate the fonts with
# the .mf instead.
#

pkg_get

# Unpack the base (that creates a base/, so we move files afterwards).
# The doc unpacks in a dedicated subdirectory doc/, and that is OK. So
#
cd $TMPDIR/lib/$PKG_NAME
pkg_unzip base.zip
mv base/* .
pkg_rmdir base
rm base.zip

# doc unpacks in a doc/ subdirectory and that's OK.
#
pkg_unzip doc.zip
rm doc.zip

KERTEXFONTS="$TMPDIR/lib/fonts/tfm/latex:KERTEXSYS"
export KERTEXFONTS

#===== TeX version
#
# The full instructions to install are in base::manifest.txt.
#
# We start by creating files from the "packed" version distributed.
#
cd $TMPDIR/lib/$PKG_NAME # our directory
echo '\input unpack.ins' | $KERTEX_BINDIR/initex >$TMPDIR/.log 2>&1

# Several files are created. You should give a look specially to the
# .cfg files. For us, the latex.ltx is the file to dump (to create the
# format):
#
cat <<EOT | $KERTEX_BINDIR/initex
\input latex.ltx
\dump
EOT

# Put the dump where TeX (kerTeX) looks for.
#
mkdir $TMPDIR/bin/lib/
mv latex.fmt $TMPDIR/bin/lib/$PKG_NAME.fmt

# And name virtex $PKG_NAME so that he loads $PKG_NAME.fmt.
#
cp $KERTEX_BINDIR/virtex $TMPDIR/bin/$PKG_NAME

#===== e-TeX version
#
cd $TMPDIR/lib/$PKG_NAME # our directory
cat <<EOT | $KERTEX_BINDIR/einitex
*\input latex.ltx
\dump
EOT

mv latex.dgst $TMPDIR/bin/lib/$PKG_NAME.dgst

cp $KERTEX_BINDIR/evirtex $TMPDIR/bin/e$PKG_NAME

#===== CUSTOM PROCESSING FINISHED
#
# Time to do whether the build or the install.
#
pkg_do_action

# not reached
exit 0

# Since we have exited above, no need to comment out the CID.

BEGIN_CID
NAME: latex
VERSION: 2e
KERTEX_VERSION: 0.999.0.2
SOURCES:
ftp://anonymous:kertex@ftp.dante.de/
	LCD HOME/
	GET /tex-archive/macros/latex/base.zip
	GET /tex-archive/macros/latex/doc.zip
	LCD /lib/fonts/tfm/latex
	GET fonts/tfm/	/\.tfm$/
END:
END_CID


