-
Notifications
You must be signed in to change notification settings - Fork 6
/
install.sh
executable file
·202 lines (171 loc) · 5.04 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
#!/bin/bash
# Copyright 2016-2022 Institut national de recherche pour l'agriculture, l'alimentation et l'environnement (INRAE)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
function usage() {
if [ -n "$1" ]
then
echo "$1" >&2
fi
echo "Usage: $0 [-p DEFAULT_PARAM_VALUES_FILE] [-o DEFAULT_OPTIONS_FILE] [-i] INSTALL_DIRECTORY" >&2
exit 1
}
while getopts ":p:o:" opt
do
case "$opt" in
p)
if [ -n "$DEFAULT_PARAM_VALUES" ]
then
usage "Duplicate option -$opt"
fi
DEFAULT_PARAM_VALUES="$OPTARG"
;;
o)
if [ -n "$DEFAULT_OPTIONS" ]
then
usage "Duplicate option -$opt"
fi
DEFAULT_OPTIONS="$OPTARG"
;;
\?)
usage "Invalid option: -$OPTARG"
;;
:)
usage "Option -$OPTARG requires an argument"
;;
esac
done
shift $((OPTIND-1))
if [ -z "$DEFAULT_PARAM_VALUES" ]
then
if [ -f "share/default-param-values.xml.$HOSTNAME" ]
then
DEFAULT_PARAM_VALUES="share/default-param-values.xml.$HOSTNAME"
fi
fi
if [ -z "$DEFAULT_PARAM_VALUES" ]
then
if [ -f "share/default-param-values.xml" ]
then
DEFAULT_PARAM_VALUES="share/default-param-values.xml"
fi
fi
if [ -z "$DEFAULT_OPTIONS" ]
then
if [ -f "share/default-options.txt.$HOSTNAME" ]
then
DEFAULT_OPTIONS="share/default-options.txt.$HOSTNAME"
fi
fi
if [ -z "$DEFAULT_OPTIONS" ]
then
if [ -f "share/default-options.txt" ]
then
DEFAULT_OPTIONS="share/default-options.txt"
fi
fi
if [ "$#" -ne 1 ]; then
usage "Missing install directory"
fi
if ! [ -d "$1" ]; then
usage "$1 does not exist"
fi
VERSION=$(sed -n -e '/^version/s,version = ,,p' ./alvisnlp-core/target/classes/fr/inra/maiage/bibliome/alvisnlp/core/app/AlvisNLPVersion.properties)
LIB_FILES="alvisnlp-core/target/lib/*.jar alvisnlp-core/target/*.jar alvisnlp-bibliome/target/lib/*.jar alvisnlp-bibliome/target/*.jar"
SOURCES_DIR="$(readlink -m $(dirname $0))"
echo "Sources directory: $SOURCES_DIR"
INSTALL_DIR="$(readlink -m $1)"
echo "Install directory: $INSTALL_DIR"
if [ "$SOURCES_DIR" = "$INSTALL_DIR" ]
then
echo "Cannot install into the sources dir"
exit 1
fi
if [ -n "$DEFAULT_PARAM_VALUES" ]
then
echo "Default parameter values file: $DEFAULT_PARAM_VALUES"
else
echo "Found no default parameter values file (it is highly recommended)"
fi
if [ -n "$DEFAULT_OPTIONS" ]
then
echo "Default options file: $DEFAULT_OPTIONS"
else
echo "Found no default options file (no worries)"
fi
BIN_DIR="$INSTALL_DIR/bin"
DOC_DIR="$INSTALL_DIR/doc/alvisnlp-$VERSION"
LIB_DIR="$INSTALL_DIR/lib/alvisnlp-$VERSION"
SHARE_DIR="$INSTALL_DIR/share/alvisnlp-$VERSION"
mkdir -p "$INSTALL_DIR"
mkdir -p "$BIN_DIR"
mkdir -p "$DOC_DIR"
rm -f -r "$LIB_DIR"
mkdir -p "$LIB_DIR"
mkdir -p "$SHARE_DIR"
cp -f -u -r $LIB_FILES "$LIB_DIR"
function insert_param_value() {
module="$1"
param="$2"
value="$3"
if [ -n "$DEFAULT_PARAM_VALUES" ]
then
echo Inserting default param value: "$module"/"$param"="$value"
xsltproc --stringparam module "$module" --stringparam param "$param" --stringparam value "$value" share/insert-default-param.xslt "$DEFAULT_PARAM_VALUES" >.default-param-values.xml.tmp
mv .default-param-values.xml.tmp .default-param-values.xml
DEFAULT_PARAM_VALUES=.default-param-values.xml
fi
}
insert_param_value fr.inra.maiage.bibliome.alvisnlp.bibliomefactory.modules.python.PythonScript alvisnlpPythonDirectory "$SHARE_DIR"
insert_param_value fr.inra.maiage.bibliome.alvisnlp.bibliomefactory.modules.python.Stanza alvisnlpPythonDirectory "$SHARE_DIR"
cp -f -u share/alvisnlp.py "$SHARE_DIR"
if [ -n "$DEFAULT_PARAM_VALUES" ]
then
cp -f -u "$DEFAULT_PARAM_VALUES" "$SHARE_DIR/default-param-values.xml"
fi
if [ -f "$DEFAULT_OPTIONS" ]
then
cp -f -u "$DEFAULT_OPTIONS" "$SHARE_DIR/default-options.txt"
fi
read -r -d '' TEMPLATE <<'EOF'
#!/bin/bash
# qsub options
#$ -S /bin/bash
#$ -V
#$ -cwd
ulimit -c 0
export CLASSPATH="__LIB_DIR__/*:$CLASSPATH"
JVMOPTS=
OPTERR=0
while getopts J: o; do
case "$o" in
J) JVMOPTS="$JVMOPTS $OPTARG";;
?) break;;
esac
done
shift $(($OPTIND-1))
OPTS=""
if [ -f "__SHARE_DIR__/default-param-values.xml" ]
then
OPTS="$OPTS ""-defaultParamValuesFile __SHARE_DIR__/default-param-values.xml"
fi
if [ -f "__SHARE_DIR__/default-options.txt" ]
then
OPTS="$OPTS "$(cat __SHARE_DIR__/default-options.txt)
fi
java $JVMOPTS fr.inra.maiage.bibliome.alvisnlp.core.app.cli.AlvisNLP $OPTS "$@"
EOF
BIN_FILE="$BIN_DIR/alvisnlp-$VERSION"
sed -e "s,__LIB_DIR__,$LIB_DIR," -e "s,__SHARE_DIR__,$SHARE_DIR," <<<"$TEMPLATE" >"$BIN_FILE"
chmod +x "$BIN_FILE"
ln -s -f "$BIN_FILE" "$BIN_DIR/alvisnlp"