-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrocky-dataverse.sh
488 lines (381 loc) · 15.6 KB
/
rocky-dataverse.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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
#!/usr/bin/env bash
#
# Install Dataverse on Rocky Linux
#
# Alan Franco
# github.com/fzappa/rocky-dataverse
#
# License: GPL-3.0
#
# Based on https://guides.dataverse.org/en/5.11/installation/prerequisites.html
#
####### CHANGE ME ##########
INSTITUTE="My Institute"
EMAIL="user@domain.org"
PROJECT_NAME="RedeDadosAbertos"
SCRIPT_DIR="/opt/rocky-dataverse"
DATAVERSE_VERSION="5.11"
JAVA_VERSION="11"
POSTGRESQL_VERSION="13"
PAUSE_SETUP="YES"
# DOI CONFIGURE
USE_FAKE_DOI="YES"
# EDIT IF USE_FAKE_DOI="NO"
DOI_PREFIX="10.5072"
DOI_USERNAME="username"
DOI_PASSWD="password"
# CONFIGURE SEND E-MAIL
SEND_EMAIL="NO"
MAIL_HOST="mail.smtp"
MAIL_USER=$EMAIL
FROM_ADDRESS=$EMAIL
BUILD_IMAGEMAGICK="YES"
BUILD_R="YES"
CHANGE_PAYARA_INDEX="NO"
# CUSTOM HEADER, FOOTER AND HOMEPAGE
CUSTOM_PAGES="NO"
# If you want to install Maxmind
# Create an account and download at: https://dev.maxmind.com/geoip/geolite2-free-geolocation-data?lang=en
BUILD_MAXMIND="YES"
GEOLITE_PACKAGE="GeoLite2-Country.tar.gz"
# Change according to version
# FIXME ==>
if [[ $DATAVERSE_VERSION == "5.11" || $DATAVERSE_VERSION == "5.10.1" || $DATAVERSE_VERSION == "5.9" ]]; then
# v5.11, v5.10.1, v5.9
PAYARA_VERSION="5.2021.6"
else
echo -e "${RED}ERROR: Dataverse $DATAVERSE_VERSION is not supported.${NC}"
exit
fi
SOLR_VERSION="8.11.1"
PAYARA_SERVICE="https://guides.dataverse.org/en/$DATAVERSE_VERSION/_downloads/c08a166c96044c52a1a470cc2ff60444/payara.service"
SOLR_SERVICE="https://guides.dataverse.org/en/$DATAVERSE_VERSION/_downloads/0736976a136678bbc024ce423b223d3a/solr.service"
##############################
# Colours
RED='\e[0;31m'
REDB='\e[1;31;5m'
GREEN='\e[1;92m'
YELLOW='\e[1;33m'
NC='\e[0m' # No Color
pre_config(){
echo -e "${YELLOW}Pre config...${NC}"
read_any
if [ ! -d $SCRIPT_DIR ]; then
mkdir $SCRIPT_DIR
yes | cp -rp ~/rocky-dataverse.sh $SCRIPT_DIR
else
yes | cp -rp ~/rocky-dataverse.sh $SCRIPT_DIR
fi
if [[ $BUILD_MAXMIND == "YES" ]]; then
if [ -f ~/$GEOLITE_PACKAGE ]; then
yes | cp -rp ~/$GEOLITE_PACKAGE $SCRIPT_DIR
else
echo -e "${RED}ERROR: $GEOLITE_PACKAGE NOT FOUND in ~/${NC}"
echo -e "${YELLOW}Please create an account and download at:${NC}"
echo -e "${YELLOW}https://dev.maxmind.com/geoip/geolite2-free-geolocation-data?lang=en${NC}"
echo -e "${YELLOW}or set BUILD_MAXMIND var to NO.${NC}"
exit
fi
fi
if [[ $CHANGE_PAYARA_INDEX == "YES" ]]; then
if [ -f ~/index.html ]; then
yes | cp -rp ~/index.html $SCRIPT_DIR
else
echo -e "${RED}ERROR: index.html NOT FOUND in ~/${NC}"
fi
fi
}
download_packages(){
echo -e "${YELLOW}Download all packages...${NC}"
cd $SCRIPT_DIR
if [ ! -f ~/rocky-dataverse/payara-$PAYARA_VERSION.zip ]; then
echo -e "${YELLOW}Download Payara $PAYARA_VERSION...${NC}"
wget -c https://s3-eu-west-1.amazonaws.com/payara.fish/Payara+Downloads/$PAYARA_VERSION/payara-$PAYARA_VERSION.zip
else
cp -rp ~/rocky-dataverse/payara-$PAYARA_VERSION.zip .
fi
if [ ! -f ~/rocky-dataverse/dvinstall.zip ]; then
echo -e "${YELLOW}Download Dataverse $DATAVERSE_VERSION...${NC}"
wget -c https://github.com/IQSS/dataverse/releases/download/v$DATAVERSE_VERSION/dvinstall.zip
else
cp -rp ~/rocky-dataverse/dvinstall.zip .
fi
if [ ! -f ~/rocky-dataverse/solr-$SOLR_VERSION.tgz ]; then
echo -e "${YELLOW}Download Solr $SOLR_VERSION...${NC}"
wget -c https://archive.apache.org/dist/lucene/solr/$SOLR_VERSION/solr-$SOLR_VERSION.tgz
else
cp -rp ~/rocky-dataverse/solr-$SOLR_VERSION.tgz .
fi
}
install_java(){
echo -e "${YELLOW}Install Java $JAVA_VERSION...${NC}"
read_any
dnf install -y java-$JAVA_VERSION-openjdk
alternatives --set java java-$JAVA_VERSION-openjdk.x86_64
}
download_payara(){
echo -e "${YELLOW}Download Payara $PAYARA_VERSION...${NC}"
read_any
useradd dataverse
usermod -aG wheel dataverse
cd $SCRIPT_DIR
wget -c https://s3-eu-west-1.amazonaws.com/payara.fish/Payara+Downloads/$PAYARA_VERSION/payara-$PAYARA_VERSION.zip
unzip payara-$PAYARA_VERSION.zip
mv payara5 /usr/local
}
install_payara(){
echo -e "${YELLOW}Install Payara $PAYARA_VERSION...${NC}"
read_any
chown -R root:root /usr/local/payara5
chown dataverse /usr/local/payara5/glassfish/lib
chown -R dataverse:dataverse /usr/local/payara5/glassfish/domains/domain1
cd /usr/lib/systemd/system/
wget -c $PAYARA_SERVICE
sed -i "/^User=.*/a Group=dataverse" payara.service
echo -e "${GREEN}Start and enable Payara service...${NC}"
systemctl daemon-reload
systemctl enable --now payara.service
rm -rf $SCRIPT_DIR/payara-$PAYARA_VERSION.zip
}
change_index_payara(){
echo -e "${YELLOW}Change Payara's default index page...${NC}"
read_any
# Just to not show payara's default page during dataverse startup
rm -rf /usr/local/payara5/glassfish/domains/domain1/docroot/index.html
cp $SCRIPT_DIR/index.html /usr/local/payara5/glassfish/domains/domain1/docroot/
chown dataverse.dataverse /usr/local/payara5/glassfish/domains/domain1/docroot/index.html
chmod 755 /usr/local/payara5/glassfish/domains/domain1/docroot/index.html
}
install_postgresql(){
echo -e "${YELLOW}Install Postgresql $POSTGRESQL_VERSION...${NC}"
read_any
#dnf module list postgresql
dnf module reset postgresql
dnf module install -y postgresql:$POSTGRESQL_VERSION
postgresql-setup --initdb
systemctl enable --now postgresql
}
configure_postgresql(){
echo -e "${YELLOW}Configure Postgresql $POSTGRESQL_VERSION...${NC}"
read_any
# vim /var/lib/pgsql/data/pg_hba.conf
echo "local all all trust" > /var/lib/pgsql/data/pg_hba.conf
echo "host all all 127.0.0.1/32 trust" >> /var/lib/pgsql/data/pg_hba.conf
echo "host all all ::1/128 trust" >> /var/lib/pgsql/data/pg_hba.conf
echo "local replication all peer" >> /var/lib/pgsql/data/pg_hba.conf
echo "host replication all 127.0.0.1/32 ident" >> /var/lib/pgsql/data/pg_hba.conf
echo "host replication all ::1/128 ident" >> /var/lib/pgsql/data/pg_hba.conf
systemctl restart postgresql
}
download_dataverse(){
echo -e "${YELLOW}Download Dataverse v$DATAVERSE_VERSION...${NC}"
read_any
cd $SCRIPT_DIR
wget -c https://github.com/IQSS/dataverse/releases/download/v$DATAVERSE_VERSION/dvinstall.zip
unzip dvinstall.zip
}
install_solr(){
echo -e "${YELLOW}Install SOLR $SOLR_VERSION...${NC}"
read_any
cd $SCRIPT_DIR
wget -c https://archive.apache.org/dist/lucene/solr/$SOLR_VERSION/solr-$SOLR_VERSION.tgz
useradd solr
usermod -aG wheel solr
mkdir /usr/local/solr
cp $SCRIPT_DIR/solr-$SOLR_VERSION.tgz /usr/local/solr
cd /usr/local/solr
chown solr:solr /usr/local/solr -R
sudo -u solr tar xvzf solr-$SOLR_VERSION.tgz
cd solr-$SOLR_VERSION
sudo -u solr cp -r /usr/local/solr/solr-$SOLR_VERSION/server/solr/configsets/_default server/solr/collection1
sudo -u solr cp $SCRIPT_DIR/dvinstall/schema*.xml /usr/local/solr/solr-$SOLR_VERSION/server/solr/collection1/conf
sudo -u solr cp $SCRIPT_DIR/dvinstall/solrconfig.xml /usr/local/solr/solr-$SOLR_VERSION/server/solr/collection1/conf
echo "solr soft nproc 65000" >> /etc/security/limits.conf
echo "solr hard nproc 65000" >> /etc/security/limits.conf
echo "solr soft nofile 65000" >> /etc/security/limits.conf
echo "solr hard nofile 65000" >> /etc/security/limits.conf
dnf install -y lsof
sudo -u solr echo "name=collection1" > /usr/local/solr/solr-$SOLR_VERSION/server/solr/collection1/core.properties
sudo -u solr sed -i "s/name=\"solr.jetty.request.header.size\" default=\"8192\"/name=\"solr.jetty.request.header.size\" default=\"102400\"/g" /usr/local/solr/solr-$SOLR_VERSION/server/etc/jetty.xml
cd /etc/systemd/system
wget -c $SOLR_SERVICE
sed -i "/^User = .*/a Group = solr" solr.service
systemctl daemon-reload
echo -e "${GREEN}Start and enable SOLR service...${NC}"
systemctl enable --now solr.service
usermod -s /sbin/nologin solr
rm -rf /usr/local/solr/solr-$SOLR_VERSION.tgz
}
install_magick(){
echo -e "${YELLOW}Install ImageMagick...${NC}"
read_any
dnf install -y epel-release
dnf install -y jq
dnf install -y ImageMagick
}
install_r(){
echo -e "${YELLOW}Install R...${NC}"
read_any
dnf config-manager --enable powertools
dnf install -y R-core R-core-devel
mount -o remount,exec /tmp
Rscript -e 'install.packages("R2HTML", repos="https://cloud.r-project.org/", lib="/usr/lib64/R/library")'
Rscript -e 'install.packages("rjson", repos="https://cloud.r-project.org/", lib="/usr/lib64/R/library")'
Rscript -e 'install.packages("DescTools", repos="https://cloud.r-project.org/", lib="/usr/lib64/R/library")'
Rscript -e 'install.packages("Rserve", repos="https://cloud.r-project.org/", lib="/usr/lib64/R/library")'
Rscript -e 'install.packages("haven", repos="https://cloud.r-project.org/", lib="/usr/lib64/R/library")'
mount -o remount,rw,noexec,nosuid,nodev,bind /tmp
cd $SCRIPT_DIR
git clone -b master https://github.com/IQSS/dataverse.git
cd $SCRIPT_DIR/dataverse/scripts/r/rserve
bash rserve-setup.sh
systemctl daemon-reload
systemctl enable --now rserve
}
install_maxmind(){
echo -e "${YELLOW}Install MAXMIND...${NC}"
read_any
cd /usr/local
wget -c https://github.com/CDLUC3/counter-processor/archive/v0.1.04.tar.gz
tar xvfz v0.1.04.tar.gz
cd $SCRIPT_DIR
tar xvfz $GEOLITE_PACKAGE
cp GeoLite2-Country_*/GeoLite2-Country.mmdb /usr/local/counter-processor-0.1.04/maxmind_geoip
useradd counter
chown -R counter:counter /usr/local/counter-processor-0.1.04
dnf install -y python39
python3.9 -m ensurepip
cd /usr/local/counter-processor-0.1.04
sed -i "s/ipython==7.19.0/ipython>=7.16.1/g" requirements.txt
sed -i "s/traitlets==5.0.5/traitlets>=4.3.3/g" requirements.txt
pip3 install -r requirements.txt
}
custom_pages(){
echo -e "${YELLOW}Configure custom pages for DATAVERSE $DATAVERSE_VERSION...${NC}"
read_any
mkdir -p /var/www/dataverse/branding/
cd /var/www/dataverse/branding
wget -c https://guides.dataverse.org/en/latest/_downloads/0f28d7fe1a9937d9ef47ae3f8b51403e/custom-homepage.html
wget -c https://guides.dataverse.org/en/latest/_downloads/4e2c4e359b641142d3b5d34f979248b0/custom-header.html
wget -c https://guides.dataverse.org/en/latest/_downloads/1c9c782c8c0a4b602ad667eb5871203b/custom-footer.html
wget -c https://guides.dataverse.org/en/latest/_downloads/483ea011831fc72d7f1e923a1898f3a3/custom-stylesheet.css
curl -X PUT -d '/var/www/dataverse/branding/custom-homepage.html' http://localhost:8080/api/admin/settings/:HomePageCustomizationFile
curl -X PUT -d '/var/www/dataverse/branding/custom-header.html' http://localhost:8080/api/admin/settings/:HeaderCustomizationFile
curl -X PUT -d 'true' http://localhost:8080/api/admin/settings/:DisableRootDataverseTheme
curl -X PUT -d '/var/www/dataverse/branding/custom-footer.html' http://localhost:8080/api/admin/settings/:FooterCustomizationFile
curl -X PUT -d '/var/www/dataverse/branding/custom-stylesheet.css' http://localhost:8080/api/admin/settings/:StyleCustomizationFile
}
install_dataverse(){
echo -e "${YELLOW}Install DATAVERSE $DATAVERSE_VERSION...${NC}"
read_any
cd $SCRIPT_DIR/dvinstall/
dnf install -y python3-psycopg2
sudo -u dataverse python3 install.py
# como root
cd $SCRIPT_DIR/dvinstall/
bash setup-all.sh
chown root /usr/local/payara5/glassfish/lib
}
configure_fake_doi(){
# https://brapci.inf.br/wiki/index.php/Dataverse:DOI
echo -e "${YELLOW}Configure FAKE DOI for tests...\n${NC}"
read_any
curl -X PUT -d FAKE http://localhost:8080/api/admin/settings/:DoiProvider
}
configure_regular_doi(){
# https://brapci.inf.br/wiki/index.php/Dataverse:DOI
# https://guides.dataverse.org/en/5327-fake-pid-provider/installation/config.html#id106
echo -e "${YELLOW}Configure Regular DOI...\n${NC}"
read_any
sed -i "s/Ddoi.username=dataciteuser/Ddoi.username=$DOI_USERNAME/g" /usr/local/payara5/glassfish/domains/domain1/config/domain.xml
sed -i "s/Ddoi.password=\${ALIAS=doi_password_alias}/Ddoi.password=$DOI_PASSWD/g" /usr/local/payara5/glassfish/domains/domain1/config/domain.xml
curl -X PUT -d "$DOI_PREFIX" localhost:8080/api/admin/settings/:Authority
curl -X PUT -d DataCite http://localhost:8080/api/admin/settings/:DoiProvider
}
configure_dataverse(){
echo -e "${YELLOW}Configure DATAVERSE $DATAVERSE_VERSION for tests...\n${NC}"
read_any
if [[ $USE_FAKE_DOI == "YES" ]]; then
configure_fake_doi
else
configure_regular_doi
fi
curl -X PUT -d "$PROJECT_NAME <$EMAIL>" http://localhost:8080/api/admin/settings/:SystemEmail
curl -X PUT -d ", $INSTITUTE" http://localhost:8080/api/admin/settings/:FooterCopyright
}
configure_email(){
echo -e "${YELLOW}Configure e-mail...${NC}"
read_any
cd /usr/local/payara5/bin
./asadmin delete-javamail-resource mail/notifyMailSession
./asadmin create-javamail-resource --mailhost $MAIL_HOST \
--mailuser $MAIL_USER \
--fromaddress $FROM_ADDRESS \
--property mail.smtp.auth=false:mail.smtp.password=passwd:mail.smtp.port=587:mail.smtp.socketFactory.port=javax.net.ssl.SSLSocketFactory \
mail/notifyMailSession
}
configure_selinux(){
echo -e "${YELLOW}Enable AVC rules in SELinux for Apache and NGINX...${NC}"
read_any
setsebool -P httpd_can_network_connect 1
setsebool -P httpd_can_network_relay 1
setsebool -P httpd_run_stickshift 1
setsebool -P httpd_setrlimit 1
}
security(){
# Restore Postgresql security
sed -i '2s/trust/md5/' /var/lib/pgsql/data/pg_hba.conf
# enable the following setting to address CVE-2021-44228
#echo "SOLR_OPTS=\"\$SOLR_OPTS -Dlog4j2.formatMsgNoLookups=true\"" >> /usr/local/solr/$SOLR_VERSION/bin/solr.in.sh
}
read_any(){
if [[ $PAUSE_SETUP == "YES" ]]; then
read -n 1 -s -r -p "Press any key to continue..."$'\n' msg
fi
}
main(){
echo -e "${REDB}\n\nINSTALL DATAVERSE v$DATAVERSE_VERSION ${NC}"
if [[ $EUID -ne 0 ]]; then
echo -e "${REDB}ERROR: Run the script as ROOT!\n${NC}"
exit
else
pre_config
download_packages
install_java
download_payara
install_payara
install_postgresql
configure_postgresql
download_dataverse
install_solr
if [[ $BUILD_IMAGEMAGICK == "YES" ]]; then
install_magick
fi
if [[ $BUILD_R == "YES" ]]; then
install_r
fi
if [[ $BUILD_MAXMIND == "YES" ]]; then
install_maxmind
fi
install_dataverse
configure_dataverse
if [[ $SEND_EMAIL == "YES" ]]; then
configure_email
fi
configure_selinux
if [[ $CHANGE_PAYARA_INDEX == "YES" ]]; then
change_index_payara
fi
if [[ $CUSTOM_PAGES == "YES" ]]; then
custom_pages
fi
#security
echo -e "${REDB}\n\nPOST INSTALL TIPS${NC}"
echo " "
echo -e "${GREEN}RECOMENDED: Check SELinux rules with audit2allow -a${NC}"
echo -e "${GREEN}Create test modules with \"audit2allow -a -M module_name\"${NC}"
echo -e "${GREEN}Install modules with \"semodule -i module_name.te\"${NC}"
echo -e "${GREEN}Enable with \"semodule -e module_name\"${NC}"
fi
}
main