Last active
July 12, 2019 07:27
-
-
Save micheljung/6e0b0904bf0bd08afdc94a37d6ede5e5 to your computer and use it in GitHub Desktop.
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/sh | |
# Adapted from https://raw.githubusercontent.com/yihui/tinytex/master/tools/install-unx.sh | |
packages_file=$1 | |
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" | |
TLREPO=${CTAN_REPO:-ftp://ftp.rrze.uni-erlangen.de/ctan/systems/texlive/tlnet} | |
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 | |
# No idea if it's a bug or not that the --admin flag is only checked for non-Darwin | |
if [ $(uname) != 'Darwin' ]; then | |
# ask `tlmgr path add` to add binaries to ~/bin instead of the default | |
# /usr/local/bin unless this script is invoked with the argument '--admin' | |
# (e.g., users want to make LaTeX binaries available system-wide) | |
if [ "$1" != '--admin' ]; then | |
mkdir -p $HOME/bin | |
echo "tlpdbopt_sys_bin ${HOME}/bin" >> tinytex.profile | |
fi | |
fi | |
} | |
prepare_installation_file() { | |
echo "Downloading ${TLURL} to ${PWD} ..." | |
if [ $(uname) = 'Darwin' ]; then | |
curl -LO $TLURL || fail "Could not download ${TLURL}" | |
else | |
wget $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 | |
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/*" | |
./tlmgr option repository "$TLREPO" || fail "Could not set repository to ${TLREPO}" | |
if [ "$3" != '' ]; then | |
./tlmgr option repository "$3" || fail "Could not set repository to ${3}" | |
if [ "$4" != '' ]; then | |
echo "WARN tlgpg installation is not supported" | |
# We're in a corporate environment that has no access to this URL | |
# ./tlmgr --repository http://www.preining.info/tlgpg/ install tlgpg | |
fi | |
# test if the repository is accessible; if not, set the default CTAN repo | |
./tlmgr update --list || ./tlmgr option repository ctan | |
fi | |
./tlmgr install latex-bin luatex xetex || fail "Could not install latex-bin, luatex, xetex" | |
popd; popd; | |
rm -rf $TEXDIR || fail "Could not delete ${TEXDIR}" | |
mkdir -p $TEXDIR || fail "Could not create ${TEXDIR}" | |
mv texlive/* $TEXDIR || fail "Could not move texlive files to ${TEXDIR}" | |
rm -r texlive || fail "Could not delete texlive" | |
} | |
install_custom_packages() { | |
$TEXDIR/bin/*/tlmgr install $(cat ${packages_file}) | tr '\n' ' ' || fail "Could not install custom packages" | |
} | |
configure_path() { | |
if [ "$1" = '--admin' ]; then | |
if [ "$2" != '--no-path' ]; then | |
sudo $TEXDIR/bin/*/tlmgr path add || fail "Could not modify path" | |
fi | |
else | |
$TEXDIR/bin/*/tlmgr path add || fail "Could not modify path" | |
fi | |
} | |
install_rpackage_tinytex() { | |
R -e "getOption('repos')" | |
R -e "install.packages('tinytex')" || fail "Could not install R package tinytex" | |
} | |
cd ${TMPDIR:-/tmp} | |
prepare_variables | |
remove_existing_files | |
create_rprofile | |
create_tinytex_profile | |
prepare_installation_file | |
install_texlive | |
install_custom_packages | |
configure_path | |
# For Jenkins, the remote repository is explicitly disabled for some reason. | |
# install_rpackage_tinytex |
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/sh | |
echo Installing TinyTeX... | |
wget -qO- "https://yihui.name/gh/tinytex/tools/install-unx.sh" | sh > /dev/null | |
echo "The path ${HOME} is found in the following locations:" | |
grep -R --exclude="*.log" ${HOME} .TinyTeX/ | |
echo "Installing and testing tinytex R package..." | |
mkdir -p rpackages | |
echo ".libPaths('~/rpackages')" > .Rprofile | |
R --silent -e 'install.packages("tinytex")' | |
R --silent -e 'tinytex::tinytex_root()' | |
echo "Packing TinyTeX..." | |
tar czf tinytex.tar.gz .TinyTeX > /dev/null | |
echo "Removing TinyTeX..." | |
rm -rf ./bin .TinyTeX > /dev/null | |
echo "Unpacking TinyTeX..." | |
tar xzf tinytex.tar.gz > /dev/null | |
echo "Calling tlmgr path add..." | |
./.TinyTeX/bin/x86_64-linux/tlmgr path add > /dev/null | |
echo "Testing tinytex R package..." | |
R --silent -e 'tinytex::tinytex_root()' | |
echo "As you can see, now the tinytex_root is incorrect" |
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 | |
tabu | |
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