Last active
July 23, 2019 11:22
-
-
Save micheljung/a8ea7ea0ad3f08bccefb40f6aba179de to your computer and use it in GitHub Desktop.
Script to create a truly portable TinyTeX installation without accessing any URLs other than a CTAN repository. Useful to build TinyTeX in corporate environments with restricted internet access. Since I'm not good at Shell scripting, the error handling might not work as expected.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -u | |
set -e | |
set -o pipefail | |
# Adapted from https://github.com/yihui/tinytex/blob/master/tools/install-base.sh | |
# Creates a truly portable TinyTeX without accessing any URLs other than the CTAN repository | |
# Make sure that /usr/lib64/microsoft-r/3.3/lib64/R/etc/Renviron contains http_proxy, | |
# https_proxy and ftp_proxy (or adjust the script accordingly) | |
TLREPO=ftp://ftp.rrze.uni-erlangen.de/ctan/systems/texlive/tlnet | |
TINYTEX_DIR="${PWD}/build/tinytex" | |
PACKAGES_FILE=${1:-tinytex-packages.txt} | |
fail() { | |
echo $1 | |
exit 1; | |
} | |
extract_variable_from_renviron() { | |
renviron="/usr/lib64/microsoft-r/3.3/lib64/R/etc/Renviron" | |
grep -oP "${1} *= *\K.*" "${renviron}" | |
} | |
prepare_variables() { | |
export http_proxy=$(extract_variable_from_renviron http_proxy) | |
[ -n "${http_proxy}" ] || fail "Could not extract http_proxy from Renviron" | |
export https_proxy=$(extract_variable_from_renviron https_proxy) | |
[ -n "${https_proxy}" ] || fail "Could not extract http_proxy from Renviron" | |
export ftp_proxy=$(extract_variable_from_renviron ftp_proxy) | |
[ -n "${ftp_proxy}" ] || fail "Could not extract http_proxy from Renviron" | |
TLURL="${TLREPO}/install-tl-unx.tar.gz" | |
if [ $(uname) = 'Darwin' ]; then | |
TEXDIR=${TINYTEX_DIR:-~/Library/TinyTeX} | |
else | |
TEXDIR=${TINYTEX_DIR:-~/.TinyTeX} | |
fi | |
} | |
remove_existing_files() { | |
rm -f install-tl-unx.tar.gz tinytex.profile | |
} | |
create_rprofile() { | |
if [ ! $(grep libPaths ~/.Rprofile) ]; then | |
echo ".libPaths('~/rstudiolibs')" >> ~/.Rprofile | |
mkdir -p ~/rstudiolibs | |
fi | |
} | |
create_tinytex_profile() { | |
echo 'selected_scheme scheme-infraonly | |
TEXDIR ./ | |
TEXMFSYSCONFIG ./texmf-config | |
TEXMFCONFIG $HOME/.TinyTeX/texmf-config | |
TEXMFLOCAL ./texmf-local | |
TEXMFHOME $HOME/.TinyTeX/texmf-home | |
TEXMFSYSVAR ./texmf-var | |
TEXMFVAR $HOME/.TinyTeX/texmf-var | |
option_doc 0 | |
option_src 0 | |
option_autobackup 0 | |
portable 1 | |
' > tinytex.profile | |
} | |
prepare_installation_file() { | |
echo "Downloading ${TLURL} to ${PWD} ..." | |
if [ $(uname) = 'Darwin' ]; then | |
curl -LO $TLURL || fail "Could not download ${TLURL}" | |
else | |
wget -nv $TLURL || fail "Could not download ${TLURL}" | |
fi | |
tar -xzf install-tl-unx.tar.gz || fail "Could not unpack install-tl-unx.tar.gz" | |
rm install-tl-unx.tar.gz || fail "Could not delete install-tl-unx.tar.gz" | |
} | |
install_texlive() { | |
mkdir texlive | |
pushd texlive | |
TEXLIVE_INSTALL_ENV_NOCHECK=true TEXLIVE_INSTALL_NO_WELCOME=true ../install-tl-*/install-tl -no-gui -profile=../tinytex.profile -repository $TLREPO | |
echo "Cleaning up setup files" | |
rm -r ../install-tl-* ../tinytex.profile install-tl.log || fail "Could not clean up setup files" | |
pushd bin/* || fail "Could not change to directory bin/*" | |
echo "Setting repository to ${TLREPO}" | |
./tlmgr option repository "$TLREPO" || fail "Could not set repository to ${TLREPO}" | |
./tlmgr update --list || fail "Repository is not accessible" | |
echo "Installing latex-bin, luatex, xetex" | |
./tlmgr install latex-bin luatex xetex || fail "Could not install latex-bin, luatex, xetex" | |
popd; popd; | |
[[ -n "${TEXDIR}" ]] || fail "TEXDIR must not be empty" | |
[[ "${TEXDIR}" != "/" ]] || fail "TEXDIR must not be /" | |
echo "Removing ${TEXDIR}" | |
rm -rf "${TEXDIR}" || fail "Could not delete ${TEXDIR}" | |
echo "Creating ${TEXDIR}" | |
mkdir -p "${TEXDIR}" || fail "Could not create ${TEXDIR}" | |
echo "Moving files from texlive/* to ${TEXDIR}" | |
mv texlive/* "${TEXDIR}" || fail "Could not move texlive files to ${TEXDIR}" | |
echo "Removing directory 'texlive'" | |
rm -r texlive || fail "Could not delete texlive" | |
} | |
install_custom_packages() { | |
echo "Installing custom packages from ${PACKAGES_FILE}" | |
"${TEXDIR}"/bin/*/tlmgr install $(cat ${PACKAGES_FILE}) | tr '\n' ' ' || fail "Could not install custom packages" | |
} | |
prepare_variables | |
remove_existing_files | |
create_rprofile | |
create_tinytex_profile | |
prepare_installation_file | |
install_texlive | |
install_custom_packages | |
echo "Finished" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
buildscript { | |
repositories { | |
maven { url "https://nexus.example.com/content/groups/public" } | |
} | |
dependencies { | |
classpath "com.netflix.nebula:gradle-ospackage-plugin:6.2.1" | |
} | |
} | |
apply plugin: 'base' | |
apply plugin: 'maven-publish' | |
apply plugin: "nebula.rpm" | |
group = 'com.example' | |
// Version has to be passed at build time from command line | |
version = "${version}" | |
task rpm(type: Rpm) { | |
group 'build' | |
release '1' | |
arch X86_64 | |
os LINUX | |
postInstall file('src/main/sh/postInstall.sh') | |
into '/opt/tinytex' | |
from('build/tinytex') { | |
into '.' | |
} | |
user 'tinytex' | |
permissionGroup 'tinytex' | |
} | |
assemble.dependsOn rpm | |
artifacts { | |
archives rpm | |
} | |
publishing { | |
repositories { | |
maven { | |
url "https://nexus.example.com/content/repositories/${project.version.endsWith('-SNAPSHOT') ? 'snapshots' : 'releases'}" | |
credentials(PasswordCredentials) { | |
username System.env.NEXUS_USER | |
password System.env.NEXUS_PASS | |
} | |
} | |
} | |
publications { | |
tinytex(MavenPublication) { | |
artifactId = 'custom-tinytex' | |
artifact rpm | |
} | |
} | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
amscls | |
amsfonts | |
amsmath | |
bibtex | |
booktabs | |
caption | |
dvipdfmx | |
dvips | |
ec | |
etoolbox | |
fancyvrb | |
float | |
fontspec | |
framed | |
geometry | |
graphics | |
graphics-def | |
gsftopk | |
helvetic | |
hyperref | |
ifluatex | |
ifxetex | |
inconsolata | |
latexmk | |
lm | |
luaotfload | |
makeindex | |
mathspec | |
metafont | |
mfware | |
natbib | |
oberdiek | |
tex | |
times | |
titling | |
tools | |
upquote | |
url | |
xkeyval | |
zapfding |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment