-
Notifications
You must be signed in to change notification settings - Fork 4
/
install.sh
executable file
·145 lines (127 loc) · 3.82 KB
/
install.sh
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
136
137
138
139
140
141
142
143
144
#!/bin/bash
# USAGE:
# 1. install to user's local directories
#
# $ ./install
#
# 2. install to global directories
#
# $ sudo -sH
# $ ./install --global
#
LOCALFONTREPO="${LOCALFONTREPO:-http://boron:18181/fonts}"
reconfig_lyx() {
echo -n "Refreshing Lyx configuration ... "
lyx -batch -x reconfigure examples/report_lyx/main_en.lyx
echo "Done"
}
if [[ $1 == '--global' ]];
then
TEXMF=$(kpsewhich -var-value TEXMFLOCAL)
LYXDIR=$(cd $(dirname $(which lyx)) && cd .. && pwd)/share/lyx
FONTDIR=/usr/share/fonts
else
reconfig_lyx
TEXMF=$(kpsewhich -var-value TEXMFHOME)
LYXDIR=
for lyxdir in .lyx2.2 .lyx2.1 .lyx
do
if [[ -d "$HOME/$lyxdir" ]]
then
LYXDIR="$HOME/$lyxdir"
fi
done
FONTDIR="$HOME/.local/share/fonts"
fi
##################### Part 1 : Latex class #########################
echo -n "User LaTeX templates are to be installed to $TEXMF ... "
DSTDIR=$TEXMF/tex/latex
[[ -d $DSTDIR ]] || mkdir -p $DSTDIR
cp -r src/tex/latex/cgdrep $DSTDIR
texhash
echo "Done"
##################### Part 2 : Lyx layout #########################
if [[ -d $LYXDIR ]]
then
echo -n "Lyx user dir found in $LYXDIR, installing Lyx layouts ... "
cp src/lyx/layouts/* $LYXDIR/layouts/
reconfig_lyx
fi
if [[ -d $LYXDIR ]]
then
# install template documents
cp examples/report_lyx/main_cn.lyx $LYXDIR/templates/report_cn.lyx
cp examples/report_lyx/main_en.lyx $LYXDIR/templates/report_en.lyx
cp examples/report_lyx/main.bib $LYXDIR/templates/
cp examples/report_lyx/Divergence_theorem.png $LYXDIR/templates/
# change template directory
if [ "$DISPLAY" ]
then
lyx -x "lyxrc-apply \\template_path \"$LYXDIR/templates\"" -x preferences-save -x lyx-quit
fi
fi
echo "Done"
##################### Part 3 : Install fonts #########################
FONTS=(
"NotoSansSC,Noto Sans SC,$LOCALFONTREPO/NotoSansSC.zip,https://noto-website.storage.googleapis.com/pkgs/NotoSansSC.zip"
"NotoSerifSC,Noto Serif SC,$LOCALFONTREPO/NotoSerifSC.zip,https://noto-website.storage.googleapis.com/pkgs/NotoSerifSC.zip"
"XITS,XITS,$LOCALFONTREPO/xits-1.106.zip,https://cloud.github.com/downloads/khaledhosny/xits-math/xits-1.106.zip"
"STIX,STIXGeneral,$LOCALFONTREPO/STIXv1.1.0.zip,https://jaist.dl.sourceforge.net/project/stixfonts/Past%20Releases/STIXv1.1.0.zip"
"mplus,M+ 1m,$LOCALFONTREPO/M-1m.zip,https://www.fontsquirrel.com/fonts/download/M-1m"
"SourceSerifPro,Source Serif Pro,$LOCALFONTREPO/SourceSerifPro.zip,https://github.com/adobe-fonts/source-serif-pro/archive/2.000R.zip"
)
install_one_font() {
fname="$1"
url1="$2"
url2="$3"
dirSave=$(pwd)
FTMP=$(mktemp)
for url in "$url1" "$url2"
do
curl -L -s --connect-timeout 20 -o $FTMP "$url"
if [[ $? -eq 0 ]]
then
fdir="$FONTDIR/$fname"
[[ -d "$fdir" ]] || mkdir -p "$fdir"
cd "$fdir";
unzip -o $FTMP
if [[ $? -eq 0 ]]
then
break
fi
fi
done
rm $FTMP
cd $dirSave
}
install_fonts() {
for ln in "${FONTS[@]}"
do
OLDIFS=$IFS
IFS=','
set -- $ln
fname="$1"
query="$2"
url1="$3"
url2="$4"
IFS=$OLDIFS
# check if the font is already installed
fc-list -q "$query"
if [[ $? -eq 0 ]]
then
echo "... font \"$query\" found"
else
echo "... download and install font \"$query\""
install_one_font "$fname" "$url1" "$url2"
fc-cache
fc-list "$query"
if [[ $? -ne 0 ]]
then
echo "... failed to install font \"$query\""
exit -1
fi
fi
done
}
install_fonts
echo "install completed"