2 # -----------------------------------------------------------------------
3 # Copyright (C) 2009-2012 Equinox Software Inc.
4 # Bill Erickson <berick@esilibrary.com>
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 # -----------------------------------------------------------------------
17 while getopts ayst option
23 s) SAMPLEDATA=--load-all-sample;;
33 setting_up_opensrf_env
38 setting_ldconfig_and_rsyslog_and_hosts_and_ejabberd
47 if [ $AUTOSTART ]; then
53 function init_variables {
54 echo _.-~= initializing installer
55 # -----------------------------------------------------------------------
56 # Handling passed arguments to the script
57 # -----------------------------------------------------------------------
58 export DOJO_VERSION='1.3.3';
59 export PATH=/openils/bin:$PATH
60 export LD_LIBRARY_PATH=/openils/lib:/usr/local/lib:/usr/local/lib/dbd:$LD_LIBRARY_PATH
62 echo AUTOSTART=${AUTOSTART}
64 echo SAMPLEDATA=${SAMPLEDATA}
65 echo LIVETEST=${LIVETEST}
66 echo DOJO_VERSION=${DOJO_VERSION}
68 echo LD_LIBRARY_PATH=${LD_LIBRARY_PATH}
69 echo BASE_DIR=${BASE_DIR}
70 # -----------------------------------------------------------------------
72 # -----------------------------------------------------------------------
73 # If you change the jabber password, you will need to
74 # edit opensrf_core.xml and srfsh.xml accordingly
75 export JABBER_PASSWORD='password'
76 export ADMIN_USER='admin';
77 export ADMIN_PASS='demo123';
78 # -----------------------------------------------------------------------
79 # You can override these like so:
80 # EVERGREEN_BRANCH='master' ./eg_wheezy_installer.sh
81 # -----------------------------------------------------------------------
82 OPENSRF_REPO='git://git.evergreen-ils.org/OpenSRF.git'
83 OPENSRF_BRANCH='master'
84 EVERGREEN_REPO='git://git.evergreen-ils.org/Evergreen.git'
85 EVERGREEN_BRANCH='master'
86 echo OPENSRF_REPO=${OPENSRF_REPO}
87 echo OPENSRF_BRANCH=${OPENSRF_BRANCH}
88 echo EVERGREEN_REPO=${EVERGREEN_REPO}
89 echo EVERGREEN_BRANCH=${EVERGREEN_BRANCH}
90 OPENSRF_PREREQ_TARGET=debian-wheezy
91 EVERGREEN_PREREQ_TARGET=debian-wheezy
92 EVERGREEN_DB_PREREQ_TARGET=postgres-server-debian-wheezy
93 echo OPENSRF_PREREQ_TARGET=${OPENSRF_PREREQ_TARGET}
94 echo EVERGREEN_PREREQ_TARGET=${EVERGREEN_PREREQ_TARGET}
95 echo EVERGREEN_DB_PREREQ_TARGET=${EVERGREEN_DB_PREREQ_TARGET}
96 echo End of intializing installer =~-._
99 function configure_cpan {
100 echo _.-~= configure CPAN
101 # -----------------------------------------------------------------------
102 # force CPAN to load by installing something that should already be installed
108 echo Return Value = $?
109 # CPAN follow pre-reqs?
110 if [ ! "$(echo 'o conf prerequisites_policy' | cpan | grep follow)" ]; then
113 echo "setting cpan prerequisites_policy to follow"
114 echo -e "o conf prerequisites_policy follow\\n o conf commit" | cpan
120 -----------------------------------------------------------------------
121 The install will go faster if CPAN is configured to automatically install
122 prerequisites. You can revert the action later with:
124 echo -e "o conf prerequisites_policy ask\n o conf commit" | cpan
127 echo -n 'Automatically install prereqs? [Y/n] ';
129 [ "$X" == 'n' -o "$X" == "N" ] && break;
130 if [ "$X" == 'y' -o "$X" == 'Y' ]; then
131 echo -e "o conf prerequisites_policy follow\\n o conf commit" | cpan
137 echo End of configure CPAN =~-._
140 function build_essentials {
141 echo _.-~= Installing some build essentials
142 # Install some essential tools
144 && apt-get -yq dist-upgrade \
145 && apt-get -yq install build-essential automake git psmisc ntp rsyslog;
146 echo Return Value = $?
148 if [ $LIVETEST ]; then
149 cpan TAP::Parser::SourceHandler::pgTAP
150 echo Return Value = $?
152 echo End of Installing some build essentials =~-._
155 function setting_up_opensrf_env {
156 echo _.-~= creating opensrf user and environment
157 # Create opensrf user and set up environment
158 if [ ! "$(grep ^opensrf: /etc/passwd)" ]; then
159 useradd -m -s /bin/bash opensrf
160 echo Return Value = $?
161 echo 'export PATH=/openils/bin:$PATH' >> /home/opensrf/.bashrc
162 echo 'export LD_LIBRARY_PATH=/openils/lib:/usr/local/lib:/usr/local/lib/dbd:$LD_LIBRARY_PATH' >> /home/opensrf/.bashrc
164 echo end of creating opensrf user and environment =~-._
167 function cloning_git_repos {
168 echo _.-~= cloning git repositories
171 git clone --depth 0 --branch $OPENSRF_BRANCH $OPENSRF_REPO OpenSRF;
172 git clone --depth 0 --branch $EVERGREEN_BRANCH $EVERGREEN_REPO Evergreen;
174 rm -rf /home/opensrf/Evergreen /home/opensrf/OpenSRF
175 su - opensrf sh -c "$OSRF_COMMAND";
176 echo Return Value = $?
179 cd /home/opensrf/OpenSRF/
180 echo 'Tip of OpenSRF:' `git log --format=oneline | head -1`
181 cd /home/opensrf/Evergreen/
182 echo 'Tip of Evergreen:' `git log --format=oneline | head -1`
184 echo End of cloning git repositories =~-._
187 function opensrf_prereqs {
188 echo _.-~= Installing OpenSRF pre-requisites
190 mkdir -p /usr/src/evergreen;
191 cd /usr/src/evergreen;
193 yes | make -f /home/opensrf/OpenSRF/src/extras/Makefile.install ${OPENSRF_PREREQ_TARGET}
195 make -f /home/opensrf/OpenSRF/src/extras/Makefile.install ${OPENSRF_PREREQ_TARGET}
197 echo Return Value = $?
198 echo End of Installing OpenSRF pre-requisites =~-._
201 function evergreen_prereqs {
202 echo _.-~= Installing Evergreen pre-requisites
204 yes | make -f /home/opensrf/Evergreen/Open-ILS/src/extras/Makefile.install ${EVERGREEN_PREREQ_TARGET}
206 make -f /home/opensrf/Evergreen/Open-ILS/src/extras/Makefile.install ${EVERGREEN_PREREQ_TARGET}
208 echo Return Value = $?
209 echo End of Installing Evergreen pre-requisites =~-._
212 function evergreen_db_prereqs {
213 echo _.-~= Installing Evergreen database pre-requisites
215 yes | make -f /home/opensrf/Evergreen/Open-ILS/src/extras/Makefile.install ${EVERGREEN_DB_PREREQ_TARGET}
217 make -f /home/opensrf/Evergreen/Open-ILS/src/extras/Makefile.install ${EVERGREEN_DB_PREREQ_TARGET}
219 echo Return Value = $?
220 echo End of Installing Evergreen database pre-requisites =~-._
223 function setting_ldconfig_and_rsyslog_and_hosts_and_ejabberd {
224 echo _.-~= setting ld.so.conf and rsyslog and /etc/hosts and ejabberd
225 cp $BASE_DIR/evergreen.ld.conf /etc/ld.so.conf.d/
227 echo Return Value = $?
228 # Configure rsyslog and restart
229 cp /home/opensrf/Evergreen/Open-ILS/examples/evergreen-rsyslog.conf /etc/rsyslog.d/evergreen.conf
230 /etc/init.d/rsyslog restart
231 echo Return Value = $?
232 if [ ! "$(grep 'public.localhost' /etc/hosts)" ]; then
235 echo 'Adding public.localhost and private.localhost to /etc/hosts'
236 echo '127.0.1.2 public.localhost public' >> /etc/hosts
237 echo '127.0.1.3 private.localhost private' >> /etc/hosts
242 * Add these lines to /etc/hosts.
244 127.0.1.2 public.localhost public
245 127.0.1.3 private.localhost private
251 echo "INFO: /etc/hosts already has public.localhost line";
253 echo Return Value = $?
254 # Patch Ejabberd and register users
255 if [ ! "$(grep 'public.localhost' /etc/ejabberd/ejabberd.cfg)" ]; then
257 /etc/init.d/ejabberd stop;
258 killall beam epmd; # just in case
259 cp ejabberd.cfg /root/ejabberd.cfg.orig
260 patch -p0 < $BASE_DIR/ejabberd.EG.patch
261 chown ejabberd:ejabberd ejabberd.cfg
262 /etc/init.d/ejabberd start
263 echo Return Value = $?
265 ejabberdctl register router private.localhost $JABBER_PASSWORD
266 echo Return Value = $?
267 ejabberdctl register opensrf private.localhost $JABBER_PASSWORD
268 echo Return Value = $?
269 ejabberdctl register router public.localhost $JABBER_PASSWORD
270 echo Return Value = $?
271 ejabberdctl register opensrf public.localhost $JABBER_PASSWORD
272 echo Return Value = $?
274 echo End of setting ld.so.conf and rsyslog and /etc/hosts and ejabberd =~-._
277 function build_opensrf {
278 # Build and install OpenSRF
279 echo _.-~= Building OpenSRF
281 cd /home/opensrf/OpenSRF;
283 ./configure --prefix=/openils --sysconfdir=/openils/conf;
285 su - opensrf sh -c "$OSRF_COMMAND"
286 echo Return Value = $?
287 echo End of Building OpenSRF =~-._
290 function test_opensrf_build {
291 echo _.-~= Running OpenSRF build tests
292 cd /home/opensrf/OpenSRF;
294 echo Return Value = $?
295 echo End of OpenSRF build tests =~-._
298 function install_opensrf {
299 echo _.-~= Installing OpenSRF
301 echo Return Value = $?
302 echo End of Installing OpenSRF =~-._
305 function build_evergreen {
306 echo _.-~= Building Evergreen
308 export PATH=/openils/bin:$PATH
309 cd /home/opensrf/Evergreen;
311 ./configure --prefix=/openils --sysconfdir=/openils/conf;
314 su - opensrf sh -c "$OSRF_COMMAND"
315 echo Return Value = $?
316 echo End of Building Evergreen =~-._
319 function test_evergreen_build {
320 echo _.-~= Running Evergreen build tests
321 cd /home/opensrf/Evergreen
323 echo Return Value = $?
324 echo End of Evergreen build tests =~-._
327 function install_evergreen {
328 echo _.-~= Installing Evergreen
330 echo Return Value = $?
332 cp /openils/conf/opensrf.xml.example /openils/conf/opensrf.xml
333 cp /openils/conf/opensrf_core.xml.example /openils/conf/opensrf_core.xml
335 # fetch and install Dojo
337 wget -N "http://download.dojotoolkit.org/release-$DOJO_VERSION/dojo-release-$DOJO_VERSION.tar.gz" \
338 || wget -N "http://evergreen-ils.org/~phasefx/download.dojotoolkit.org/dojo-release-$DOJO_VERSION.tar.gz"
339 tar -zxf dojo-release-$DOJO_VERSION.tar.gz;
340 cp -r dojo-release-$DOJO_VERSION/* /openils/var/web/js/dojo/;
342 # give it all to opensrf
343 chown -R opensrf:opensrf /openils
345 # copy srfsh config into place
346 cp /openils/conf/srfsh.xml.example /home/opensrf/.srfsh.xml;
347 chown opensrf:opensrf /home/opensrf/.srfsh.xml;
348 echo End of Installing Evergreen =~-._
351 function configure_database {
352 echo _.-~= configure database
354 echo "Using password evergreen for the evergreen database user."
355 echo -e "evergreen\nevergreen\n" | su - postgres sh -c 'createuser -P -s evergreen;'
357 echo -e "\n\nPlease enter a password for the evergreen database user.\n If you do not want to edit configs, use \"evergreen\"\n"
358 su - postgres sh -c 'createuser -P -s evergreen;'
361 # Apply the DB schema
362 cd /home/opensrf/Evergreen
363 perl Open-ILS/src/support-scripts/eg_db_config \
367 --update-config $SAMPLEDATA \
370 --password evergreen \
371 --hostname localhost \
372 --database evergreen \
373 --admin-user $ADMIN_USER \
374 --admin-pass $ADMIN_PASS;
375 echo Return Value = $?
377 if [ $LIVETEST ]; then
379 git clone --depth 0 https://github.com/theory/pgtap.git \
384 su - postgres -c "$PG_CMD"
385 cd /var/lib/postgresql/pgtap \
387 echo 'CREATE EXTENSION pgtap;' | su - postgres -c "psql evergreen"
389 echo configure database =~-._
392 function configure_apache {
393 echo _.-~= configure apache
394 /etc/init.d/apache2 stop
395 # Copy apache configs into place and create SSL cert
396 cd /home/opensrf/Evergreen/
397 cp Open-ILS/examples/apache/eg.conf /etc/apache2/sites-available/
398 cp Open-ILS/examples/apache/eg_vhost.conf /etc/apache2/
399 cp Open-ILS/examples/apache/eg_startup /etc/apache2/
401 mkdir -p /etc/apache2/ssl;
402 if [ ! -f /etc/apache2/ssl/server.key ] ; then
403 echo -e "\n\nConfiguring a new temporary SSL certificate....\n";
405 yes "" | openssl req -new -x509 -days 365 -nodes -out /etc/apache2/ssl/server.crt -keyout /etc/apache2/ssl/server.key
407 openssl req -new -x509 -days 365 -nodes -out /etc/apache2/ssl/server.crt -keyout /etc/apache2/ssl/server.key
410 echo -e "\nkeeping existing ssl/server.key file\n";
414 echo Return Value = $?
416 echo Return Value = $?
418 echo Return Value = $?
419 a2dissite 000-default
420 echo Return Value = $?
422 echo Return Value = $?
424 echo Modifying APACHE_RUN_USER/APACHE_RUN_GROUP in /etc/apache2/envvars
425 sed -i 's/www-data/opensrf/g' /etc/apache2/envvars
427 echo Making sure /var/lock/apache2 is owned by opensrf
428 chown opensrf:opensrf /var/lock/apache2
430 echo Modifying KeepAliveTimeout in /etc/apache2/apache2.conf
431 sed -i 's/KeepAliveTimeout .*/KeepAliveTimeout 1/' /etc/apache2/apache2.conf
433 echo End of configure apache =~-._
436 function start_evergreen {
437 echo _.-~= Starting Evergreen
438 if [ $LIVETEST ]; then
439 rm /openils/var/log/*.log
443 export LD_LIBRARY_PATH=/openils/lib:/usr/local/lib:/usr/local/lib/dbd:$LD_LIBRARY_PATH \
444 && export PATH=/openils/bin:$PATH \
445 && OSRF_HOSTNAME="dns_hack" /openils/bin/osrf_control --localhost --restart-all && sleep 3 \
446 && /openils/bin/autogen.sh /openils/conf/opensrf_core.xml \
449 echo Starting services...
450 su - opensrf sh -c "$OSRF_COMMAND";
451 echo Return Value = $?
453 echo Restarting Apache
454 /etc/init.d/apache2 restart
455 echo Return Value = $?
457 echo End of Starting Evergreen =~-._
460 function test_evergreen_live {
461 # TODO: Eventually move these tests into a Make target within Evergreen
462 cd /home/opensrf/Evergreen
463 echo _.-~= Running pgTAP tests
464 su - postgres -c 'cd /home/opensrf/Evergreen ; pg_prove -vr -d evergreen Open-ILS/src/sql/Pg/t/ ; echo Return Value = $?'
465 echo End of pgTAP tests =~-._
466 echo _.-~= Running pgTAP live tests
467 su - postgres -c 'cd /home/opensrf/Evergreen ; pg_prove -vr -d evergreen Open-ILS/src/sql/Pg/live_t/ ; echo Return Value = $?'
468 echo End of pgTAP live tests =~-._
469 echo _.-~= Running settings-tester.pl
470 su - opensrf sh -c 'export PATH=/openils/bin:$PATH ; cd /home/opensrf/Evergreen/Open-ILS/src/support-scripts/ ; ./settings-tester.pl ; echo Return Value = $?'
471 echo End of settings-tester.pl output =~-._
472 echo _.-~= Running perl live tests
473 su - opensrf sh -c 'export PATH=/openils/bin:$PATH ; cd /home/opensrf/Evergreen/Open-ILS/src/perlmods/ ; make livecheck; echo Return Value = $?'
474 echo End of perl live tests =~-._
475 echo _.-~= Gathering log summary
478 su - opensrf sh -c 'cd /openils/var/log/ ; wc -l *.log'
481 su - opensrf sh -c 'cd /openils/var/log/ ; du -sh *.log'
483 echo 'perl -ne ''if (/^\[.*?\] (.*?) \[/) { print "$1\n"; }'' osrfsys.log | sort | uniq -c | sort -k2:'
484 (cd /openils/var/log/ ; perl -ne 'if (/^\[.*?\] (.*?) \[/) { print "$1\n"; }' osrfsys.log | sort | uniq -c | sort -k2)
486 echo End of log summary =~-._
489 echo _.-~= Log Output: $x
493 echo _.-~= Gathering system information
498 echo 'select version();' | su - postgres -c 'psql -At'
500 echo '/proc/meminfo:'
503 echo '/proc/cpuinfo:'
510 sudo cpan -l 2> /dev/null | sort
511 echo End of system information =~-._