#!/bin/bash
# postflight script for the MacTeX installer
# Adjust PATH and MANPATH
# Finally, construct the TeX Distribution data structure. Start with the key link
if [[ ! -d /Library/TeX ]]; then
mkdir /Library/TeX
fi
if [[ ( ! -L /Library/TeX/texbin ) && ( -d /Library/TeX/texbin ) && ( -e /Library/TeX/texbin/tex ) ]]; then
rm -R /Library/TeX/texbin
fi
if [[ -L /Library/TeX/texbin ]]; then
rm /Library/TeX/texbin
fi
# In Mavericks and above, /Library/TeX/texbin points to /Library/TeX/Distributions/Programs/texbin
# but that then points to the old location. Jerome understands why!
ln -fhs Distributions/Programs/texbin /Library/TeX/texbin
# TEXDIST SCRIPT
# Isolate out the instructions making the texdist script. This is separate from the "texdist structure"
# which appears all over the place. it is script to manipulate this structure from the command line.
# It needs updating. For now we leave it in place if it already exists, but do not install it.
# END OF TEXDIST SCRIPT
if [[ -L /Library/TeX/Documentation ]]; then
rm /Library/TeX/Documentation
fi
if [[ ! -e /Library/TeX/Documentation ]]; then
ln -s Distributions/.DefaultTeX/Contents/Doc /Library/TeX/Documentation
fi
if [[ -L /Library/TeX/Root ]]; then
rm /Library/TeX/Root
fi
if [[ ! -e /Library/TeX/Root ]]; then
ln -s Distributions/.DefaultTeX/Contents/Root /Library/TeX/Root
fi
if [[ -L /Library/TeX/Local ]]; then
rm /Library/TeX/Local
fi
if [[ ! -e /Library/TeX/Local ]]; then
ln -s Distributions/.DefaultTeX/Contents/TexmfLocal /Library/TeX/Local
fi
if [[ ! -d /Library/TeX/Distributions ]]; then
mkdir /Library/TeX/Distributions
fi
# NEW STUFF
if [[ ! -d /Library/TeX/Distributions/Programs ]]; then
mkdir /Library/TeX/Distributions/Programs
ln -s ../.DefaultTeX/Contents/Programs/texbin /Library/TeX/Distributions/Programs/texbin
fi
# END OF NEW STUFF
if [[ ! -e /Library/TeX/Distributions/TeXDist-description.rtf ]]; then
cp ./TeXDist-description.rtf /Library/TeX/Distributions/TeXDist-description.rtf
chmod 644 /Library/TeX/Distributions/TeXDist-description.rtf
fi
if [[ ! -d /Library/TeX/Distributions/.DefaultTeX ]]; then
mkdir /Library/TeX/Distributions/.DefaultTeX
fi
# /Library/TeX/Distributions/.DefaultTeX/Contents will become a link to the Contents
# folder of the active distribution. Make TeXLive-2021 that active distribution
# These are symbolic links, so the linked material will be created later on.
if [[ -L /Library/TeX/Distributions/.DefaultTeX/Contents ]]; then
rm /Library/TeX/Distributions/.DefaultTeX/Contents
fi
if [[ ! -e /Library/TeX/Distributions/.DefaultTeX/Contents ]]; then
ln -s ../TeXLive-2021.texdist/Contents /Library/TeX/Distributions/.DefaultTeX/Contents
fi
# Now we come to the key data defining the various TeX distributions which can occur.
# It is legal to install this data even if the actual distribution isn't available, because the
# Preference Pane checks to make sure the links point somewhere before using them.
# MacTeX-2021 only installs data for 2021, and not for other years.
# The TeX Distribution data is much more elaborate than necessary because Jerome
# Laurens and Gerben Wierda thought of other uses of the data, which front ends haven't
# yet implemented.
# For mysterious reasons, each actual distribution occurs twice. Take for example TeXLive-2021.
# In /Library/TeX/Distributions, there is a folder named TeXLive-2021.texdist. But there is also
# a hidden folder of distributions, /Library/TeX/Distributions/.FactoryDefaults, and this folder
# contains a folder TeXLive-2021 as well. Notice that the first name has an extension and the
# second does not.
# The TeXLive-2021 folder in .FactoryDefaults contains a subfolder named Contents. The
# TeXLive-2021.texdist folder in Distributions contains an item named Contents, but this
# item is a symbolic link to the Contents folder in TeXLive-2021. Aside from this element,
# TeXLive-2021.texdist is empty. All of the interesting links are in
# .FactoryDefaults/TeXLive-2021/Contents
# This strange design was required so icons could be assigned to the various distributions,
# but that was never carried out. The extra complications now have no purpose, but they take
# almost no disk space and the only people noticing them are people reading these comments!
# All the items of interest are in /Library/TeX/Distributions/.FactoryDefaults/Contents
# Many of these items are there for future use and aren't currently used by software. The key
# subfolder of Contents for us is named Programs. It contains four links titled i386, ppc, powerpc,
# and x86_64. Each is a link to the actual binary directory of the distribution of indicated type.
# Some of these links might be missing for other distributions, but for TeXLive-2021, the
# links i386, ppc, and powerpc all point to universal-darwin, and x86_64 points to x86_64-darwin.
# Incidentally, ppc and powerpc will usually point to the same place; this link is duplicated for
# historical reasons.
# Programs also contains a symbolic link named texdist which points to one of the links
# just described. The Preference Pane may reset this link. For instance, the drop down panel
# allowing the user to choose 32 or 64 bit binaries resets the texdist link.
# There is one other key item. Although Leopard can run 64 bit programs, the TeX Live 64 bit
# programs are compiled on Snow Leopard and require that operating system. Jerome Laurens has
# provided a mechanism for handling that situation. On Mac OS X, the Contents directory can contain
# an Info.plist file. Jerome defined such a plist file which lives the minimal operating version which
# can run particular binaries. This would allow us in the future to compile the 64 bit binaries on Lion
# or another advanced system.
# We first create .FactoryDefaults where the interesting data lives. We usually write data there
# only if it doesn't already exist. But we will rewrite the data for our own distribution.
if [[ ! -d /Library/TeX/Distributions/.FactoryDefaults ]]; then
mkdir /Library/TeX/Distributions/.FactoryDefaults
fi
if [[ -d /Library/TeX/Distributions/.FactoryDefaults/TeXLive-2021 ]]; then
rm -R /Library/TeX/Distributions/.FactoryDefaults/TeXLive-2021
fi
# Next we create links to the main data in .Factory Defaults
if [[ ! -d /Library/TeX/Distributions/TeXLive-2021.texdist ]]; then
mkdir -p /Library/TeX/Distributions/TeXLive-2021.texdist
ln -s ../.FactoryDefaults/TeXLive-2021/Contents /Library/TeX/Distributions/TeXLive-2021.texdist/Contents
fi
# At last! Here's the data!
if [[ ! -d /Library/TeX/Distributions/.FactoryDefaults/TeXLive-2021 ]]; then
mkdir -p /Library/TeX/Distributions/.FactoryDefaults/TeXLive-2021/Contents/AllTexmf
mkdir -p /Library/TeX/Distributions/.FactoryDefaults/TeXLive-2021/Contents/Doc
mkdir -p /Library/TeX/Distributions/.FactoryDefaults/TeXLive-2021/Contents/Programs
mkdir -p /Library/TeX/Distributions/.FactoryDefaults/TeXLive-2021/Contents/Resources
ln -s ../../../../../../usr/local/texlive/2021/texmf-dist/doc/info /Library/TeX/Distributions/.FactoryDefaults/TeXLive-2021/Contents/Info
ln -s ../../../../../../usr/local/texlive/2021/texmf-dist/doc/man /Library/TeX/Distributions/.FactoryDefaults/TeXLive-2021/Contents/Man
ln -s ../../../../../../usr/local/texlive/2021 /Library/TeX/Distributions/.FactoryDefaults/TeXLive-2021/Contents/Root
ln -s ../../../../../../usr/local/texlive/texmf-local /Library/TeX/Distributions/.FactoryDefaults/TeXLive-2021/Contents/TexmfLocal
ln -s ../../../../../../usr/local/texlive/2021/texmf-var /Library/TeX/Distributions/.FactoryDefaults/TeXLive-2021/Contents/TexmfSysVar
ln -s ../../../../../../../usr/local/texlive/2021/bin/i386-darwin /Library/TeX/Distributions/.FactoryDefaults/TeXLive-2021/Contents/Programs/i386
ln -s ../../../../../../../usr/local/texlive/2021/bin/powerpc-darwin /Library/TeX/Distributions/.FactoryDefaults/TeXLive-2021/Contents/Programs/powerpc
ln -s ../../../../../../../usr/local/texlive/2021/bin/powerpc-darwin /Library/TeX/Distributions/.FactoryDefaults/TeXLive-2021/Contents/Programs/ppc
ln -s ../../../../../../../usr/local/texlive/2021/bin/x86_64-darwinlegacy /Library/TeX/Distributions/.FactoryDefaults/TeXLive-2021/Contents/Programs/x86_64-legacy
ln -s ../../../../../../../usr/local/texlive/2021/bin/universal-darwin /Library/TeX/Distributions/.FactoryDefaults/TeXLive-2021/Contents/Programs/x86_64
ln -s ../../../../../../../usr/local/texlive/2021/bin/universal-darwin /Library/TeX/Distributions/.FactoryDefaults/TeXLive-2021/Contents/Programs/arm64
ln -s ../../../../../../../usr/local/texlive/2021/bin/universal-darwin /Library/TeX/Distributions/.FactoryDefaults/TeXLive-2021/Contents/Programs/universal
ln -s ../../../../../../../usr/local/texlive/2021/texmf-dist/doc /Library/TeX/Distributions/.FactoryDefaults/TeXLive-2021/Contents/Doc/texmf-dist-doc
ln -s ../../../../../../../usr/local/texlive/2021/texmf-dist/doc /Library/TeX/Distributions/.FactoryDefaults/TeXLive-2021/Contents/Doc/texmf-doc
ln -s ../../../../../../../usr/local/texlive/2021/texmf-dist/doc /Library/TeX/Distributions/.FactoryDefaults/TeXLive-2021/Contents/Doc/texmf-doc-doc
ln -s ../../../../../../../usr/local/texlive/2021/texmf-dist/doc /Library/TeX/Distributions/.FactoryDefaults/TeXLive-2021/Contents/Doc/texmf-var-doc
ln -s ../../../../../../../usr/local/texlive/2021/texmf-dist /Library/TeX/Distributions/.FactoryDefaults/TeXLive-2021/Contents/AllTexmf/texmf
ln -s ../../../../../../../usr/local/texlive/2021/texmf-dist /Library/TeX/Distributions/.FactoryDefaults/TeXLive-2021/Contents/AllTexmf/texmf-dist
ln -s ../../../../../../../usr/local/texlive/2021/texmf-dist/doc /Library/TeX/Distributions/.FactoryDefaults/TeXLive-2021/Contents/AllTexmf/texmf-doc
ln -s ../../../../../../../usr/local/texlive/2021/texmf-var /Library/TeX/Distributions/.FactoryDefaults/TeXLive-2021/Contents/AllTexmf/texmf-var
ln -s ../../../../../../../usr/local/texlive/texmf-local /Library/TeX/Distributions/.FactoryDefaults/TeXLive-2021/Contents/AllTexmf/texmf-local
PROCESSOR=`/usr/bin/uname -p`
SYSVERSION=`/usr/bin/uname -r | /usr/bin/cut -f 1 -d .`
if [[ "$PROCESSOR" == "powerpc" ]]; then
echo "### setting program link powerpc"
ln -s powerpc /Library/TeX/Distributions/.FactoryDefaults/TeXLive-2021/Contents/Programs/texbin
fi
if [[ "$PROCESSOR" == "i386" ]]; then
echo "### setting program link i386"
ln -s i386 /Library/TeX/Distributions/.FactoryDefaults/TeXLive-2021/Contents/Programs/texbin
fi
# Snow Leopard test
if [[ `/usr/bin/uname -r | /usr/bin/cut -f 1 -d .` -lt 10 ]]; then
exit 0
fi
# 64 bit test
if [[ `/usr/sbin/sysctl hw.cpu64bit_capable | /usr/bin/cut -b 22` -lt 1 ]]; then
exit 0
fi
if [[ `/usr/bin/uname -r | /usr/bin/cut -f 1 -d .` -lt 18 ]]; then
ln -fs x86_64-legacy /Library/TeX/Distributions/.FactoryDefaults/TeXLive-2021/Contents/Programs/texbin
exit 0
fi
ln -fs universal /Library/TeX/Distributions/.FactoryDefaults/TeXLive-2021/Contents/Programs/texbin
fi
exit 0