#! /bin/sh
### ====================================================================
### Source this file to change the environment to use the TeXlive
### distribution of TeX.
###
### Usage:
###	. /opt/uumath/skel/SYS.texlive-2024.sh
###	. /usr/uumath/skel/SYS.texlive-2024.sh
###
### [04-Feb-2025] -- update for TeXLive 2025 release
### [05-Mar-2024] -- update for TeXLive 2024 release
### [18-Feb-2023] -- update for TeXLive 2023 release
### [05-Jan-2022] -- update for TeXLive 2022 release
### [06-Jan-2021] -- update for TeXLive 2021 release
### [23-Dec-2019] -- update for TeXLive 2020 release
### [07-Mar-2019] -- update for TeXLive 2019 release
### [17-Jan-2018] -- update for TeXLive 2018 release
### [04-Feb-2017] -- update for TeXLive 2017 release
### [30-Mar-2016] -- update for TeXLive 2016 release
### [28-Mar-2015] -- update for TeXLive 2015 release
### [08-Apr-2014] -- update for TeXLive 2014 release
### [30-Mar-2013] -- update for TeXLive 2013 release
### [14-Apr-2012] -- update for TeXLive 2012 release
### [30-May-2011] -- update for TeXLive 2011 release
### [08-Oct-2010] -- update for TeXLive 2010 release
### [09-Jul-2009] -- update for TeXLive 2009 release
### [22-Aug-2008] -- update for TeXLive 2008 release
### [20-Aug-2008] -- update for sun4v architecture
### [30-Nov-2007] -- update for TeXlive 11/2007 release
### [01-Jul-2007] -- update with TEXMFDBS and extra TEXINPUTS directories
### [16-Mar-2007] -- update for TeXlive 9/2003
### [27-Aug-2003] -- update with TEXMFCNF setting
### [27-Jan-2003] -- update for TeXlive7
### [19-Jul-2001] -- update for TeXlive6
### [22-May-2001] -- update for TeXlive5d
### [04-Aug-1999]
### ====================================================================

unset BIBINPUTS DVIPSHEADERS MFINPUTS TEXCONFIG TEXFONTS TEXFORMATS TEXINPUTS TEXPKS VFFONTS XDVIFONTS
unalias amslatex amstex latex latex209 latex2e pdflatex pdftex tex 2>/dev/null

TEXLIVEYEAR=2025

### Some TeX Live 2018 binaries cannot run on Red Hat 6 and CentOS 6,
### so fall back to previous year.
### [09-May-2019] no longer needed: test -f /etc/redhat-release && fgrep -q -s 'release 6' /etc/redhat-release && TEXLIVEYEAR=2017

### On some of our systems, /usr/local has been usurped by the package
### manager, so our local builds are in /usr/uumath.  We therefore
### check for both.
TEXLIVE=/usr/uumath/texlive/$TEXLIVEYEAR
test -d $TEXLIVE || TEXLIVE=/usr/local/texlive/$TEXLIVEYEAR
test ! -d $TEXLIVE && echo ERROR: No TeX Live $TEXLIVEYEAR on this system && exit 1

