Skip to content

Commit

Permalink
Refactor install script
Browse files Browse the repository at this point in the history
  • Loading branch information
cdlm committed Apr 29, 2024
1 parent 41e04f2 commit 197cecd
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 35 deletions.
4 changes: 2 additions & 2 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ steps:
image: ubuntu
commands:
- apt update && apt install -y curl perl
- echo $PATH
- export PATH=$HOME/texlive/bin/x86_64-linux:$HOME/texlive/bin/aarch64-linux:$PATH
- ./ci/install-texlive
- xargs tlmgr install < texlive-2023.deps
- latexmk sbabook
- latexmk sbabook.bod
- latexmk sbabook.spiral
Expand All @@ -92,9 +92,9 @@ steps:
image: ubuntu
commands:
- apt update && apt install -y curl perl
- echo $PATH
- export PATH=$HOME/texlive/bin/x86_64-linux:$HOME/texlive/bin/aarch64-linux:$PATH
- ./ci/install-texlive
- xargs tlmgr install < texlive.deps
- latexmk sbabook
- latexmk sbabook.bod
- latexmk sbabook.spiral
Expand Down
58 changes: 25 additions & 33 deletions ci/install-texlive
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,36 @@ trap 's=$?; echo "$0: Error on line "$LINENO": $BASH_COMMAND"; exit $s' ERR
IFS=$'\n\t'
# preamble from https://disconnected.systems/blog/another-bash-strict-mode/

: "${TEXLIVE_TARBALL:=install-tl-unx.tar.gz}"

function die() {
echo "$@" >&2
exit 1
}

function texlive-repo() {
[[ $# -eq 1 ]] || die "${FUNCNAME[0]}: No release specified (YYYY or rolling)"
local release="$1"
local release="$1" url

if [[ "$release" = rolling ]]; then
echo 'http://mirror.ctan.org/systems/texlive/tlnet'
url='http://mirror.ctan.org/systems/texlive/tlnet'
else
[[ "$release" = [0-9][0-9][0-9][0-9] ]] || die "${FUNCNAME[0]}: incorrect release '$release'"
echo "https://ftp.tu-chemnitz.de/pub/tug/historic/systems/texlive/${release}/tlnet-final/"
url="https://ftp.tu-chemnitz.de/pub/tug/historic/systems/texlive/${release}/tlnet-final/"
# the rolling release is missing the shasum, and the tlnet directory
# US mirror: http://ftp.math.utah.edu/pub/tex/historic/systems/texlive/${release}/
fi
}

function deps-file() {
if [[ "$1" = [0-9][0-9][0-9][0-9] ]]; then
echo "texlive-$1.deps"
else
echo texlive.deps
fi
}

function texlive-release() {
tlmgr --version \
| grep 'TeX Live .*version' \
| grep --only-matching '\d\d\d\d'
# resolve possible mirror to fixed URL
curl -LIs -o /dev/null -w '%{url_effective}' "$url"
}

# Ensure meaningful default values for required environment variables.
# Override the full repository URL or set TEXLIVE_RELEASE to pick that year's frozen release.
# Defaults to the current rolling release.
: "${TEXLIVE_RELEASE:=rolling}"
: "${TEXLIVE_REPOSITORY:="$(texlive-repo "$TEXLIVE_RELEASE")"}"
: "${TEXLIVE_TARBALL:=install-tl-unx.tar.gz}"

function get-texlive-installer() {
[[ $# -eq 1 ]] || die "Usage: ${FUNCNAME[0]} texlive-repo-url"
local repo="$1"

# download, checksum, extract
curl --silent --location --remote-name-all "${TEXLIVE_REPOSITORY}/${TEXLIVE_TARBALL}"{,.sha512}
curl --silent --location --remote-name-all "${repo}/${TEXLIVE_TARBALL}"{,.sha512}
sha512sum --check "${TEXLIVE_TARBALL}.sha512"
tar --extract --gzip --file "${TEXLIVE_TARBALL}"
}
Expand Down Expand Up @@ -83,30 +70,35 @@ EOF
}

function install-texlive() {
[[ $# -eq 2 ]] || die "Usage: ${FUNCNAME[0]} (YYYY | rolling) texlive-repository-url"
local release="$1" repo="$2"

echo "Downloading TeXlive..."
echo " release $TEXLIVE_RELEASE"
echo " from $TEXLIVE_REPOSITORY"
echo " release ${release}"
echo " from ${repo}"

get-texlive-installer
get-texlive-installer "$repo"

# find installer path from archive listing, sanity check
local installer
installer="$(tar --list --gzip --file "${TEXLIVE_TARBALL}" | grep '/install-tl$' )"
[[ -x "$installer" ]] || die "can not find TeXlive installer at ${installer}";

texlive-profile >> texlive.profile
"$installer" --repository "$TEXLIVE_REPOSITORY" --profile texlive.profile
}
"$installer" --repository "$repo" --profile texlive.profile
tlmgr option repository "$repo"

function install-deps() {
tlmgr update --self --all
tlmgr install latex-bin latexmk
xargs tlmgr install < "$(deps-file "$TEXLIVE_RELEASE")"
}

# Only call the main function if this script was called as a command. This makes
# it possible to source this script as a library.
if [[ ${BASH_SOURCE[0]} == "$0" ]]; then
install-texlive
install-deps
# Override the full repository URL or set TEXLIVE_RELEASE to pick that year's frozen release.
# Defaults to the current rolling release.
release="${1:-${TEXLIVE_RELEASE:-rolling}}"
repo="${2:-${TEXLIVE_REPOSITORY:-$(texlive-repo "$release")}}"

install-texlive "$release" "$repo"
fi
5 changes: 5 additions & 0 deletions ci/list-deps
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ function info {
printf "\n" 1>&2
}

function texlive-release() {
tlmgr --version \
| sed '/^tlmgr/d ; s/.*version //'
}

function filter-inputs {
sed -e '\#^INPUT '"$PREFIX"'/texmf-dist#!d' \
-e 's#^INPUT '"$PREFIX"'/##' \
Expand Down

0 comments on commit 197cecd

Please sign in to comment.