#
# This is a strictly POSIX 1003.2 shell (Bourne shell) script
# adding the LaTeX lm font package 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) 2012 Yellow Rabbit <yrabbit@sdf.lonestar.org>
# (simple adaptation for geometry of one of Thierry Laronde's scripts)
# All rights reserved and absolutely no warranty! Use at your own
# risks.
#

# Needed post action (build, apply, remove) routines.
#
pkg_post_build()
{
	return 0 # 
}

pkg_post_apply()
{
	return 0 #
}

pkg_post_remove()
{
	return 0 #
}

#==================== 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
#
#

pkg_get

cd $TMPDIR/lib/$PKG_NAME/..
$PKG_UNZIP geometry.zip
rm geometry.zip
cd $TMPDIR/lib/$PKG_NAME
$KERTEX_BINDIR/latex geometry.ins

# patch
# comment out pdf output 
$PKG_SED \
  -e 's/\\RequirePackage{ifpdf}%/%\\RequirePackage{ifpdf}%/g' \
  -e 's/\\RequirePackage{ifvtex}%/%\\RequirePackage{ifvtex}%/g' \
  -e 's/\\RequirePackage{ifxetex}%/\\newif\\ifpdf\\pdffalse\\newif\\ifvtex\\vtexfalse\\newif\\ifxetex\\xetexfalse%\\RequirePackage{ifxetex}%/g' \
  geometry.sty >geometry.sty.new 

# correct dvips driver
cat <<EOF >patch.sed
/AtBeginDvi{\\\\special{papersize=\\\\the\\\\paperwidth,\\\\the\\\\paperheight}}%/ {
h
n
H
n
H
n
H
g
s/AtBeginDvi{\\\\special{papersize=\\\\the\\\\paperwidth,\\\\the\\\\paperheight}}%.*\\\\fi.*\\\\fi.*\\\\ifx\\\\Gm@driver\\\\Gm@dvips/AtBeginDvi{\\\\special{papersize=\\\\the\\\\paperwidth,\\\\the\\\\paperheight}}% \\\\fi \\\\ifx\\\\Gm@driver\\\\Gm@dvips/
}
p

EOF

$PKG_SED -n -f patch.sed geometry.sty.new >geometry.sty

rm geometry.sty.new
rm patch.sed

#===== 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/geometry
VERSION: 5.6
LICENCE: LaTeX Project Public License version 1.3c or any later version.
KERTEX_VERSION: 0.9999.4.2
KXPATH:
	latex geometry
SOURCES:
ftp://anonymous:yrabbit@ftp.ctan.org/
    LCD HOME/..
	GET /tex-archive/macros/latex/contrib/geometry.zip
END:
END_CID
