-
Notifications
You must be signed in to change notification settings - Fork 10
/
invenio-setup-environment
executable file
·206 lines (186 loc) · 6.76 KB
/
invenio-setup-environment
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
#!/bin/bash
#
# A helper devscript to set up Invenio development environment.
# (Alters bashrc, sets up /opt/invenio, sets up Python invenio
# symlinks.) For more information, see
# <https://github.com/tiborsimko/invenio-devscripts>.
#
# Tibor Simko <[email protected]>
#
# Copyright (C) 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/>.
# sanity check: CLI confirmation
if [ "$1" != "--yes-i-know" ]; then
echo "[ERROR] You did not use --yes-i-know. Not going to set up Invenio development environment."
exit 1
fi
# sanity check: environment variables
if [ -z "$CFG_INVENIO_SRCDIR" ]; then
echo "[ERROR] CFG_INVENIO_SRCDIR not set up. Maybe you want to run invenio-kickstart? Exiting."
exit 1
fi
if [ -z "$CFG_INVENIO_PORT_HTTP" ]; then
echo "[ERROR] CFG_INVENIO_PORT_HTTP not set up. Maybe you want to run invenio-kickstart? Exiting."
exit 1
fi
if [ -z "$CFG_INVENIO_PORT_HTTPS" ]; then
echo "[ERROR] CFG_INVENIO_PORT_HTTPS not set up. Maybe you want to run invenio-kickstart? Exiting."
exit 1
fi
# quit on errors and potentially unbound symbols:
set -o errexit
set -o nounset
## show command execution:
#set -o xtrace
os_unknown () {
echo "[ERROR] Cannot detect OS version."
echo "[ERROR] Please contact authors. Exiting."
exit 1
}
common_configure_home () {
if ! grep -q PATH=.*invenio-devscripts $HOME/.bashrc; then
echo "export PATH=${CFG_INVENIO_SRCDIR}-devscripts:\$PATH" >> $HOME/.bashrc
fi
if ! grep -q CFG_INVENIO_SRCDIR $HOME/.bashrc; then
echo "export CFG_INVENIO_SRCDIR=$CFG_INVENIO_SRCDIR" >> $HOME/.bashrc
fi
if ! grep -q CFG_INVENIO_PORT_HTTP $HOME/.bashrc; then
echo "export CFG_INVENIO_PORT_HTTP=$CFG_INVENIO_PORT_HTTP" >> $HOME/.bashrc
fi
if ! grep -q CFG_INVENIO_PORT_HTTPS $HOME/.bashrc; then
echo "export CFG_INVENIO_PORT_HTTPS=$CFG_INVENIO_PORT_HTTPS" >> $HOME/.bashrc
fi
if ! grep -q CFG_INVENIO_HOSTNAME $HOME/.bashrc; then
echo "export CFG_INVENIO_HOSTNAME=`hostname -s`" >> $HOME/.bashrc
fi
if ! grep -q CFG_INVENIO_DOMAINNAME $HOME/.bashrc; then
if [ $(uname -s) = "FreeBSD" ]; then
# FreeBSD does not have "hostname -d" option, so use awk:
thishostname=$(hostname -f | awk '{print substr($0, index($0,".")+1)}')
else
# GNU/Linux can use "hostname -d":
thishostname=`hostname -d`
fi
if [ -z $thishostname ]; then
thishostname="localdomain"
fi
echo "export CFG_INVENIO_DOMAINNAME=$thishostname" >> $HOME/.bashrc
fi
if ! grep -q CFG_INVENIO_ADMIN $HOME/.bashrc; then
echo "export CFG_INVENIO_ADMIN=`whoami`@localhost" >> $HOME/.bashrc
fi
chmod go+rx $CFG_INVENIO_SRCDIR # so that sudo -u www-data make install would work later
}
redhat_configure_home () {
common_configure_home
if ! grep -q CFG_INVENIO_USER $HOME/.bashrc; then
echo "export CFG_INVENIO_USER=apache" >> $HOME/.bashrc
fi
if ! grep -q CFG_INVENIO_APACHECTL $HOME/.bashrc; then
echo "export CFG_INVENIO_APACHECTL=/etc/init.d/httpd" >> $HOME/.bashrc
fi
if ! grep -q CFG_INVENIO_MYSQLCTL $HOME/.bashrc; then
echo "export CFG_INVENIO_MYSQLCTL=/etc/init.d/mysqld" >> $HOME/.bashrc
fi
}
debian_configure_home () {
common_configure_home
if ! grep -q CFG_INVENIO_USER $HOME/.bashrc; then
echo "export CFG_INVENIO_USER=www-data" >> $HOME/.bashrc
fi
if ! grep -q CFG_INVENIO_APACHECTL $HOME/.bashrc; then
echo "export CFG_INVENIO_APACHECTL=/etc/init.d/apache2" >> $HOME/.bashrc
fi
if ! grep -q CFG_INVENIO_MYSQLCTL $HOME/.bashrc; then
echo "export CFG_INVENIO_MYSQLCTL=/etc/init.d/mysql" >> $HOME/.bashrc
fi
}
freebsd_configure_home () {
common_configure_home
if ! grep -q CFG_INVENIO_USER $HOME/.bashrc; then
echo "export CFG_INVENIO_USER=www" >> $HOME/.bashrc
fi
if ! grep -q CFG_INVENIO_APACHECTL $HOME/.bashrc; then
echo "export CFG_INVENIO_APACHECTL=/usr/local/etc/rc.d/apache22" >> $HOME/.bashrc
fi
if ! grep -q CFG_INVENIO_MYSQLCTL $HOME/.bashrc; then
echo "export CFG_INVENIO_MYSQLCTL=/usr/local/etc/rc.d/mysql-server" >> $HOME/.bashrc
fi
}
redhat_configure_opt () {
# apache user is not installed yet at this moment, so we shall use
# root; later after installing apache we'll fix the rights
sudo chgrp root /opt
sudo chmod g+w /opt
sudo mkdir -p /opt/invenio
sudo chown -R root.root /opt/invenio
}
debian_configure_opt () {
sudo chgrp www-data /opt
sudo chmod g+w /opt
sudo mkdir -p /opt/invenio
sudo chown -R www-data.www-data /opt/invenio
}
freebsd_configure_opt () {
sudo mkdir -p /opt
sudo chgrp www /opt
sudo chmod g+w /opt
sudo mkdir -p /opt/invenio
sudo chown -R www:www /opt/invenio
}
common_configure_symlinks () {
for pythonversion in python2.4 python2.6 python2.7; do
for libversion in lib lib64 local/lib local/lib64; do
for packageversion in site-packages dist-packages; do
if [ -d /usr/$libversion/$pythonversion/$packageversion/ ] && [ ! -L /usr/$libversion/$pythonversion/$packageversion/invenio ]; then
sudo ln -s /opt/invenio/lib/python/invenio /usr/$libversion/$pythonversion/$packageversion/invenio
fi
done
done
done
}
redhat_configure_symlinks () {
sudo -u root mkdir -p /opt/invenio/lib/python/invenio
common_configure_symlinks
}
debian_configure_symlinks () {
sudo -u www-data mkdir -p /opt/invenio/lib/python/invenio
common_configure_symlinks
}
freebsd_configure_symlinks () {
sudo -u www mkdir -p /opt/invenio/lib/python/invenio
common_configure_symlinks
}
main () {
if [ -e /etc/redhat-release ]; then
redhat_configure_home
redhat_configure_opt
redhat_configure_symlinks
elif [ -e /etc/debian_version ]; then
debian_configure_home
debian_configure_opt
debian_configure_symlinks
elif [ $(uname -s) = "FreeBSD" ]; then
freebsd_configure_home
freebsd_configure_opt
freebsd_configure_symlinks
else
os_unknown
fi
}
echo "[INFO] $0 started."
main
echo "[INFO] $0 finished."
# end of file