-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathinstall.sh
executable file
·232 lines (212 loc) · 6.69 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#!/bin/bash
#
# install the requirement packages
# environment check
## python
[ ! $(command -v python) ] && {
echo "No python interpreter in your PATH"
exit 1
}
## python>3
[ "$(python -V 2>&1 | awk '{print $2}' | cut -d '.' -f 1)" -ne 3 ] && {
echo "Require python3+, instead $(python -V 2>&1)"
exit 1
}
set -e
<<"PARSER"
("package", type=str, default='cat', nargs='*',
choices=['all', 'cat', 'ctcdecode', 'kenlm', 'ctc-crf', 'fst-decoder',
'g2p-tool'],
help="Select modules to be installed/uninstalled. Default: cat.")
('-r', "--remove", action='store_true', default=False,
help="Remove modules instead of installing.")
('-f', "--force", action='store_true', default=False,
help="Force to install modules whatever they exist or not.")
PARSER
eval $(python cat/utils/parseopt.py $0 $*)
function check_py_package() {
name=$1
[ -z $name ] && {
echo "error calling check_py_package()"
return 1
}
cd /tmp
python -c "import $name" >/dev/null 2>&1
echo "$?"
}
function exc_install() {
name=$1
[ -z $name ] && {
echo "error calling exc_install()"
return 1
}
case $name in
ctcdecode | cat | all)
# install ctcdecode is annoying...
[[ $force == "False" && $(check_py_package ctcdecode) -eq 0 ]] || {
if [ ! -d src/ctcdecode ]; then
git clone --recursive https://github.com/maxwellzh/ctcdecode.git src/ctcdecode
else
cd src/ctcdecode
git pull --recurse-submodules
cd - >/dev/null
fi
# ctcdecode doesn't support -e, but we want to install locally
# ... so we cannot put it in requirements.txt
python -m pip install src/ctcdecode || return 1
}
;;&
kenlm | cat | all)
# install kenlm
# kenlm is a denpendency of cat, so we first check the python package installation
[[ $force == "False" && $(check_py_package kenlm) -eq 0 && -x src/bin/lmplz && -x src/bin/build_binary ]] || {
python -m pip install -e git+https://github.com/kpu/kenlm.git#egg=kenlm
cd src/kenlm
mkdir -p build && cd build
(cmake .. && make -j $(nproc)) || {
echo "If you meet building error and have no idea why it is raised, "
echo "... please first confirm all requirements are installed. See"
echo "... https://github.com/kpu/kenlm/blob/master/BUILDING"
return 1
}
# link executable binary files
cd ../../
mkdir -p bin && cd bin
ln -snf ../kenlm/build/bin/* ./ && cd ../../
}
;;&
ctc-crf | cat | all)
# install ctc-crf loss function
[[ $force == "False" && $(check_py_package ctc_crf) -eq 0 ]] || {
if [ $(command -v gcc-7) ]; then
export ver=7
elif [ $(command -v gcc-6) ]; then
export ver=6
else
echo "gcc-6/gcc-7 command not found. You may need to install one of them."
return 1
fi
cd src/ctc_crf
CC=gcc-${ver} CXX=g++-${ver} make || return 1
# test the installation
echo "Test CTC-CRF installation:"
cd test && python main.py || return 1
cd ../../../
}
;;&
cat | all)
# change dir to a different one to test whether cat module has been installed.
[[ $force == "False" && $(check_py_package cat) -eq 0 ]] || {
python -m pip install -r requirements.txt || return 1
python -m pip install -e . || return 1
# check installation
$(cd egs && python -c "import cat") >/dev/null || return 1
}
;;&
fst-decoder | all)
# install the fst decoder
# test kaldi installation
[[ $force == "False" && -x src/bin/latgen-faster ]] || {
[ -z $KALDI_ROOT ] && {
echo "\$KALDI_ROOT variable is not set, try"
echo " KALDI_ROOT=<path to kaldi> $0 ..."
return 1
}
export KALDI_ROOT=$KALDI_ROOT
cd src/fst-decoder && make || return 1
[ ! -f $(command -v ./latgen-faster) ] && {
echo "It seems the installation is success, but executable"
echo "... binary 'latgen-faster' not found at src/fst-decoder."
return 1
}
cd - >/dev/null
[ ! -d src/bin ] && mkdir src/bin
cd src/bin/ && ln -snf ../fst-decoder/latgen-faster ./
cd - >/dev/null
}
;;&
g2p-tool | all)
# install the Phonetisaurus G2P tool
export LD_LIBRARY_PATH=$CONDA_PREFIX/lib:\$LD_LIBRARY_PATH
[[ $force == "False" && $(check_py_package phonetisaurus) -eq 0 ]] || {
cd src/g2p-tool
./build.sh
cd - >/dev/null
}
;;
*) ;;
esac
echo "installed module:$name"
return 0
}
function exc_rm() {
name=$1
[ -z $name ] && return 0
case $name in
cat | all)
# FIXME: maybe we should clean building dependencies?
python -m pip uninstall -y cat
python setup.py clean --all
;;&
ctcdecode | all)
python -m pip uninstall -y ctcdecode
rm -rf src/ctcdecode
;;&
kenlm | all)
python -m pip uninstall -y kenlm
[ -d src ] && {
cd src/
[ -d kenlm/build/bin ] && {
for exc in $(ls kenlm/build/bin); do
rm -if bin/$exc
done
}
[ -d kenlm ] && rm -rf kenlm/
cd - >/dev/null
}
;;&
ctc-crf | all)
python -m pip uninstall -y ctc_crf
cd src/ctc_crf
make clean
cd - >/dev/null
;;&
fst-decoder | all)
rm -if src/bin/latgen-faster
rm -rf src/fst-decoder/latgen-faster
;;&
g2p-tool | all)
python -m pip uninstall -y phonetisaurus
rm -if ls src/bin/phonetisaurus-*
;;
*) ;;
esac
echo "removed module:$name"
return 0
}
# squeeze the packages to 'all' once there is 'all'
for p in $package; do
if [ $p == "all" ]; then
package="all"
break
fi
done
if [ $remove == "False" ]; then
# install packages
for p in $package; do
exc_install $p || {
echo "failed to install $p." 1>&2
exit 1
}
done
elif [ $remove == "True" ]; then
# remove packages
for p in $package; do
exc_rm $p || {
echo "failed to remove $p." 1>&2
exit 1
}
done
fi
echo "$0 done"
exit 0