forked from tiborsimko/invenio-devscripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
invenio-recreate-demo-site
executable file
·191 lines (166 loc) · 7.37 KB
/
invenio-recreate-demo-site
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
#!/bin/sh
#
# A helper devscript to recreate Invenio demo site. Assumes an
# already running Invenio instance on the box, and certain sudo
# rights. For more information, see
# <https://github.com/tiborsimko/invenio-devscripts>.
#
# Tibor Simko <[email protected]>
#
# Copyright (C) 2011, 2012, 2013 CERN.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
# config section:
CFG_INVENIO_SRCDIR=${CFG_INVENIO_SRCDIR:=~/private/src/invenio}
CFG_INVENIO_PREFIX=${CFG_INVENIO_PREFIX:=/opt/invenio}
CFG_INVENIO_HOSTNAME=${CFG_INVENIO_HOSTNAME:=pcuds07}
CFG_INVENIO_DOMAINNAME=${CFG_INVENIO_DOMAINNAME:=cern.ch}
CFG_INVENIO_PORT_HTTP=${CFG_INVENIO_PORT_HTTP:=80}
CFG_INVENIO_PORT_HTTPS=${CFG_INVENIO_PORT_HTTPS:=443}
CFG_INVENIO_USER=${CFG_INVENIO_USER:=www-data}
CFG_INVENIO_ADMIN=${CFG_INVENIO_ADMIN:[email protected]}
CFG_INVENIO_DATABASE_NAME=${CFG_INVENIO_DATABASE_NAME:=invenio}
CFG_INVENIO_DATABASE_USER=${CFG_INVENIO_DATABASE_USER:=invenio}
CFG_INVENIO_APACHECTL=${CFG_INVENIO_APACHECTL:=/etc/init.d/apache2}
CFG_INVENIO_MYSQLCTL=${CFG_INVENIO_MYSQLCTL:=/etc/init.d/mysql}
# sanity check: CLI confirmation
if [ "$1" != "--yes-i-know" ]; then
echo "[ERROR] You did not use --yes-i-know. Not going to recreate Invenio demo site."
exit
fi
# quit on errors and potentially unbound symbols:
set -o errexit
set -o nounset
# sanity check: hostname
if [ "`hostname`" != "$CFG_INVENIO_HOSTNAME" ]; then
echo "[ERROR] This hostname is not whitelisted for recreating the demo site."
exit
fi
# give user a chance to quit:
echo "[INFO] GOING TO RECREATE YOUR INVENIO DEMO SITE IN 5 SECONDS!"
echo -n "[INFO] THIS IS YOUR LAST CHANCE TO INTERRUPT BY PRESSING Ctrl-C! "
for i in 0 1 2 3 4; do
echo -n "."
sleep 1
done
echo
# wipe out existing installation place:
sudo rm -rf $CFG_INVENIO_PREFIX/var/tmp/ooffice-tmp-files
sudo -u $CFG_INVENIO_USER rm -rf $CFG_INVENIO_PREFIX/*
# install Invenio sources:
cd $CFG_INVENIO_SRCDIR
rm -rf autom4te.cache/
aclocal
automake -a
autoconf
./configure --prefix=$CFG_INVENIO_PREFIX
make -s
sudo -u $CFG_INVENIO_USER make -s install
sudo -u $CFG_INVENIO_USER make -s install-jquery-plugins
sudo -u $CFG_INVENIO_USER make -s install-mathjax-plugin
sudo -u $CFG_INVENIO_USER make -s install-ckeditor-plugin
sudo -u $CFG_INVENIO_USER make -s install-pdfa-helper-files
# if applicable, install also Twitter Bootstrap (for 'next' branch):
if grep -q install-bootstrap INSTALL; then
sudo -u $CFG_INVENIO_USER make -s install-bootstrap
fi
# if applicable, install also jQuery Tokeninput (for 'next' branch):
if grep -q install-jquery-tokeninput INSTALL; then
sudo -u $CFG_INVENIO_USER make -s install-jquery-tokeninput
fi
# if applicable, install also Plupload (for 'next' branch):
if grep -q install-plupload-plugin INSTALL; then
sudo -u $CFG_INVENIO_USER make -s install-plupload-plugin
fi
# if applicable, install also Hogan (for 'next' branch):
if grep -q install-hogan-plugin INSTALL; then
sudo -u $CFG_INVENIO_USER make -s install-hogan-plugin
fi
# make special sudo powered place for LibreOffice:
sudo mkdir -p $CFG_INVENIO_PREFIX/var/tmp/ooffice-tmp-files
sudo chown -R nobody $CFG_INVENIO_PREFIX/var/tmp/ooffice-tmp-files
sudo chmod -R 755 $CFG_INVENIO_PREFIX/var/tmp/ooffice-tmp-files
# set up invenio-local.conf:
siteurl=${CFG_INVENIO_HOSTNAME}
if [ "${CFG_INVENIO_DOMAINNAME}" = "localhost" ]; then
siteurl="localhost"
else
siteurl=${siteurl}.${CFG_INVENIO_DOMAINNAME}
fi
sitesecureurl=${siteurl}
if [ "${CFG_INVENIO_PORT_HTTP}" != "80" ]; then
siteurl=${siteurl}:${CFG_INVENIO_PORT_HTTP}
fi
if [ "${CFG_INVENIO_PORT_HTTPS}" != "443" ]; then
sitesecureurl=${sitesecureurl}:${CFG_INVENIO_PORT_HTTPS}
fi
echo "[Invenio]
CFG_SITE_URL = http://${siteurl}
CFG_SITE_SECURE_URL = https://${sitesecureurl}
CFG_DATABASE_NAME = ${CFG_INVENIO_DATABASE_NAME}
CFG_DATABASE_USER = ${CFG_INVENIO_DATABASE_USER}
CFG_SITE_ADMIN_EMAIL = ${CFG_INVENIO_ADMIN}
CFG_SITE_SUPPORT_EMAIL = ${CFG_INVENIO_ADMIN}
CFG_WEBALERT_ALERT_ENGINE_EMAIL = ${CFG_INVENIO_ADMIN}
CFG_WEBCOMMENT_ALERT_ENGINE_EMAIL = ${CFG_INVENIO_ADMIN}
CFG_WEBCOMMENT_DEFAULT_MODERATOR = ${CFG_INVENIO_ADMIN}
CFG_BIBAUTHORID_AUTHOR_TICKET_ADMIN_EMAIL = ${CFG_INVENIO_ADMIN}
CFG_BIBCATALOG_SYSTEM_EMAIL_ADDRESS = ${CFG_INVENIO_ADMIN}
CFG_BIBSCHED_PROCESS_USER = ${CFG_INVENIO_USER}" | \
sudo -u $CFG_INVENIO_USER tee $CFG_INVENIO_PREFIX/etc/invenio-local.conf
# if applicable, create secret key:
if grep -q create-secret-key INSTALL; then
sudo -u $CFG_INVENIO_USER $CFG_INVENIO_PREFIX/bin/inveniocfg --update-all
sudo -u $CFG_INVENIO_USER $CFG_INVENIO_PREFIX/bin/inveniocfg --create-secret-key
# FIXME: the following line is a hack that was needed to overcome
# certain virtualenv confusion at times. The confusion was
# leading to a situation where it was not possible to import
# generated CFG_SITE_SECRET_KEY later; the system still saw the
# old empty key value. The line below deletes corresponding pyc
# file which solves the problem in a workaround way until the
# issue is fully debugged. Ugly, but works, and does not harm
# anything.
sudo -u $CFG_INVENIO_USER rm -f $CFG_INVENIO_PREFIX/lib/python/invenio/config.pyc
fi
# update Invenio with this information:
sudo -u $CFG_INVENIO_USER $CFG_INVENIO_PREFIX/bin/inveniocfg --update-all
# MySQL-5.5 hack: before dropping and recreating tables, let's stop
# Apache and let's restart MySQL to free any DB connections we may
# have. This helps in case we are running MySQL-5.5 where otherwise
# we could get into "Waiting for table metadata lock" situations due
# to other existing DB sessions.
sudo $CFG_INVENIO_APACHECTL stop
sudo $CFG_INVENIO_MYSQLCTL restart
# MySQL-5.5 hack: also, let's drop tables here in the shell, rather
# than from within inveniocfg, where MySQLdb may open new sessions
# that may lead to autocommit and metadata lock issues.
$CFG_INVENIO_PREFIX/bin/dbexec < $CFG_INVENIO_PREFIX/lib/sql/invenio/tabdrop.sql
# drop and recreate tables and Atlantis demo site:
sudo -u $CFG_INVENIO_USER $CFG_INVENIO_PREFIX/bin/inveniocfg --create-tables --yes-i-know
# if needed, load BibField configuration (useful for `next' branch):
if grep -q load-bibfield-conf INSTALL; then
sudo -u $CFG_INVENIO_USER $CFG_INVENIO_PREFIX/bin/inveniocfg --load-bibfield-conf
fi
# update Apache configuration now: (this needs to be done after table
# creation in the next branch)
sudo -u $CFG_INVENIO_USER $CFG_INVENIO_PREFIX/bin/inveniocfg --create-apache-conf
# create demo site
sudo -u $CFG_INVENIO_USER $CFG_INVENIO_PREFIX/bin/inveniocfg --create-demo-site --yes-i-know
# MySQL-5.5 hack: restart Apache back:
sudo $CFG_INVENIO_APACHECTL start
# load Atlantis demo records:
sudo -u $CFG_INVENIO_USER $CFG_INVENIO_PREFIX/bin/inveniocfg --load-demo-records --yes-i-know
# restart Invenio WSGI app:
sudo -u $CFG_INVENIO_USER touch $CFG_INVENIO_PREFIX/var/www-wsgi/invenio.wsgi
echo "[INFO] Done."