-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathinvenio2-kickstart
executable file
·297 lines (259 loc) · 10.6 KB
/
invenio2-kickstart
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
#!/usr/bin/env bash
#
# >>> About
#
# This helper devscript installs Invenio 2.0 development environment
# on a fresh (virtual) machine in a fully automated, unassisted way.
#
# Tested on: CentOS 6 x86_64
# Ubuntu 14.04 LTS (Trusty Tahr) amd64
#
# For more information, see "Usage" section below as well as
# <https://github.com/tiborsimko/invenio-devscripts>.
#
# >>> Copyright
#
# Tibor Simko <[email protected]>
#
# Copyright (C) 2014 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/>.
#
# >>> Usage
#
# First, start a new VM like this:
#
# laptop> mkdir -p ~/private/vm/invenio2trusty64
# laptop> cd ~/private/vm/invenio2trusty64
# laptop> vim Vagrantfile # enter following content:
# Vagrant.configure("2") do |config|
# config.vm.box = "trusty64"
# config.vm.box_url = "http://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box"
# config.vm.hostname = 'localhost.localdomain'
# config.vm.network :forwarded_port, host: 8080, guest: 8080
# config.vm.network :forwarded_port, host: 8443, guest: 8443
# config.vm.provider :virtualbox do |vb|
# vb.customize ["modifyvm", :id, "--memory", "2048"]
# vb.customize ["modifyvm", :id, "--cpus", 2]
# end
# end
# laptop> vagrant up
#
# Second, connect to VM and launch kickstarter:
#
# laptop> vagrant ssh
# vm> wget https://raw.githubusercontent.com/tiborsimko/invenio-devscripts/master/invenio2-kickstart
# vm> chmod u+x ./invenio2-kickstart
# vm> ./invenio2-kickstart --yes-i-know --yes-i-really-know
#
# Third, go brew some tee, come back in twenty minutes, enjoy!
#
# laptop> firefox http://0.0.0.0:8080/
#
# >>> Configuration
#
# It is not necessary to set any particular configuration parameters;
# the default values (displayed below) should suit typical use case.
# If you want to change some variables, just set them before launching
# this script, for example:
#
# CFG_INVENIO2_FOO=foo1 CFG_INVENIO2_BAR=bar3 ./invenio-kickstart
#
# Howgh!
# configuration:
CFG_INVENIO2_REPOSITORY_GENERAL=${CFG_INVENIO2_REPOSITORY_GENERAL:=git://github.com/inveniosoftware/invenio}
CFG_INVENIO2_REPOSITORY_GENERAL_BRANCH=${CFG_INVENIO2_REPOSITORY_GENERAL_BRANCH:=pu}
CFG_INVENIO2_REPOSITORY_OVERLAY=${CFG_INVENIO2_REPOSITORY_OVERLAY:=git://github.com/inveniosoftware/invenio-demosite}
CFG_INVENIO2_REPOSITORY_OVERLAY_BRANCH=${CFG_INVENIO2_REPOSITORY_OVERLAY_BRANCH:=pu}
CFG_INVENIO2_SITE_URL=${CFG_INVENIO2_SITE_URL:=http://0.0.0.0:8080}
CFG_INVENIO2_SITE_SECURE_URL=${CFG_INVENIO2_SITE_SECURE_URL:=http://0.0.0.0:8080}
CFG_INVENIO2_VIRTUAL_ENV=${CFG_INVENIO2_VIRTUAL_ENV:=invenio2}
CFG_INVENIO2_DATABASE_USER=${CFG_INVENIO2_DATABASE_USER:=invenio2}
CFG_INVENIO2_DATABASE_NAME=${CFG_INVENIO2_DATABASE_NAME:=invenio2}
CFG_INVENIO2_DEMOSITE_POPULATE_BEFORE=${CFG_INVENIO2_DEMOSITE_POPULATE_BEFORE:=}
CFG_INVENIO2_DEMOSITE_POPULATE=${CFG_INVENIO2_DEMOSITE_POPULATE:=}
# sanity check: CLI confirmation
if [[ "$@" != *"--yes-i-know"* ]]; then
echo "[ERROR] You did not use --yes-i-know. Not going to kickstart Invenio on this machine."
exit 1
fi
if [[ "$@" != *"--yes-i-really-know"* ]]; then
echo "[ERROR] You did not use --yes-i-really-know. Not going to kickstart Invenio on this machine."
exit 1
fi
# quit on errors and potentially unbound symbols:
## (unfortunately cannot use due to virtualenvwrapper)
## set -o errexit
## set -o nounset
configure_iptables () {
# open HTTP and HTTPS ports in the firewall:
if [ -e /sbin/iptables ]; then
thisinputchain="INPUT"
if sudo /sbin/iptables -nL | grep -q 'Chain RH-Firewall-1-INPUT'; then
thisinputchain="RH-Firewall-1-INPUT"
fi
httpport=$(echo ${CFG_INVENIO2_SITE_URL} | cut -d: -f 3)
httpsport=$(echo ${CFG_INVENIO2_SITE_SECURE_URL} | cut -d: -f 3)
if [ -n $httpport ]; then
if ! sudo /sbin/iptables -nL | grep -q dpt:$httpport; then
sudo /sbin/iptables -I $thisinputchain -p tcp -m tcp --dport $httpport -j ACCEPT
sudo /sbin/iptables -I OUTPUT -p tcp -m tcp --dport $httpport -j ACCEPT
fi
fi
if [ -n $httpsport ]; then
if ! sudo /sbin/iptables -nL | grep -q dpt:$httpsport; then
sudo /sbin/iptables -I $thisinputchain -p tcp -m tcp --dport $httpsport -j ACCEPT
sudo /sbin/iptables -I OUTPUT -p tcp -m tcp --dport $httpsport -j ACCEPT
fi
fi
fi
}
setup_ubuntu_trusty () {
# install initial batch of prerequisites:
sudo DEBIAN_FRONTEND=noninteractive apt-get -y update
sudo DEBIAN_FRONTEND=noninteractive apt-get -y install git vim screen
sudo DEBIAN_FRONTEND=noninteractive apt-get -y install \
build-essential git redis-server \
libmysqlclient-dev libxml2-dev libxslt-dev \
libjpeg-dev libfreetype6-dev libtiff-dev \
software-properties-common python-dev \
virtualenvwrapper subversion libffi-dev \
libssl-dev
sudo pip install -U virtualenvwrapper pip
source $(which virtualenvwrapper.sh)
# install MySQL:
sudo DEBIAN_FRONTEND=noninteractive apt-get -y install mysql-server
# install nodejs:
sudo apt-get -y install python-software-properties
sudo add-apt-repository -y ppa:chris-lea/node.js
sudo apt-get -y update
sudo apt-get -y install nodejs
# install bower globally:
sudo su -c "npm install -g bower"
}
setup_centos6 () {
# install initial batch of prerequisites:
sudo yum update -y
sudo yum groupinstall -y "Development Tools"
(cd /tmp && wget http://download.fedoraproject.org/pub/epel/6/$(uname -m)/epel-release-6-8.noarch.rpm)
sudo rpm -ivh /tmp/epel-release-6-8.noarch.rpm
sudo yum install -y git wget redis python-devel \
mysql-devel libxml2-devel libxslt-devel \
python-pip python-virtualenvwrapper subversion \
libffi-devel openssl-devel
sudo pip install -U virtualenvwrapper pip
source $(which virtualenvwrapper.sh)
# install MySQL:
sudo yum install -y mysql-server
sudo /sbin/service mysqld start
sudo /sbin/chkconfig mysqld on
mysqladmin -u root password ''
# install nodejs:
sudo yum install -y npm
# install bower globally:
sudo su -c "npm install -g bower"
# configure iptables:
configure_iptables
}
install_invenio () {
# create virtual environment:
mkvirtualenv $CFG_INVENIO2_VIRTUAL_ENV
cdvirtualenv
# clone there Invenio and its demo site overlay:
mkdir src
cd src
git clone -b $CFG_INVENIO2_REPOSITORY_GENERAL_BRANCH $CFG_INVENIO2_REPOSITORY_GENERAL
git clone -b $CFG_INVENIO2_REPOSITORY_OVERLAY_BRANCH $CFG_INVENIO2_REPOSITORY_OVERLAY
# install ipython
pip install ipython
# install Invenio requirements:
cdvirtualenv src/invenio
pip install --process-dependency-links -e .[development,docs]
# compile I18N PO catalogue:
python setup.py compile_catalog
# install Invenio demo site overlay:
cdvirtualenv src/$(basename ${CFG_INVENIO2_REPOSITORY_OVERLAY})
overlaypackage=$(dirname $(ls */config.py))
pip install -r requirements.txt --exists-action i
# compile overlay I18N PO catalogue:
python setup.py compile_catalog
# install JS/CSS assets using bower:
inveniomanage bower -i bower-base.json > bower.json
CI=true bower install
# create secret key for your installation:
inveniomanage config create secret-key
# set configuration variables suitable for local (VM) developments:
inveniomanage config set CFG_EMAIL_BACKEND flask.ext.email.backends.console.Mail
inveniomanage config set CFG_BIBSCHED_PROCESS_USER $USER
inveniomanage config set CFG_DATABASE_NAME $CFG_INVENIO2_DATABASE_NAME
inveniomanage config set CFG_DATABASE_USER $CFG_INVENIO2_DATABASE_USER
inveniomanage config set CFG_SITE_URL $CFG_INVENIO2_SITE_URL
inveniomanage config set CFG_SITE_SECURE_URL $CFG_INVENIO2_SITE_SECURE_URL
# install JS/CSS asset filters:
sudo su -c "npm install -g less clean-css requirejs uglify-js"
# collect JS/CSS assets into your instance directory:
inveniomanage config set COLLECT_STORAGE invenio.ext.collect.storage.link
inveniomanage collect
# create database:
inveniomanage database init --user=root --yes-i-know
inveniomanage database create
# build documentation:
inveniomanage documentation build
# install honcho to run development celery/redis/web servers:
cdvirtualenv src/invenio
pip install honcho flower
honcho start &
# populate your site with demo records:
cdvirtualenv src/$(basename ${CFG_INVENIO2_REPOSITORY_OVERLAY})
if [ "${CFG_INVENIO2_DEMOSITE_POPULATE_BEFORE}" != "" ]; then
eval ${CFG_INVENIO2_DEMOSITE_POPULATE_BEFORE}
fi
inveniomanage demosite populate --packages=${overlaypackage}.base ${CFG_INVENIO2_DEMOSITE_POPULATE} --yes-i-know
}
main () {
# detect OS and call appropriate setup functions:
if hash lsb_release 2> /dev/null; then
os_distribution=$(lsb_release -i | cut -f 2)
os_release=$(lsb_release -r | cut -f 2)
elif [ -e /etc/redhat-release ]; then
os_distribution=$(cat /etc/redhat-release | cut -d ' ' -f 1)
os_release=$(cat /etc/redhat-release | grep -oE '[0-9]+\.' | cut -d. -f1)
else
os_distribution="UNDETECTED"
os_release="UNDETECTED"
fi
if [ "$os_distribution" = "Ubuntu" ]; then
if [ "$os_release" = "14.04" ]; then
setup_ubuntu_trusty
install_invenio
else
echo "[ERROR] Sorry, unsupported release ${os_release}."
echo "[ERROR] Please contact authors. Exiting."
fi
elif [ "$os_distribution" = "CentOS" ]; then
if [ "$os_release" = "6" ]; then
setup_centos6
install_invenio
else
echo "[ERROR] Sorry, unsupported release ${os_release}."
echo "[ERROR] Please contact authors. Exiting."
fi
else
echo "[ERROR] Sorry, unsupported distribution ${os_distribution}."
echo "[ERROR] Please contact authors. Exiting."
exit 1;
fi
}
main
# end of file