/usr/share/sagemath/ext/texlive/texlive-install is in sagemath-common 7.4-9.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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 133 134 135 | #!/usr/bin/env python
import os
import sys
import glob
from subprocess import check_call, CalledProcessError
try:
SAGE_LOCAL = os.environ['SAGE_LOCAL']
DOT_SAGE = os.environ['DOT_SAGE']
except KeyError:
print('You need to run this script in a Sage shell ("sage -sh")')
sys.exit(1)
TEXLIVE_INSTALL_UNIX_URL = \
'http://mirror.ctan.org/systems/texlive/tlnet/install-tl-unx.tar.gz'
TEXLIVE_PROFILE_TEMPLATE = \
"""
selected_scheme scheme-minimal
TEXDIR {SAGE_LOCAL}/share/texlive
TEXMFLOCAL {SAGE_LOCAL}/share/texlive/texmf-local
TEXMFSYSCONFIG {SAGE_LOCAL}/share/texlive/texmf-config
TEXMFSYSVAR {SAGE_LOCAL}/share/texlive/texmf-var
TEXMFCONFIG {DOT_SAGE}/texlive/texmf-config
TEXMFHOME {DOT_SAGE}/texlive/texmf-home
TEXMFVAR {DOT_SAGE}/texlive/texmf-var
collection-basic 1
in_place 0
option_adjustrepo 1
option_autobackup 1
option_backupdir tlpkg/backups
option_desktop_integration 1
option_doc 1
option_file_assocs 1
option_fmt 1
option_letter 0
option_menu_integration 1
option_path 1
option_post_code 1
option_src 1
option_sys_bin {SAGE_LOCAL}/bin
option_sys_info {SAGE_LOCAL}/share/info
option_sys_man {SAGE_LOCAL}/share/man
option_w32_multi_user 1
option_write18_restricted 1
portable 0
"""
def have_texlive():
try:
check_call(['tlmgr', '--version'])
return True
except (OSError, CalledProcessError):
return False
def download_install_script(tarball):
try:
from urllib import urlretrieve
except ImportError:
from urllib.request import urlretrieve
urlretrieve(TEXLIVE_INSTALL_UNIX_URL, tarball)
def write_profile(filename):
profile = TEXLIVE_PROFILE_TEMPLATE.format(
SAGE_LOCAL=SAGE_LOCAL, DOT_SAGE=DOT_SAGE)
with open(filename, 'w') as f:
f.write(profile)
print('TeXlive unattended install profile: {0}'.format(filename))
def first_dir(glob_pattern):
"""
Return the first directory matching ``glob_pattern``
"""
for dirent in glob.glob(glob_pattern):
if os.path.isdir(dirent):
return dirent
raise RuntimeError('no directory found: {0}'.format(glob_pattern))
def install_texlive():
import tempfile
tmp_dir = tempfile.mkdtemp()
tarball = os.path.join(tmp_dir, 'install-tl-unx.tar.gz')
profile = os.path.join(tmp_dir, 'sage.profile')
download_install_script(tarball)
write_profile(profile)
original_dir = os.getcwd()
os.chdir(tmp_dir)
check_call(['tar', '-x', '-z', '-f', tarball])
install_dir = first_dir('install-tl-*')
os.chdir(install_dir)
check_call([
'./install-tl',
'-profile',
profile
])
os.chdir(original_dir)
def install_packages():
package_list_txt = os.path.join(
os.path.dirname(__file__),
'package-list.txt'
)
with open(package_list_txt) as f:
package_list = f.read()
packages = []
for pkg in package_list.splitlines():
pkg = pkg.strip()
if len(pkg) == 0:
continue
if pkg.startswith('#'):
continue
packages.append(pkg)
print('installing the following TeXlive packages:')
for pkg in packages:
print(' * ' + pkg)
check_call(['tlmgr', 'install'] + packages)
check_call(['tlmgr', 'path', 'add'])
if __name__ == '__main__':
if have_texlive():
print('Using your own texlive install (see "tlmgr --version")')
else:
print('Performing minimal texlive install into {0}'
.format(SAGE_LOCAL))
install_texlive()
install_packages()
|