#!/bin/sh
#$Id: get_mk_install.sh,v 1.3 2012/01/13 15:53:06 tlaronde Exp $
# C) 2012 Thierry Laronde <tlaronde@polynum.com>
#
# All rights reserved and no warranty! Run it at your risks!
#

# Stop if error
#
set -e

cat <<EOT

This script is for a Unix like OS.

Be sure to run me in a dir where there is enough place for the
sources unpacked (40 Mb will do; I will _not_ remove the bundle).

During the build, don't be afraid of some compiler warnings: these
are purely cosmetic ones, because the translation of Pascal in C
don't put extra braces when indenting if/else; or because D.E. Knuth 
and Silvio Levy have written the CWEB programs so that they can compile
even on pre-ANSI C compilers (old prototypes).

Don't worry: if something is really wrong, the build fails...

I will build in SAVE_SPACE mode, requiring the minimal amount of
place.

When files have to be installed, I will have to switch under root.
Once, for kerTeX install. Once, for the installation of dumps and
compiled fonts.

Don't run me as root now! (R.I.S.K. and the kerTeX package framework
will refuse.)

EOT

echo -n "Which version of the install doc do you want (en|fr)? [en] "

read ans

case "$ans" in
	fr) ftp http://downloads.kergis.com/LISEZ.MOI
		;;
	*) ftp http://downloads.kergis.com/README
		;;
esac

# Get the bundle.
#
ftp http://downloads.kergis.com/kertex_bundle.tar


test -s kertex_bundle.tar\
	|| { echo "Getting the bundle failed..."; exit 1; }

# Untar the bundle.
#
tar xf kertex_bundle.tar

for src in knuth etex bibtex ams adobe kertex_M kertex_T risk_comp; do
	tar xzf ${src}_*.tar.gz
	rm ${src}_*.tar.gz
done

# Start compiling kertex_M.
#
( 
	cd kertex_M;
	cd `../risk_comp/sys/posix/sh/rkconfig`;
	make SAVE_SPACE=YES;
)

# Then compile kertex_T.

cd kertex_T
cd `../risk_comp/sys/posix/sh/rkconfig`
make SAVE_SPACE=YES

echo -n "Do you want to install kerTeX here now? [Yn] "

read ans

test "x$ans" != x || ans=YES

case $ans in
	y|Y|yes|YES)
		;;
	*) make pkg;
		echo "I have built the package here: $pwd/PKG.tar";
		exit 0;
		;;
esac

# We are installing...
#
make local_install

echo -n "Do you want to generate the dumps and the fonts now? [Yn] "

read ans

test "x$ans" != x || ans=YES

case $ans in
	y|Y|yes|YES) . which_kertex;
		$KERTEX_SHELL $KERTEX_BINDIR/adm/pkg_core install
		exit 0
		;;
	*) echo "You can generate them later running: adm/pkg_core";
		;;
esac

# Not reached.
#
exit 0

