-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtexlive.sh
executable file
·132 lines (112 loc) · 4.49 KB
/
texlive.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/bin/bash
# Script to fetch `install-tl` script from different sources, depending on argument
# given.
set -ueo pipefail
usage() {
echo "Usage: $0 get_installer|install latest|version (YYYY)"
}
check_path() {
# The following test assumes the most basic program, `tex`, is present, see also
# https://www.tug.org/texlive/doc/texlive-en/texlive-en.html#x1-380003.5
echo "Checking PATH and installation..."
if tex --version
then
echo "PATH and installation seem OK, exiting with success."
exit 0
else
echoerr "PATH or installation unhealthy, further action required..."
fi
}
if [[ $# != 2 ]]; then
echoerr "Unsuitable number of arguments given."
usage
# From /usr/include/sysexits.h
exit 64
fi
# From: https://stackoverflow.com/a/2990533/11477374
echoerr() { echo "$@" 1>&2; }
# Bind CLI arguments to explicit names:
ACTION=${1}
VERSION=${2}
# Download the `install-tl` script from the `tlnet-final` subdirectory, NOT
# from the parent directory. The latter contains an outdated, non-final `install-tl`
# script, causing this exact problem:
# https://tug.org/pipermail/tex-live/2017-June/040376.html
HISTORIC_URL="ftp://tug.org/historic/systems/texlive/${VERSION}/tlnet-final"
REGULAR_URL="http://mirror.ctan.org/systems/texlive/tlnet"
case ${ACTION} in
"get_installer")
if [[ ${VERSION} == "latest" ]]
then
# Get from default, current repository
GET_URL="${REGULAR_URL}/${TL_INSTALL_ARCHIVE}"
else
# Get from historic repository
GET_URL="${HISTORIC_URL}/${TL_INSTALL_ARCHIVE}"
fi
wget "$GET_URL"
;;
"install")
if [[ ${VERSION} == "latest" ]]
then
# Install using default, current repository.
# Install process/script documentation is here:
# https://www.tug.org/texlive/doc/texlive-en/texlive-en.html
perl install-tl \
--profile="$TL_PROFILE"
else
# Install using historic repository (`install-tl` script and repository
# versions need to match)
perl install-tl \
--profile="$TL_PROFILE" \
--repository="$HISTORIC_URL"
fi
# If automatic `install-tl` process has already adjusted PATH, we are happy.
check_path
echo "install-tl procedure did not adjust PATH automatically, trying other options..."
# `\d` class doesn't exist for basic `grep`, use `0-9`, which is much more
# portable. Finding the initial dir is very fast, but looking through everything
# else afterwards might take a while. Therefore, print and quit after first result.
# Path example: `/usr/local/texlive/2018/bin/x86_64-linux`
TEXLIVE_BIN_DIR=$(find / -type d -regextype grep -regex '.*/texlive/[0-9]\{4\}/bin/.*' -print -quit)
# -z test: string zero length?
if [ -z "$TEXLIVE_BIN_DIR" ]
then
echoerr "Expected TeXLive installation dir not found and TeXLive installation did not modify PATH automatically."
echoerr "Exiting."
exit 1
fi
echo "Found TeXLive binaries at $TEXLIVE_BIN_DIR"
echo "Trying native TeXLive symlinking using tlmgr..."
# To my amazement, `tlmgr path add` can fail but still link successfully. So
# check if PATH is OK despite that command failing.
"$TEXLIVE_BIN_DIR"/tlmgr path add || \
echoerr "Command borked, checking if it worked regardless..."
check_path
echoerr "Symlinking using tlmgr did not succeed, trying manual linking..."
SYMLINK_DESTINATION="/usr/local/bin"
# "String contains", see: https://stackoverflow.com/a/229606/11477374
if [[ ! ${PATH} == *${SYMLINK_DESTINATION}* ]]
then
# Should never get here, but make sure.
echoerr "Symlink destination ${SYMLINK_DESTINATION} not in PATH (${PATH}), exiting."
exit 1
fi
echo "Symlinking TeXLive binaries in ${TEXLIVE_BIN_DIR}"
echo "to a directory (${SYMLINK_DESTINATION}) found on PATH (${PATH})"
# Notice the slash and wildcard.
ln \
--symbolic \
--verbose \
--target-directory="$SYMLINK_DESTINATION" \
"$TEXLIVE_BIN_DIR"/*
check_path
echoerr "All attempts failed, exiting."
exit 1
;;
*)
echoerr "Input not understood."
usage
# From /usr/include/sysexits.h
exit 64
esac