This repository has been archived by the owner on Jan 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
install_zotero.sh
executable file
·354 lines (282 loc) · 13.7 KB
/
install_zotero.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
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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
#!/bin/bash
echo "######################################################"
echo "######################################################"
echo "######################################################"
echo "### SCRIPT TO INSTALL ZOTERO WITH MINIMUM EFFORTS ####"
echo "### AUTHOR: PATRICK HÖHN #############################"
echo "### RELEASED UNDER GPLv2 OR LATER ####################"
echo "######################################################"
echo "######################################################"
echo "######################################################"
echo "install required packages"
echo "add key for elasticsearch repository"
wget -qO - http://packages.elasticsearch.org/GPG-KEY-elasticsearch | apt-key add -
echo "add debian wheezy backports repository"
# removed for the time being, potentially not required anymore
# sed -i '$s,$,\ndeb http://ftp.acc.umu.se./debian wheezy-backports main,' /etc/apt/sources.list
sed -i '$s,$,\ndeb http://packages.elasticsearch.org/elasticsearch/1.4/debian stable main,' /etc/apt/sources.list
echo "update package cache"
apt-get update
echo "dependencies for dataserver"
apt-get install -y apache2 libapache2-mod-php5 mysql-server memcached zendframework php5-cli php5-memcache php5-mysql php5-curl php5-memcached
echo "general dependencies"
apt-get install -y git gnutls-bin runit libapache2-modsecurity curl elasticsearch openjdk-7-jre
echo "created required directories"
mkdir -p /srv/zotero/dataserver
# fuck DEBIAN
#mkdir -p /srv/zotero/log/{download,upload,error}
mkdir -p /srv/zotero/log/download
mkdir -p /srv/zotero/log/upload
mkdir -p /srv/zotero/log/error
# save current directory
cur_dir=$(pwd)
echo "setting elasticsearch to be started during booting"
update-rc.d elasticsearch defaults 95 10
echo "starting elasticsearch"
/etc/init.d/elasticsearch start
echo "download source code of dataserver"
git clone git://github.com/zotero/dataserver.git /srv/zotero/dataserver
echo "download source code of Elastica"
git clone git://github.com/ruflin/Elastica.git /srv/zotero/dataserver/include/Elastica
cd /srv/zotero/dataserver/include/Elastica
git checkout fc607170ab2ca751097648d48a5d38e15e9d5f6a
echo "install composer"
cd /srv/zotero/dataserver
curl -sS https://getcomposer.org/installer | php
echo "install dependencies"
php composer.phar install
echo "remove composer"
rm composer.phar
echo "install add_user script"
cp "$cur_dir/add_user" /srv/zotero/dataserver/admin
echo "install change_password script"
cp "$cur_dir/change_password" /srv/zotero/dataserver/admin
echo "patch master.sql"
cp "$cur_dir/master.sql" /srv/zotero/dataserver/misc
echo "prepare directory rights"
chown www-data:www-data /srv/zotero/dataserver/tmp
echo "replace zend by native installation"
cd /srv/zotero/dataserver/include
rm -r Zend
ln -s /usr/share/php/Zend/
read -p "Do you want to use SSL certificates for Zotero server? (y/n)" SSL
if [ $SSL=y ] ;
then
read -p "Do you want to generate SSL certificates now? (y/n)" gen_SSL
if [ $gen_SSL=y ];
then
echo "generate SSL key and cert"
certtool -p --sec-param high --outfile /etc/apache2/zotero.key
certtool -s --load-privkey /etc/apache2/zotero.key --outfile /etc/apache2/zotero.cert
else
cp "$cur_dir/zotero.key" /etc/apache2/zotero.key
cp "$cur_dir/zotero.cert" /etc/apache2/zotero.cert
fi
fi
read -p "Do you want to use SSL certificates for LibreS3? (y/n)" SSL_LibreS3
if [ $SSL_LibreS3=y ] ;
then
cat "$cur_dir/sx.cert" >> /srv/zotero/dataserver/vendor/guzzle/guzzle/src/Guzzle/Http/Resources/cacert.pem
fi
echo "enable rewrite support for apache2 server"
a2enmod rewrite
if [ $SSL=y ] ;
then
echo "enable ssl support for apache2 server"
a2enmod ssl
echo "create available site for zotero"
echo "<VirtualHost *:443>
DocumentRoot /srv/zotero/dataserver/htdocs
SSLEngine on
SSLCertificateFile /etc/apache2/zotero.cert
SSLCertificateKeyFile /etc/apache2/zotero.key
<Directory "/srv/zotero/dataserver/htdocs/">
Options FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ErrorLog /srv/zotero/error.log
CustomLog /srv/zotero/access.log common
</VirtualHost>" > /etc/apache2/sites-available/zotero
else
echo "create available site for zotero"
echo "<VirtualHost *:80>
DocumentRoot /srv/zotero/dataserver/htdocs
<Directory "/srv/zotero/dataserver/htdocs/">
Options FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ErrorLog /srv/zotero/error.log
CustomLog /srv/zotero/access.log common
</VirtualHost>" > /etc/apache2/sites-available/zotero
fi
echo "activate site for zotero"
a2ensite zotero
echo "change .htaccess"
sed -i '3i RewriteCond %{REQUEST_URI} !^/zotero' /srv/zotero/dataserver/htdocs/.htaccess
echo "restart apache2"[5~
service apache2 reload
echo "###############"
echo "configure MySQL"
echo "###############"
echo " [mysqld]
character-set-server = utf8
collation-server = utf8_general_ci
event-scheduler = ON
sql-mode = STRICT_ALL_TABLES
default-time-zone = '+0:00'" > /etc/mysql/conf.d/zotero.cnf
/etc/init.d/mysql restart
echo -n "root Password for MySQL: "
read password
echo -n "password for zotero database user: "
read zotero_password
cd /srv/zotero/dataserver/misc
DB="mysql -h 127.0.0.1 -P 3306 -u root -p${password}"
echo "DROP DATABASE IF EXISTS zotero_master" | $DB
echo "DROP DATABASE IF EXISTS zotero_shards" | $DB
echo "DROP DATABASE IF EXISTS zotero_ids" | $DB
echo "DROP DATABASE IF EXISTS zotero_www" | $DB
echo "CREATE DATABASE zotero_master" | $DB
echo "CREATE DATABASE zotero_shards" | $DB
echo "CREATE DATABASE zotero_ids" | $DB
echo "CREATE DATABASE zotero_www" | $DB
echo "DROP USER IF EXISTS zotero@localhost;" | $DB
echo "CREATE USER zotero@localhost IDENTIFIED BY '${zotero_password}';" | $DB
echo "GRANT SELECT, INSERT, UPDATE, DELETE ON zotero_master.* TO zotero@localhost;" | $DB
echo "GRANT SELECT, INSERT, UPDATE, DELETE ON zotero_shards.* TO zotero@localhost;" | $DB
echo "GRANT SELECT,INSERT,DELETE ON zotero_ids.* TO zotero@localhost;" | $DB
echo "GRANT SELECT,INSERT,DELETE ON zotero_www.* TO zotero@localhost;" | $DB
echo "Load in master schema"
$DB zotero_master < master.sql
$DB zotero_master < coredata.sql
$DB zotero_master < fulltext.sql
echo "Set up shard info"
echo "INSERT INTO shardHosts VALUES (1, '127.0.0.1', 3306, 'up');" | $DB zotero_master
echo "INSERT INTO shards VALUES (1, 1, 'zotero_shards', 'up', 0);" | $DB zotero_master
echo Load in shard schema
cat shard.sql | $DB zotero_shards
cat triggers.sql | $DB zotero_shards
echo "Load in schema on id server"
cat ids.sql | $DB zotero_ids
echo "Load in www schema"
$DB zotero_www < $(cur_dir)www.sql
echo "Setup roleIDs"
echo "INSERT INTO LUM_ROLE VALUES ('Deleted', 1);" | $DB zotero_www
echo "INSERT INTO LUM_ROLE VALUES ('Invalid', 2);" | $DB zotero_www
echo "INSERT INTO LUM_ROLE VALUES ('Valid', 3);" | $DB zotero_www
echo "#################################"
echo "Configuration database connection"
echo "#################################"
# add code to also configure other databases
cp /srv/zotero/dataserver/include/config/dbconnect.inc.php-sample /srv/zotero/dataserver/include/config/dbconnect.inc.php
echo -n "hostname for database: "
read hostname
sed -i "s/host\ =\ ''/host\ =\ '${hostname}'/g" /srv/zotero/dataserver/include/config/dbconnect.inc.php
sed -i "s/host\ =\ false/host\ =\ '${hostname}'/g" /srv/zotero/dataserver/include/config/dbconnect.inc.php
sed -i "s/port\ =\ ''/port\ =\ 3306/g" /srv/zotero/dataserver/include/config/dbconnect.inc.php
sed -i "s/port\ =\ false/port\ =\ 3306/g" /srv/zotero/dataserver/include/config/dbconnect.inc.php
sed -i "s/user\ =\ ''/user\ =\ 'zotero'/g" /srv/zotero/dataserver/include/config/dbconnect.inc.php
sed -i "s/user\ =\ false/user\ =\ 'zotero'/g" /srv/zotero/dataserver/include/config/dbconnect.inc.php
sed -i "s/pass\ =\ ''/pass\ =\ '${zotero_password}'/g" /srv/zotero/dataserver/include/config/dbconnect.inc.php
sed -i "s/pass\ =\ false/pass\ =\ '${zotero_password}'/g" /srv/zotero/dataserver/include/config/dbconnect.inc.php
sed -i "8s/db\ =\ ''/db\ =\ 'zotero_master'/" /srv/zotero/dataserver/include/config/dbconnect.inc.php
sed -i "15s/db\ =\ false/db\ =\ 'zotero_shards'/" /srv/zotero/dataserver/include/config/dbconnect.inc.php
sed -i "22s/db\ =\ false/db\ =\ 'zotero_master'/" /srv/zotero/dataserver/include/config/dbconnect.inc.php
sed -i "s/ids/zotero_ids/g" /srv/zotero/dataserver/include/config/dbconnect.inc.php
sed -i "s/'www'/'zotero_www'/g" /srv/zotero/dataserver/include/config/dbconnect.inc.php
echo "###################################"
echo "General configuration of dataserver"
echo "###################################"
cp /srv/zotero/dataserver/include/config/config.inc.php-sample /srv/zotero/dataserver/include/config/config.inc.php
sed -i "s/TESTING_SITE\ =\ true/TESTING_SITE\ =\ false/" /srv/zotero/dataserver/include/config/config.inc.php
sed -i "s/DEV_SITE\ =\ true/DEV_SITE\ =\ false/" /srv/zotero/dataserver/include/config/config.inc.php
echo -n "base-uri for zotero api: "
read API_URI
sed -i "s,API_BASE_URI\ =\ '',API_BASE_URI = '${API_URI}'," /srv/zotero/dataserver/include/config/config.inc.php
echo -n "sync domain for zotero: "
read SYNC_DOMAIN
sed -i "s/SYNC_DOMAIN\ =\ ''/SYNC_DOMAIN\ =\ '${SYNC_DOMAIN}'/" /srv/zotero/dataserver/include/config/config.inc.php
echo -n "Salt for passwords: "
read AUTH_SALT
sed -i "s/AUTH_SALT\ =\ ''/AUTH_SALT\ =\ '${AUTH_SALT}'/" /srv/zotero/dataserver/include/config/config.inc.php
echo -n "api super username: "
read API_SUPER_USERNAME
sed -i "s/API_SUPER_USERNAME\ =\ ''/API_SUPER_USERNAME\ =\ '${API_SUPER_USERNAME}'/" /srv/zotero/dataserver/include/config/config.inc.php
echo -n "api super password: "
read API_SUPER_PASSWORD
sed -i "s/API_SUPER_PASSWORD\ =\ ''/API_SUPER_PASSWORD\ =\ '${API_SUPER_PASSWORD}'/" /srv/zotero/dataserver/include/config/config.inc.php
echo -n "aws access key: "
read AWS_ACCESS_KEY
sed -i "s/AWS_ACCESS_KEY\ =\ ''/AWS_ACCESS_KEY\ =\ '${AWS_ACCESS_KEY}'/" /srv/zotero/dataserver/include/config/config.inc.php
echo -n "aws secret key: "
read AWS_SECRET_KEY
sed -i "s/AWS_SECRET_KEY\ =\ ''/AWS_SECRET_KEY\ =\ '${AWS_SECRET_KEY}'/" /srv/zotero/dataserver/include/config/config.inc.php
echo -n "s3_bucket: "
read S3_BUCKET
sed -i "s/S3_BUCKET\ =\ ''/S3_BUCKET\ =\ '${S3_BUCKET}'/" /srv/zotero/dataserver/include/config/config.inc.php
sed -i "s/us-east-1/custom/" /srv/zotero/dataserver/include/config/config.inc.php
echo -n "s3 endpoint url: "
read S3_ENDPOINT
sed -i "s/S3_ENDPOINT\ =\ 's3.amazonaws.com'/S3_ENDPOINT\ =\ '${S3_ENDPOINT}'/" /srv/zotero/dataserver/include/config/config.inc.php
read AWS_HOST
sed -i "27a\ \ \ \ \ \ \ \ public static \$AWS_HOST\ =\ '${AWS_HOST};'" /srv/zotero/dataserver/include/config/config.inc.php
sed -i "30i\ \ \ \ \ \ \ \ public static \$URI_PREFIX_DOMAIN_MAP = array(" /srv/zotero/dataserver/include/config/config.inc.php
sed -i "31i\ \ \ \ \ \ \ \ \ \ '\/sync\/' => 'sync'" /srv/zotero/dataserver/include/config/config.inc.php
sed -i "32i\ \ \ \ \ \ \ \ );" /srv/zotero/dataserver/include/config/config.inc.php
sed -i "33i \ " /srv/zotero/dataserver/include/config/config.inc.php
echo -n "memcached servers: "
read MEMCACHED_SERVERS
sed -i "s/'memcached1.localdomain:11211:2',\ 'memcached2.localdomain:11211:1'/'${MEMCACHED_SERVERS}'/" /srv/zotero/dataserver/include/config/config.inc.php
echo "Configure document root folder"
sed -i "s/var\/www\/dataserver/srv\/zotero\/dataserver/" /srv/zotero/dataserver/include/config/config.inc.php
echo "##############################################################"
echo "patch header.inc.php for including host name for using own AWS"
echo "##############################################################"
sed -i "225a \$awsconfig['base_url']\ =\ \"http://\" . ZCONFIG::\$AWS_HOST;" /srv/zotero/dataserver/include/header.inc.php
echo "###############################################################################"
echo "patch Storage.inc.php for using custom host name for generating base Upload URL"
echo "###############################################################################"
sed -i "s,\".s3.amazonaws.com/\",\ \".\" . Z_CONFIG::$AWS_HOST" /srv/zotero/dataserver/model/Storage.inc.php
echo "#####################################"
echo "patch AWS-SDK to use custom S3 server"
echo "#####################################"
sed -i "s,{service}.{region}.amazonaws.com,s3.drossenhausen.de.vu" /srv/zotero/dataserver/vendor/aws/aws-sdk-php/src/Aws/Common/Resources/public-endpoints.php
echo "###############"
echo "Configure runit"
echo "###############"
# because of damned debian split in three commands
# mkdir -p /etc/sv/{zotero-download,zotero-error,zotero-upload}/log
mkdir -p /etc/sv/zotero-download/log
mkdir -p /etc/sv/zotero-error/log
mkdir -p /etc/sv/zotero-upload/log
echo "#!/bin/sh
cd /srv/zotero/dataserver/processor/download
exec 2>&1
exec chpst -u www-data:www-data php5 daemon.php" > /etc/sv/zotero-download/run
echo "#!/bin/sh
cd /srv/zotero/dataserver/processor/error
exec 2>&1
exec chpst -u www-data:www-data php5 daemon.php" > /etc/sv/zotero-error/run
echo "#!/bin/sh
cd /srv/zotero/dataserver/processor/upload
exec 2>&1
exec chpst -u www-data:www-data php5 daemon.php" > /etc/sv/zotero-upload/run
echo "#!/bin/sh
exec svlogd /srv/zotero/log/download" > /etc/sv/zotero-download/log/run
echo "#!/bin/sh
exec svlogd /srv/zotero/log/error" > /etc/sv/zotero-error/log/run
echo "#!/bin/sh
exec svlogd /srv/zotero/log/upload" > /etc/sv/zotero-upload/log/run
chmod +x /etc/sv/zotero-download/run
chmod +x /etc/sv/zotero-error/run
chmod +x /etc/sv/zotero-upload/run
chmod +x /etc/sv/zotero-download/log/run
chmod +x /etc/sv/zotero-error/log/run
chmod +x /etc/sv/zotero-upload/log/run
cd /etc/service
ln -s ../sv/zotero-download /etc/service/
ln -s ../sv/zotero-upload /etc/service/
ln -s ../sv/zotero-error /etc/service/