-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathdeploy.bash
executable file
·327 lines (290 loc) · 8.47 KB
/
deploy.bash
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
#!/usr/bin/env bash
# user, that executes this script must be in sudo group
#parse command line
step="*"
while [[ $# -gt 1 ]]; do
key=$1
case $key in
-s|--step)
step="$2"
shift
;;
*)
echo 'Unknown option: '
tail -1 $key
exit
;;
esac
shift
done
if [[ -n $1 ]]; then
echo "Last option not have argument: "
tail -1 $1
exit
fi
CATS_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" # assume, that script is in a root dir of repo
# PROXY USERS, PLEASE READ THIS
# If your network is behind proxy please uncomment and set following variables
#export http_proxy=host:port
#export https_proxy=$http_proxy
#export ftp_proxy=$http_proxy
#
# You also NEED to replace following line in /etc/sudoers:
# Defaults env_reset
# With:
# Defaults env_keep="http_proxy https_proxy ftp_proxy"
# Group, apache running under
http_group=www-data
FB_DEV_VERSION=`sudo apt-cache pkgnames | grep firebird-dev`
FB_DEV_VERSION=`sudo apt-cache show firebird-dev | grep Version`
[[ $FB_DEV_VERSION =~ ([0-9]+\.[0-9]+) ]]
FB_DEV_VERSION=${BASH_REMATCH[1]}
FB_DEF_OP_MODE='superclassic'
packages=(firebird-dev)
# The firebird-dev package may contain different verisons of Firebird.
# It depends on platform you're using.
# Packages firebird2.*-(classic|super|superclassic) are mutually exclusive.
# Firebird 3.0 and higher allows to switch Operation Mode in the
# /etc/firebird/3.*/firebird.conf
echo "1. Install apt packages... "
if [[ $step =~ (^|,)1(,|$) || $step == "*" ]]; then
if [[ FB_DEV_VERSION ]]
then
if [[ `echo "$FB_DEV_VERSION < 3.0" | bc` -eq 1 ]]; then
read -e -p "Firebird Operation Mode (classic, super, superclassic): " -i $FB_DEF_OP_MODE $FB_DEF_OP_MODE
FB_PACKAGE=firebird${FB_DEV_VERSION}-${FB_DEF_OP_MODE}
else
FB_PACKAGE=firebird${FB_DEV_VERSION}-server
fi
packages+=($FB_PACKAGE)
else
echo "Can't find a proper firebird-dev package"
fi
packages+=(
git unzip wget build-essential
libaspell-dev aspell-en aspell-ru
libhunspell hunspell-en hunspell-ru
apache2 libapache2-mod-perl2 libapreq2-3 libapreq2-dev
libapache2-mod-perl2-dev libexpat1 libexpat1-dev libapache2-request-perl cpanminus)
sudo apt-get -y install ${packages[@]}
sudo dpkg-reconfigure $FB_PACKAGE # In some cases default dialog just doesn't configure SYSDBA user
echo "ok"
else
echo "skip"
fi
echo "2. Install cpan packages... "
if [[ $step =~ (^|,)2(,|$) || $step == "*" ]]; then
cpan_packages=(
Module::Install
DBI
DBI::Profile
DBD::Firebird
Algorithm::Diff
Apache2::Request
Archive::Zip
Authen::Passphrase
File::Copy::Recursive
JSON::XS
SQL::Abstract
Template
Test::Exception
Text::Aspell
Text::CSV
Text::Hunspell
Text::MultiMarkdown
XML::Parser::Expat
)
sudo cpanm -S ${cpan_packages[@]}
echo "ok"
else
echo "skip"
fi
echo "3. Init and update submodules... "
if [[ $step =~ (^|,)3(,|$) || $step == "*" ]]; then
git submodule init
git submodule update
echo "ok"
else
echo "skip"
fi
echo "4. Install formal input... "
if [[ $step =~ (^|,)4(,|$) || $step == "*" ]]; then
formal_input='https://github.com/downloads/klenin/cats-main/FormalInput.tgz'
wget $formal_input -O fi.tgz
tar -xzvf fi.tgz
pushd FormalInput/
perl Makefile.PL
make
sudo make install
popd
rm fi.tgz
rm -rf FormalInput
echo "ok"
else
echo "skip"
fi
echo "5. Generating docs... "
if [[ $step =~ (^|,)5(,|$) || $step == "*" ]]; then
cd docs/tt
ttree -f ttreerc
cd $CATS_ROOT
echo "ok"
else
echo "skip"
fi
echo "6. Configure Apache... "
if [[ $step =~ (^|,)6(,|$) || $step == "*" ]]; then
APACHE_CONFIG=$(cat <<EOF
PerlSetEnv CATS_DIR ${CATS_ROOT}/cgi-bin/
<VirtualHost *:80>
PerlRequire ${CATS_ROOT}/cgi-bin/CATS/Web/startup.pl
<Directory "${CATS_ROOT}/cgi-bin/">
Options -Indexes
LimitRequestBody 1048576
Require all granted
PerlSendHeader On
SetHandler perl-script
PerlResponseHandler main
</Directory>
ExpiresActive On
ExpiresDefault "access plus 5 seconds"
ExpiresByType text/css "access plus 1 week"
ExpiresByType application/javascript "access plus 1 week"
ExpiresByType image/gif "access plus 1 week"
ExpiresByType image/png "access plus 1 week"
ExpiresByType image/x-icon "access plus 1 week"
Alias /cats/static/css/ "${CATS_ROOT}/css/"
Alias /cats/static/ "${CATS_ROOT}/static/"
<Directory "${CATS_ROOT}/static">
# Apache allows only absolute URL-path
ErrorDocument 404 /cats/?f=static
#Options FollowSymLinks
AddDefaultCharset utf-8
Require all granted
</Directory>
Alias /cats/download/ "${CATS_ROOT}/download/"
<Directory "${CATS_ROOT}/download">
Options -Indexes
Require all granted
AddCharset utf-8 .txt
</Directory>
Alias /cats/docs/ "${CATS_ROOT}/docs/"
<Directory "${CATS_ROOT}/docs">
AddDefaultCharset utf-8
Require all granted
</Directory>
Alias /cats/junior/ "${CATS_ROOT}/junior/"
<Directory "${CATS_ROOT}/ev">
AddDefaultCharset utf-8
Require all granted
</Directory>
Alias /cats/css/ "${CATS_ROOT}/css/"
<Directory "${CATS_ROOT}/css/">
AllowOverride Options=Indexes,MultiViews,ExecCGI FileInfo
Require all granted
</Directory>
Alias /favicon.ico "${CATS_ROOT}/images/favicon.ico"
Alias /cats/images/ "${CATS_ROOT}/images/"
<Directory "${CATS_ROOT}/images/">
AllowOverride Options=Indexes,MultiViews,ExecCGI FileInfo
Require all granted
</Directory>
Alias /cats/js/ "${CATS_ROOT}/js/"
<Directory "${CATS_ROOT}/js/">
AllowOverride Options=Indexes,MultiViews,ExecCGI FileInfo
Require all granted
</Directory>
Alias /cats/ "${CATS_ROOT}/cgi-bin/"
Alias /cats "${CATS_ROOT}/cgi-bin/"
</VirtualHost>
EOF
)
sudo sh -c "echo '$APACHE_CONFIG' > /etc/apache2/sites-available/000-cats.conf"
sudo a2ensite 000-cats
sudo a2dissite 000-default
sudo a2enmod expires
sudo a2enmod apreq2
# Adjust permissions.
sudo chgrp -R ${http_group} cgi-bin css download images static tt
chmod -R g+r cgi-bin
chmod g+rw static tt download/{,att,f,img,pr,vis} cgi-bin/rank_cache{,/r} cgi-bin/repos
sudo service apache2 reload
sudo service apache2 restart
echo "ok"
else
echo "skip"
fi
echo "7. Download JS... "
if [[ $step =~ (^|,)7(,|$) || $step == "*" ]]; then
perl -e 'install_js.pl --install=all'
cd $CATS_ROOT
echo "ok"
else
echo "skip"
fi
echo "8. Configure and init cats database... "
if [[ ($step =~ (^|,)8(,|$) || $step == "*") && $FB_DEV_VERSION ]]; then
firebird="1"
dbms=""
while [ "$dbms" != "1" -a "$dbms" != "2" ]; do
echo -e "Choose DBMS:\n 1. Firebird\n 2. Postgres"
read dbms
done
CONFIG_NAME="Config.pm"
CONFIG_ROOT="${CATS_ROOT}/cgi-bin/cats-problem/CATS"
CREATE_DB_NAME="create_db.sql"
CREATE_DB_ROOT="${CATS_ROOT}/sql/"
if [[ "$dbms" = "$firebird" ]]; then
CREATE_DB_ROOT+="interbase"
else
sudo apt-get -y install "postgresql" "libpq-dev"
sudo service postgresql restart
sudo cpanm -S "DBD::Pg"
CREATE_DB_ROOT+="postgres"
fi
echo -e "...\n...\n..."
answer=""
while [ "$answer" != "y" -a "$answer" != "n" ]; do
echo -n "Do you want to do the automatic setup? "
read answer
done
if [ "$answer" = "n" ]; then
echo -e "Setup is done, you need to do following manualy:\n"
echo -e " 1. Navigate to ${CONFIG_ROOT}/"
echo -e " 2. Adjust your database connection settings in ${CONFIG_NAME}"
echo -e " 3. Navigate to ${CREATE_DB_ROOT}/"
echo -e " 4. Adjust your database connection settings in ${CREATE_DB_NAME} and create database\n"
exit 0
fi
def_db_host="localhost"
read -e -p "Host: " -i $def_db_host db_host
read -e -p "Username: " db_user
read -e -p "Password: " db_pass
if [[ "$dbms" = "$firebird" ]]; then
def_path_to_db="$HOME/.cats/cats.fdb"
read -e -p "Path to database: " -i $def_path_to_db path_to_db
FB_ALIASES="/etc/firebird/${FB_DEV_VERSION}/"
# aliases.conf is replaced by databases.conf in firebird 3.x
FB_ALIASES=$FB_ALIASES$([ `echo "$FB_DEV_VERSION < 3.0" | bc` -eq 1 ] &&
echo "aliases.conf" || echo "databases.conf")
alias="cats = $path_to_db"
has_alias=$(sudo cat $FB_ALIASES | grep -c "$alias")
if [ $has_alias -eq 0 ]; then
sudo sh -c "echo 'cats = $path_to_db' >> $FB_ALIASES"
fi
if [[ "$path_to_db" = "$def_path_to_db" ]]; then
mkdir "$HOME/.cats"
fi
sudo chown firebird.firebird $(dirname "$path_to_db")
perl -I "$CATS_ROOT/cgi-bin" -MCATS::Deploy -e \
"CATS::Deploy::create_db interbase, cats, '$db_user', '$db_pass', init_config => 1,
host => '$db_host', quiet => 1"
else
perl -I "$CATS_ROOT/cgi-bin" -MCATS::Deploy -e \
"CATS::Deploy::create_db postgres, cats, '$db_user', '$db_pass', pg_auth_type => peer,
init_config => 1, host => '$db_host', quiet => 1"
fi
echo "ok"
else
echo "skip"
fi