case `uname -s` in
	AIX)		BINDIR=powerpc-aix ;;
	Darwin)
			case `uname -m` in
			Power*)
			    # BINDIR=powerpc-darwin ;;
			    BINDIR=universal-darwin ;;
			i386)
			    # BINDIR=i386-darwin
			    BINDIR=universal-darwin ;;
			x86_64)
			    ## BINDIR=x86_64-darwin
			    ## NB: This BINDIR value is our LOCAL one, NOT from the TeX Live 2016 team!
			    BINDIR=x86_64-macosx1010
			    ;;
			*)
			    echo No TeX Live $TEXLIVEYEAR for this system ; exit 1 ;;
			esac
			;;
	DragonFly)	BINDIR=x86_64-dragonfly ;;
	FreeBSD)
			case `uname -m` in
			amd64)
			    case `uname -r` in
			    13.*)		BINDIR=amd64-freebsd130 ;;
			    14.*)		BINDIR=amd64-freebsd140 ;;
			    *)			BINDIR=amd64-freebsd 	;;
			    esac
			    ;;
			arm64)
			    BINDIR=arm64-freebsd ;;
			i386)
			    case `uname -r` in
			    8.2-RELEASE) 	BINDIR=i386-freebsd8.2 ;;
			    *)			BINDIR=i386-freebsd    ;;
			    esac
			    ;;
			powerpc)
			    BINDIR=powerpc-freebsd ;;
			riscv)
			    BINDIR=riscv-freebsd ;;
			*)
			    echo No TeX Live $TEXLIVEYEAR for this system ; exit 1 ;;
			esac
			;;
	GNU)		BINDIR=i386-gnu-hurd ;;
	GNU/kFreeBSD)	BINDIR=x86_64-kfreebsd7 ;;
	IRIX64)		BINDIR=mips-irix ;;
	LibertyBSD)
			case `uname -m` in
			i386)	BINDIR=i386-libertybsd ;;
			amd64)	BINDIR=amd64-libertybsd ;;
			esac
			;;
	Linux)		case `uname -m` in
			aarch64)
				BINDIR=aarch64-linux ;;
			alpha)
				BINDIR=alpha-linux ;;
			armv7l)
				BINDIR=armv7l-linux ;;
			i686)
				BINDIR=i386-linux
				## NB: This BINDIR value is our LOCAL one, NOT from the TeX Live 2016 team!
				BINDIR=i386-centos5
				;;
			ia64)		# use IA-32 binaries for now
				# BINDIR=i386-linux ;;
				# TeX Live 2015 has a native IA-64 build
				BINDIR=ia64-linux
				;;
			loongarch64)
				BINDIR=loongarch64-linux ;;
			m68k)
				BINDIR=m68k-linux ;;
			mips)
				BINDIR=mips32-linux ;;
			mips64)
				BINDIR=mips64-linux ;;
			parisc)
				BINDIR=parisc32-linux ;;
			parisc64)
				BINDIR=parisc64-linux ;;
			ppc)
				BINDIR=powerpc-linux ;;
			ppc64)
				BINDIR=ppc64-linux ;;
			ppc64le)
				BINDIR=ppc64le-linux ;;
			riscv64)
				BINDIR=riscv64-fedora32 ;;
			s390x)
				BINDIR=s390x-linux ;;
			sparc64)
				## BINDIR=sparc-linux
				## NB: This BINDIR value is our LOCAL one, NOT from the TeX Live 2016 team!
				BINDIR=sparc64-debian11
				;;
			x86_64)
				## NB: The nondefault BINDIR values are our LOCAL ones, NOT from the TeX Live 2016 team!
				case "`find /etc/*release* -prune ! -type d | xargs cat`" in
				*openSUSE\ Leap\ 15*)	BINDIR=x86_64-opensuse15 ;;
				*release\ 5*)		BINDIR=x86_64-centos5    ;;
				*release\ 6*)		BINDIR=x86_64-centos6    ;;
				*release\ 7*)		BINDIR=x86_64-centos7    ;;
				*release\ 8*)		BINDIR=x86_64-centos8    ;;
				*Ubuntu\ 20*)		BINDIR=x86_64-ubuntu2004 ;;
				*Ubuntu\ 22*)		BINDIR=x86_64-ubuntu2204 ;;
				*Ubuntu\ 23*)		BINDIR=x86_64-ubuntu2204 ;;
				*Ubuntu\ 24*)		BINDIR=x86_64-ubuntu2404 ;;
				*)			BINDIR=x86_64-linux      ;;
				esac
				;;
			*)
				echo No TeX Live $TEXLIVEYEAR for this system ; exit 1 ;;
			esac
			;;
	MidnightBSD)	case `uname -m` in
			amd64)	BINDIR=amd64-freebsd ;;
			esac
			;;
	NetBSD)		case `uname -m` in
			i386)	BINDIR=i386-netbsd  ;;
			amd64)	BINDIR=amd64-netbsd ;;
			esac
			;;
	OpenBSD)
			case `uname -m` in
			i386)	BINDIR=i386-openbsd ;;
			amd64)	BINDIR=amd64-openbsd ;;
			esac
			;;
	OSF1)		BINDIR=alphaev56-dec-osf4.0f
			PATH=/usr/local/share/lib/tex/texlive7/bin/$BINDIR:$path
			export PATH
			;;
	SunOS)
			case `uname -m` in
			## NB: These BINDIR values are LOCAL ones, NOT from the TeX Live 2016 team!
			i86pc)
					BINDIR=no-such-directory
					test -d $TEXLIVE/bin/i386-solaris   && BINDIR=i386-solaris
					test -d $TEXLIVE/bin/i386-solaris10 && BINDIR=i386-solaris10
					test -d $TEXLIVE/bin/x86_64-solaris && BINDIR=x86_64-solaris
					;;
			sun4u)		BINDIR=sparc-solaris10 ;;
			sun4v)		BINDIR=sparc-solaris10 ;;
			*)		echo No TeX Live $TEXLIVEYEAR for this system ; exit 1 ;;
			esac
			;;
	*)	echo No TeX Live $TEXLIVEYEAR for this system ; exit 1 ;;
esac

if test ! -d "$TEXLIVE/bin/$BINDIR"
then
	echo ========================================================================
	echo ERROR: the TeX Live $TEXLIVEYEAR binary directory for this platform
	echo
	echo $TEXLIVE/bin/$BINDIR
	echo
	echo does not exist.  This could be an error in this script, but could also
	echo arise if some binary directories have been omitted from your TeX Live
	echo $TEXLIVEYEAR installation.
	echo ========================================================================
	exit 1
fi

PATH=$TEXLIVE/bin/$BINDIR:$PATH
export PATH

# Ensure that texmf.cnf in current directory is found first
TEXMFCNF=.:$TEXMFCNF
export TEXMFCNF

# This is the path for ls-R files:
TEXMFDBS=.:$TEXLIVE/texmf-local:$TEXLIVE/texmf-extra:$TEXLIVE/texmf-var//:
export TEXMFDBS

# We have three directory trees where files can be found; two are
# small enough to allow recursive searches:
TEXFONTS=.:$TEXLIVE/texmf-local//:$TEXLIVE/texmf-extra//:$TEXLIVE/texmf-var//:
export TEXFONTS

TEXINPUTS=.:$TEXLIVE/texmf-local//:$TEXLIVE/texmf-extra//:$TEXLIVE/texmf-var//:
export TEXINPUTS

# gsftopk uses this environment variable to find *.pf[ab] files
TEXPSHEADERS=$TEXINPUTS
export TEXPSHEADERS

# documentation paths

INFOPATH=$TEXLIVE/texmf-dist/doc/info:$INFOPATH
export INFOPATH

MANPATH=$TEXLIVE/texmf-dist/doc/man:$MANPATH
export MANPATH
