forked from czcorpus/kontext
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.ubuntu.sh
executable file
·219 lines (184 loc) · 6.97 KB
/
install.ubuntu.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
#!/bin/bash
# ----------------------------------------
# Installation script for Ubuntu 18.04
# ----------------------------------------
WEBSERVER_USER="www-data"
MANATEE_VER=2.158.8
# run the install script from the installation root directory
INSTALL_DIR="$(dirname $(dirname $(readlink -f $(dirname "$0" ))))"
echo "Fullpath to the current KonText installation directory: $INSTALL_DIR"
# ---------------------
# set installation type
# ---------------------
INSTALL_TYPE="default"
# check installation type parameter
while [[ $# -gt 0 ]]
do
key="$1"
case ${key} in
-t|--type)
if [ $2 == 'ucnk' ]
then
INSTALL_TYPE='ucnk'
fi
echo Installation type ${INSTALL_TYPE}
shift
shift
;;
esac
done
# ------------------
# set up environment
# ------------------
cd /
# trap 'exit' ERR
# --------------------------------------
# Install prerequisites for Ubuntu 18.04
# --------------------------------------
apt-get update -y
locale-gen en_US.UTF-8
# install nodejs
apt-get install -y ca-certificates curl nodejs npm
npm install -g webpack
# install general & manatee prerequisites
apt-get install openssh-server net-tools nginx redis-server build-essential openssl pkg-config wget
# apt-get install libssl-dev
apt-get install python python-dev python-pip python-lxml python-cheetah python-simplejson
apt-get install libltdl7 libpcre3 libpcre++-dev libxml2-dev libxslt-dev libltdl-dev
pip install 'redis==2.10.6' gunicorn celery
# install kontext requirements
pip install -r ${INSTALL_DIR}/requirements.txt
# -------------------------------------
# install & set up manatee etc.
# -------------------------------------
# python signal fd common for both scenarios
cd /usr/local/bin
wget https://corpora.fi.muni.cz/noske/deb/1604/python-signalfd/python-signalfd_0.1-1ubuntu1_amd64.deb
dpkg -i python-signalfd_0.1-1ubuntu1_amd64.deb
# Celery
useradd -r -s /bin/false celery
adduser celery ${WEBSERVER_USER}
mkdir /etc/conf.d
cp /opt/kontext/scripts/install/conf/celery-conf.d /etc/conf.d/celery
cp /opt/kontext/scripts/install/conf/celery.service /etc/systemd/system
cp /opt/kontext/scripts/install/conf/celery.tmpfiles /usr/lib/tmpfiles.d/celery.conf
mkdir /var/log/celery
chown celery:root /var/log/celery
mkdir /var/run/celery
chown celery:root /var/run/celery
systemctl enable celery
systemctl daemon-reload
# Nginx
cp /opt/kontext/scripts/install/conf/nginx /etc/nginx/sites-available/default
case ${INSTALL_TYPE} in
ucnk)
# build from sources, use ucnk manatee patch
# Manatee
cd /usr/local/src
wget http://corpora.fi.muni.cz/noske/src/manatee-open/manatee-open-${MANATEE_VER}.tar.gz
tar xzvf manatee-open-${MANATEE_VER}.tar.gz; cd manatee-open-${MANATEE_VER}
cp ${INSTALL_DIR}/scripts/install/ucnk-manatee-${MANATEE_VER}.patch ./
patch -p0 < ucnk-manatee-${MANATEE_VER}.patch
./configure --with-pcre; make
make install; ldconfig
# move manatee files in case of CentOS
cd /usr/local/lib64/python2.7/site-packages/
cp * /usr/lib/python2.7/site-packages/
# Susanne corpus
cd /usr/local/src
wget https://corpora.fi.muni.cz/noske/src/example-corpora/susanne-example-source.tar.bz2
tar xvjf susanne-example-source.tar.bz2
# set up sample corpus
mkdir -p /var/lib/manatee/registry
mkdir -p /var/lib/manatee/vert
mkdir -p /var/lib/manatee/data/susanne
# create user filter files directory
mkdir -p /var/local/corpora/user_filter_files
# copy Susanne files from sample sources
cd /usr/local/src/susanne-example-source
sed -i 's%PATH susanne%PATH "/var/lib/manatee/data/susanne"%' ./config
cp ./source /var/lib/manatee/vert/susanne.vert
cp ./config /var/lib/manatee/registry/susanne
# generate data
encodevert -v -c ./config -p /var/lib/manatee/data/susanne ./source
;;
*)
# default: install from binary packages
cd /usr/local/bin
wget https://corpora.fi.muni.cz/noske/deb/1604/manatee-open/manatee-open_${MANATEE_VER}-1ubuntu1_amd64.deb
wget https://corpora.fi.muni.cz/noske/deb/1604/manatee-open/manatee-open-python_${MANATEE_VER}-1ubuntu1_amd64.deb
wget https://corpora.fi.muni.cz/noske/deb/1604/manatee-open/manatee-open-susanne_${MANATEE_VER}-1ubuntu1_amd64.deb
dpkg -i manatee-open_${MANATEE_VER}-1ubuntu1_amd64.deb
dpkg -i manatee-open-python_${MANATEE_VER}-1ubuntu1_amd64.deb
dpkg -i manatee-open-susanne_${MANATEE_VER}-1ubuntu1_amd64.deb
;;
esac
# --------------
# set up KonText
# --------------
# copy sample config files into working config files
cd ${INSTALL_DIR}/conf
cp config.default.xml config.xml
cp corplist.default.xml corplist.xml
cp beatconfig.sample.py beatconfig.py
# update config.xml with current install path
sed -i s%/opt/kontext%${INSTALL_DIR}% config.xml
# create directories, set permissions
cd /var/local
mkdir -p corpora
cd corpora
mkdir -p registry
mkdir -p cache
mkdir -p subcorp
mkdir -p freqs-precalc
mkdir -p freqs-cache
mkdir -p colls-cache
chown ${WEBSERVER_USER}:${WEBSERVER_USER} cache
chmod g+ws cache
chown ${WEBSERVER_USER}:${WEBSERVER_USER} subcorp
chmod g+ws subcorp
chown ${WEBSERVER_USER}:${WEBSERVER_USER} freqs-precalc
chmod g+ws freqs-precalc
chown ${WEBSERVER_USER}:${WEBSERVER_USER} freqs-cache
chmod g+ws freqs-cache
chown ${WEBSERVER_USER}:${WEBSERVER_USER} colls-cache
chmod g+ws colls-cache
chmod -R 775 subcorp
cd /var/log
mkdir -p kontext
chown ${WEBSERVER_USER}: kontext
cd /tmp
mkdir -p kontext-upload
chown ${WEBSERVER_USER}: kontext-upload
chmod -R 775 kontext-upload
# run config test
cd ${INSTALL_DIR}
python scripts/validate_setup.py conf/config.xml
# build kontext
npm install; make production
# set the anonymous user in Redis
redis-cli -n 1 set user:1 "{\"id\": 1, \"user\": \"public\", \"fullname\": \"public user\", \"pwd_hash\": \"\"}"
# generate random password for the "kontext" user and its hash using default parameters
cd ${INSTALL_DIR}
response=$(python scripts/generate_random_pwd.py)
pwd=${response%-*}
hash=${response:9}
# set the "kontext" user in redis
redis-cli -n 1 hset user_index "kontext" "\"user:2\""
redis-cli -n 1 set user:2 "{\"username\": \"kontext\", \"firstname\": \"Kontext\", \"lastname\": \"Test\", \"id\": 2, \"pwd_hash\": \"$hash\", \"email\": \"test@example.com\"}"
redis-cli -n 1 set corplist:user:1 "[\"susanne\"]"
redis-cli -n 1 set corplist:user:2 "[\"susanne\"]"
systemctl start celery
systemctl restart nginx
cd ${INSTALL_DIR}
# print final info
echo "KonText installation successfully completed."
echo "To start KonText, enter the following command in the KonText install root directory (i.e. $INSTALL_DIR):"
echo ""
echo "sudo -u $WEBSERVER_USER python public/app.py --address 127.0.0.1 --port 8080"
echo ""
echo "(--address and --port parameters are optional; default serving address is 127.0.0.1:5000)"
echo "-------------"
echo "To login as a test user, please use the following credentials:"
echo "username: kontext"
echo "password: $pwd"