-
Notifications
You must be signed in to change notification settings - Fork 52
/
switches
107 lines (90 loc) · 3.44 KB
/
switches
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
function switch-tl-to ()
{
new_target="$1"
# I think that all other TL-related files symlink through here.
# e.g.,
# /opt/texbin: symbolic link to /usr/local/texlive/2022/bin/x86_64-linux
#
# To check for more such symlinks, can use the following command:
# (https://unix.stackexchange.com/q/301717/197212)
# find / -type l -exec readlink -nf {} ';' -exec echo " -> {}" ';' | grep "/usr/local/texlive"
main_tl_dir_parent="/usr/local/texlive"
main_tl_dir="${main_tl_dir_parent}/tl"
if [ ! -L "${main_tl_dir}" ]; then
echo "Error: Not a symbolic link. Needs setup." >&2
return 1
fi
if [ ! -d "${main_tl_dir_parent}/${new_target}" ]; then
echo "Error: the directory ${main_tl_dir_parent}/${new_target} does not exist."
return 1
fi
# This is just an optimization to get an early return so we don't need to
# rerun fc-cache.
#
current_target="$( readlink "${main_tl_dir}")"
if [ "${current_target}" = "${new_target}" ]; then
# nothing to be done
return 0
fi
# sanity check that the target dir is a valid TL dir
expected_tlmgr="${main_tl_dir_parent}/${new_target}/bin/x86_64-linux/tlmgr"
# use '*' to match "x86_64-linux"
if [ ! -e "${expected_tlmgr}" ]; then
echo "Error: In the new target, ${new_target}, tlmgr is not found in the expected location: ${expected_tlmgr}." >&2
return 1
fi
sudo rm "${main_tl_dir}"
sudo ln -s "${new_target}" "${main_tl_dir}"
# TODO: tell users they can remove this file and run "sudo fc-cache -fsv"
# and then this command won't be run anymore.
if [ -e "/etc/fonts/conf.d/09-texlive.conf" ]; then
# This is because we set up the *system* fonts to be able to use TeX Live fonts.
# See this file: /etc/fonts/conf.d/09-texlive.conf
# You can see that the fonts are being used by looking at "sudo lsof".
# For example, search for NotoSans-Regular.ttf.
#
# Although in the file 09-texlive.conf it is a path through the 'tl' link, I
# think when those paths are processed the *absolute* path is what is
# stored/cached, so we have to update those paths when we change the symlink.
echo "Running fc-cache to update system font reference..."
sudo fc-cache -fsv >/dev/null 2>&1
fc_cache_ret=$?
if [ "${fc_cache_ret}" != "0" ]; then
echo "ERROR: fc-cache -fsv exited with error." >&2
fi
echo "Running fc-cache to update system font reference...Done."
fi
\sudo -k
}
_switch_tl_to()
{
local cur
cur=${COMP_WORDS[COMP_CWORD]}
if [ "$COMP_CWORD" == "1" ]; then
# the "--hide=tl" hides the "tl" symlink.
COMPREPLY=( $( compgen -W '`ls --hide=tl /usr/local/texlive/`' -- $cur ) )
fi
}
complete -F _switch_tl_to ${filenames:-} switch-tl-to
function switch-sys-fonts-to-tl ()
{
SYSFONT='/etc/fonts/conf.d/09-texlive.conf'
if sudo cp "$(kpsewhich -var-value TEXMFSYSVAR)/fonts/conf/texlive-fontconfig.conf" "${SYSFONT}" \
> /dev/null 2>&1; then
echo "finished copying."
else
echo "Error: could not copy the font config to the system font directory."
fi
sudo fc-cache -fsv
\sudo -k
}
function switch-sys-fonts-to-ubuntu ()
{
# These LyX ctests are still expected to fail because of missing fonts.
# 434 - export/export/latex/languages/en-th_utf8_pdf4_systemF (Failed)
# 485 - DEFAULTOUTPUT_export/export/latex/languages/supported-languages_polyglossia-XeTeX_pdf4_systemF (Failed)
SYSFONT='/etc/fonts/conf.d/09-texlive.conf'
sudo rm "${SYSFONT}"
sudo fc-cache -fsv
\sudo -k
}