diff --git a/install_texlive/__init__.py b/install_texlive/__init__.py index dcb77fd..3328317 100644 --- a/install_texlive/__init__.py +++ b/install_texlive/__init__.py @@ -29,6 +29,13 @@ def is_current(version): return current_version == version +def get_mirror(): + """Get a CTAN mirror""" + r = requests.get(URL, allow_redirects=False) + r.raise_for_status() + return r.headers["Location"] + + def download(version=None, outdir='.', url=None): os.makedirs(outdir, exist_ok=True) diff --git a/install_texlive/__main__.py b/install_texlive/__main__.py index 1cc5495..40f9b27 100644 --- a/install_texlive/__main__.py +++ b/install_texlive/__main__.py @@ -7,7 +7,7 @@ import re import subprocess as sp -from . import command, download, OLDURL, get_size, is_current +from . import command, download, OLDURL, get_size, is_current, get_mirror from .parser import parser @@ -31,20 +31,23 @@ def main(): os.environ["TEXLIVE_INSTALL_ENV_NOCHECK"] = "1" log.info('Installing texlive to {}'.format(args.prefix or '/usr/local/texlive')) + if args.repository is None: + if args.version is None or is_current(args.version): + args.repository = get_mirror() + else: + args.repository = OLDURL.format(v=args.version) + if args.install_tl: install_script = args.install_tl cmd = install_script else: + log.info("Using repository: %s", args.repository) directory = os.path.join( tempfile.gettempdir(), 'texlive-{}'.format(args.version or 'current') ) download(version=args.version, outdir=directory, url=args.repository) install_script = glob(os.path.join(directory, 'install-tl-*/install-tl'))[-1] - - if args.version is None or is_current(args.version): - cmd = install_script - else: - cmd = install_script + ' --repository=' + OLDURL.format(v=args.version) + cmd = install_script + ' --repository={}'.format(args.repository) log.info(cmd)