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
37 # evergreen_db_prereqs
38 setting_ldconfig_and_rsyslog_and_hosts_and_ejabberd
43 # test_evergreen_build
44 # test_and_build_eg_browser_client
48 if [ $AUTOSTART ]; then
50 if [ $LIVETEST ]; then
56 function init_variables {
57 echo _.-~= initializing installer
59 # -----------------------------------------------------------------------
60 # Handling passed arguments to the script
61 # -----------------------------------------------------------------------
62 export DOJO_VERSION='1.3.3';
63 export PATH=/openils/bin:$PATH
64 export LD_LIBRARY_PATH=/openils/lib:/usr/local/lib:/usr/local/lib/dbd:$LD_LIBRARY_PATH
66 echo AUTOSTART=${AUTOSTART}
68 echo SAMPLEDATA=${SAMPLEDATA}
69 echo LIVETEST=${LIVETEST}
70 echo DOJO_VERSION=${DOJO_VERSION}
72 echo LD_LIBRARY_PATH=${LD_LIBRARY_PATH}
73 echo BASE_DIR=${BASE_DIR}
74 # -----------------------------------------------------------------------
76 # -----------------------------------------------------------------------
77 # If you change the jabber password, you will need to
78 # edit opensrf_core.xml and srfsh.xml accordingly
79 export JABBER_PASSWORD='password'
80 export ADMIN_USER='admin';
81 export ADMIN_PASS='demo123';
82 # -----------------------------------------------------------------------
83 # You can override these like so:
84 # EVERGREEN_BRANCH='master' ./eg_jessie_installer.sh
85 # -----------------------------------------------------------------------
86 OPENSRF_REPO='git://git.evergreen-ils.org/OpenSRF.git'
87 OPENSRF_BRANCH='master'
88 EVERGREEN_REPO='git://git.evergreen-ils.org/Evergreen.git'
89 EVERGREEN_BRANCH='master'
90 echo OPENSRF_REPO=${OPENSRF_REPO}
91 echo OPENSRF_BRANCH=${OPENSRF_BRANCH}
92 echo EVERGREEN_REPO=${EVERGREEN_REPO}
93 echo EVERGREEN_BRANCH=${EVERGREEN_BRANCH}
94 OPENSRF_PREREQ_TARGET=debian-jessie
95 EVERGREEN_PREREQ_TARGET=debian-jessie
96 EVERGREEN_DB_PREREQ_TARGET=postgres-server-debian-jessie
97 echo OPENSRF_PREREQ_TARGET=${OPENSRF_PREREQ_TARGET}
98 echo EVERGREEN_PREREQ_TARGET=${EVERGREEN_PREREQ_TARGET}
99 echo EVERGREEN_DB_PREREQ_TARGET=${EVERGREEN_DB_PREREQ_TARGET}
101 export NODEJS_REPO='https://github.com/joyent/node.git'
102 export NODEJS_VERSION='v0.10.35'
103 echo "NODEJS_REPO=$NODEJS_REPO"
104 echo "NODEJS_VERSION=$NODEJS_VERSION"
106 echo End of intializing installer =~-._
110 function configure_cpan {
111 echo _.-~= configure CPAN
113 # -----------------------------------------------------------------------
114 # force CPAN to load by installing something that should already be installed
120 echo Return Value = $?
121 # CPAN follow pre-reqs?
122 if [ ! "$(echo 'o conf prerequisites_policy' | cpan | grep follow)" ]; then
125 echo "setting cpan prerequisites_policy to follow"
126 echo -e "o conf prerequisites_policy follow\\n o conf commit" | cpan
132 -----------------------------------------------------------------------
133 The install will go faster if CPAN is configured to automatically install
134 prerequisites. You can revert the action later with:
136 echo -e "o conf prerequisites_policy ask\n o conf commit" | cpan
139 echo -n 'Automatically install prereqs? [Y/n] ';
141 [ "$X" == 'n' -o "$X" == "N" ] && break;
142 if [ "$X" == 'y' -o "$X" == 'Y' ]; then
143 echo -e "o conf prerequisites_policy follow\\n o conf commit" | cpan
149 echo End of configure CPAN =~-._
152 function build_essentials {
153 echo _.-~= Installing some build essentials
155 # Install some essential tools
157 && apt-get -yq dist-upgrade \
158 && apt-get -yq install build-essential automake git psmisc ntp rsyslog;
159 echo Return Value = $?
161 if [ $LIVETEST ]; then
162 cpan TAP::Parser::SourceHandler::pgTAP
163 echo Return Value = $?
165 echo End of Installing some build essentials =~-._
168 function setting_up_opensrf_env {
169 echo _.-~= creating opensrf user and environment
171 # Create opensrf user and set up environment
172 if [ ! "$(grep ^opensrf: /etc/passwd)" ]; then
173 useradd -m -s /bin/bash opensrf
174 echo Return Value = $?
175 echo 'export PATH=/openils/bin:$PATH' >> /home/opensrf/.bashrc
176 echo 'export LD_LIBRARY_PATH=/openils/lib:/usr/local/lib:/usr/local/lib/dbd:$LD_LIBRARY_PATH' >> /home/opensrf/.bashrc
178 echo end of creating opensrf user and environment =~-._
181 function cloning_git_repos {
182 echo _.-~= cloning git repositories
186 git clone --depth 1 --branch $OPENSRF_BRANCH $OPENSRF_REPO OpenSRF;
188 rm -rf /home/opensrf/Evergreen /home/opensrf/OpenSRF
189 su - opensrf sh -c "$OSRF_COMMAND";
190 echo Return Value = $?
193 cd /home/opensrf/OpenSRF/
194 echo 'Tip of OpenSRF:' `git log --format=oneline | head -1`
196 echo End of cloning git repositories =~-._
199 function opensrf_prereqs {
200 echo _.-~= Installing OpenSRF pre-requisites
203 mkdir -p /usr/src/evergreen;
204 cd /usr/src/evergreen;
206 yes | make -f /home/opensrf/OpenSRF/src/extras/Makefile.install ${OPENSRF_PREREQ_TARGET}
208 make -f /home/opensrf/OpenSRF/src/extras/Makefile.install ${OPENSRF_PREREQ_TARGET}
210 echo Return Value = $?
211 echo End of Installing OpenSRF pre-requisites =~-._
214 function evergreen_prereqs {
215 echo _.-~= Installing Evergreen pre-requisites
218 yes | make -f /home/opensrf/Evergreen/Open-ILS/src/extras/Makefile.install ${EVERGREEN_PREREQ_TARGET}
220 make -f /home/opensrf/Evergreen/Open-ILS/src/extras/Makefile.install ${EVERGREEN_PREREQ_TARGET}
222 echo Return Value = $?
223 echo End of Installing Evergreen pre-requisites =~-._
226 function evergreen_db_prereqs {
227 echo _.-~= Installing Evergreen database pre-requisites
230 yes | make -f /home/opensrf/Evergreen/Open-ILS/src/extras/Makefile.install ${EVERGREEN_DB_PREREQ_TARGET}
232 make -f /home/opensrf/Evergreen/Open-ILS/src/extras/Makefile.install ${EVERGREEN_DB_PREREQ_TARGET}
234 echo Return Value = $?
235 echo End of Installing Evergreen database pre-requisites =~-._
238 function setting_ldconfig_and_rsyslog_and_hosts_and_ejabberd {
239 echo _.-~= setting ld.so.conf and rsyslog and /etc/hosts and ejabberd
241 cp $BASE_DIR/evergreen.ld.conf /etc/ld.so.conf.d/
243 echo Return Value = $?
244 # Configure rsyslog and restart
245 cp /home/opensrf/Evergreen/Open-ILS/examples/evergreen-rsyslog.conf /etc/rsyslog.d/evergreen.conf
246 /etc/init.d/rsyslog restart
247 echo Return Value = $?
248 if [ ! "$(grep 'public.localhost' /etc/hosts)" ]; then
251 echo 'Adding public.localhost and private.localhost to /etc/hosts'
252 echo '127.0.1.2 public.localhost public' >> /etc/hosts
253 echo '127.0.1.3 private.localhost private' >> /etc/hosts
258 * Add these lines to /etc/hosts.
260 127.0.1.2 public.localhost public
261 127.0.1.3 private.localhost private
267 echo "INFO: /etc/hosts already has public.localhost line";
269 echo Return Value = $?
270 # Patch Ejabberd and register users
271 if [ ! "$(grep 'public.localhost' /etc/ejabberd/ejabberd.yml)" ]; then
273 /etc/init.d/ejabberd stop;
274 killall beam epmd; # just in case
275 cp ejabberd.yml /root/ejabberd.yml.orig
276 patch -p0 < $BASE_DIR/ejabberd.EG.patch
277 chown ejabberd:ejabberd ejabberd.yml
278 echo starting ejabberd after patching
280 /etc/init.d/ejabberd start
281 echo Return Value = $?
283 ejabberdctl register router private.localhost $JABBER_PASSWORD
284 echo Return Value = $?
285 ejabberdctl register opensrf private.localhost $JABBER_PASSWORD
286 echo Return Value = $?
287 ejabberdctl register router public.localhost $JABBER_PASSWORD
288 echo Return Value = $?
289 ejabberdctl register opensrf public.localhost $JABBER_PASSWORD
290 echo Return Value = $?
292 echo End of setting ld.so.conf and rsyslog and /etc/hosts and ejabberd =~-._
295 function build_opensrf {
296 # Build and install OpenSRF
297 echo _.-~= Building OpenSRF
300 cd /home/opensrf/OpenSRF;
302 ./configure --prefix=/openils --sysconfdir=/openils/conf;
304 su - opensrf sh -c "$OSRF_COMMAND"
305 echo Return Value = $?
306 echo End of Building OpenSRF =~-._
309 function test_opensrf_build {
310 echo _.-~= Running OpenSRF build tests
312 cd /home/opensrf/OpenSRF;
314 echo Return Value = $?
315 echo End of OpenSRF build tests =~-._
318 function install_opensrf {
319 echo _.-~= Installing OpenSRF
322 echo Return Value = $?
323 echo End of Installing OpenSRF =~-._
326 function build_evergreen {
327 echo _.-~= Building Evergreen
330 export PATH=/openils/bin:$PATH
331 cd /home/opensrf/Evergreen;
333 ./configure --prefix=/openils --sysconfdir=/openils/conf;
336 su - opensrf sh -c "$OSRF_COMMAND"
337 echo Return Value = $?
338 echo End of Building Evergreen =~-._
341 function test_evergreen_build {
342 echo _.-~= Running Evergreen build tests
344 cd /home/opensrf/Evergreen
346 echo Return Value = $?
347 echo End of Evergreen build tests =~-._
351 # The evergreen browser client prereq installation and
352 # build process is not baked into Evergreen proper (yet).
353 # Run it as a standalone operation for now.
354 function test_and_build_eg_browser_client {
355 echo _.-~= Running Evergreen browser client build/test
357 git clone $NODEJS_REPO
359 git checkout -b $NODEJS_VERSION $NODEJS_VERSION
360 ./configure && make -j2 && make install
361 echo Return Value = $?
363 echo Return Value = $?
364 npm install -g grunt-cli # install grunt
365 echo Return Value = $?
366 npm install -g bower # install bower
367 echo Return Value = $?
368 cd /home/opensrf/Evergreen/Open-ILS/web/js/ui/default/staff
369 npm install # fetch build depencies
370 echo Return Value = $?
372 # fetch JS/CSS/etc prereqs
374 # yes == allow sending package stats
375 yes | bower --allow-root install
377 bower --allow-root install
379 echo Return Value = $?
381 grunt build # concatentate, minify, copy into place
382 echo Return Value = $?
383 grunt test # run JS unit tests
384 echo Return Value = $?
385 echo End of Evergreen browser client build/test =~-._
388 function install_evergreen {
389 echo _.-~= Installing Evergreen
391 cd /home/opensrf/Evergreen
393 echo Return Value = $?
395 cp /openils/conf/opensrf.xml.example /openils/conf/opensrf.xml
396 cp /openils/conf/opensrf_core.xml.example /openils/conf/opensrf_core.xml
398 # fetch and install Dojo
400 wget -N "http://download.dojotoolkit.org/release-$DOJO_VERSION/dojo-release-$DOJO_VERSION.tar.gz" \
401 || wget -N "http://evergreen-ils.org/~phasefx/download.dojotoolkit.org/dojo-release-$DOJO_VERSION.tar.gz"
402 tar -zxf dojo-release-$DOJO_VERSION.tar.gz;
403 cp -r dojo-release-$DOJO_VERSION/* /openils/var/web/js/dojo/;
405 # give it all to opensrf
406 chown -R opensrf:opensrf /openils
408 # copy srfsh config into place
409 cp /openils/conf/srfsh.xml.example /home/opensrf/.srfsh.xml;
410 chown opensrf:opensrf /home/opensrf/.srfsh.xml;
411 echo End of Installing Evergreen =~-._
414 function configure_database {
415 echo _.-~= configure database
418 echo "Using password evergreen for the evergreen database user."
419 echo -e "evergreen\nevergreen\n" | su - postgres sh -c 'createuser -P -s evergreen;'
421 echo -e "\n\nPlease enter a password for the evergreen database user.\n If you do not want to edit configs, use \"evergreen\"\n"
422 su - postgres sh -c 'createuser -P -s evergreen;'
425 # Apply the DB schema
426 cd /home/opensrf/Evergreen
427 perl Open-ILS/src/support-scripts/eg_db_config \
431 --update-config $SAMPLEDATA \
434 --password evergreen \
435 --hostname localhost \
436 --database evergreen \
437 --admin-user $ADMIN_USER \
438 --admin-pass $ADMIN_PASS;
439 echo Return Value = $?
441 if [ $LIVETEST ]; then
443 git clone --depth 1 https://github.com/theory/pgtap.git \
448 su - postgres -c "$PG_CMD"
449 cd /var/lib/postgresql/pgtap \
451 echo 'CREATE EXTENSION pgtap;' | su - postgres -c "psql evergreen"
453 echo configure database =~-._
456 function configure_apache {
457 echo _.-~= configure apache
459 /etc/init.d/apache2 stop
460 # Copy apache configs into place and create SSL cert
461 cd /home/opensrf/Evergreen/
462 cp Open-ILS/examples/apache_24/eg_24.conf /etc/apache2/sites-available/eg.conf
463 cp Open-ILS/examples/apache_24/eg_vhost_24.conf /etc/apache2/eg_vhost.conf
464 cp Open-ILS/examples/apache/eg_startup /etc/apache2/
466 mkdir -p /etc/apache2/ssl;
467 if [ ! -f /etc/apache2/ssl/server.key ] ; then
468 echo -e "\n\nConfiguring a new temporary SSL certificate....\n";
470 yes "" | openssl req -new -x509 -days 365 -nodes -out /etc/apache2/ssl/server.crt -keyout /etc/apache2/ssl/server.key
472 openssl req -new -x509 -days 365 -nodes -out /etc/apache2/ssl/server.crt -keyout /etc/apache2/ssl/server.key
475 echo -e "\nkeeping existing ssl/server.key file\n";
479 echo Return Value = $?
481 echo Return Value = $?
483 echo Return Value = $?
484 a2dissite 000-default
485 echo Return Value = $?
487 echo Return Value = $?
489 echo Modifying APACHE_RUN_USER/APACHE_RUN_GROUP in /etc/apache2/envvars
490 sed -i 's/www-data/opensrf/g' /etc/apache2/envvars
492 echo Making sure /var/lock/apache2 is owned by opensrf
493 chown opensrf:opensrf /var/lock/apache2
495 echo Modifying KeepAliveTimeout in /etc/apache2/apache2.conf
496 sed -i 's/KeepAliveTimeout .*/KeepAliveTimeout 1/' /etc/apache2/apache2.conf
498 echo End of configure apache =~-._
501 function start_evergreen {
502 echo _.-~= Starting Evergreen
504 if [ $LIVETEST ]; then
505 rm /openils/var/log/*.log
509 export LD_LIBRARY_PATH=/openils/lib:/usr/local/lib:/usr/local/lib/dbd:$LD_LIBRARY_PATH \
510 && export PATH=/openils/bin:$PATH \
511 && OSRF_HOSTNAME="dns_hack" /openils/bin/osrf_control --localhost --restart-all && sleep 3 \
512 && /openils/bin/autogen.sh /openils/conf/opensrf_core.xml \
515 echo Starting services...
516 su - opensrf sh -c "$OSRF_COMMAND";
517 echo Return Value = $?
519 echo Restarting Apache
520 /etc/init.d/apache2 restart
521 echo Return Value = $?
523 echo End of Starting Evergreen =~-._
526 function test_evergreen_live {
527 # TODO: Eventually move these tests into a Make target within Evergreen
528 cd /home/opensrf/Evergreen
529 echo _.-~= Running pgTAP tests
531 su - postgres -c 'cd /home/opensrf/Evergreen ; pg_prove -vr -d evergreen Open-ILS/src/sql/Pg/t/ ; echo Return Value = $?'
532 echo End of pgTAP tests =~-._
533 echo _.-~= Running pgTAP live tests
535 su - postgres -c 'cd /home/opensrf/Evergreen ; pg_prove -vr -d evergreen Open-ILS/src/sql/Pg/live_t/ ; echo Return Value = $?'
536 echo End of pgTAP live tests =~-._
537 echo _.-~= Running settings-tester.pl
539 su - opensrf sh -c 'export PATH=/openils/bin:$PATH ; cd /home/opensrf/Evergreen/Open-ILS/src/support-scripts/ ; ./settings-tester.pl ; echo Return Value = $?'
540 echo End of settings-tester.pl output =~-._
541 echo _.-~= Running perl live tests
543 su - opensrf sh -c 'export PATH=/openils/bin:$PATH ; cd /home/opensrf/Evergreen/Open-ILS/src/perlmods/ ; make livecheck; echo Return Value = $?'
544 echo End of perl live tests =~-._
545 echo _.-~= Gathering log summary
549 su - opensrf sh -c 'cd /openils/var/log/ ; wc -l *.log'
552 su - opensrf sh -c 'cd /openils/var/log/ ; du -sh *.log'
554 echo 'perl -ne ''if (/^\[.*?\] (.*?) \[/) { print "$1\n"; }'' osrfsys.log | sort | uniq -c | sort -k2:'
555 (cd /openils/var/log/ ; perl -ne 'if (/^\[.*?\] (.*?) \[/) { print "$1\n"; }' osrfsys.log | sort | uniq -c | sort -k2)
557 echo End of log summary =~-._
560 echo _.-~= Log Output: $x
565 echo _.-~= Gathering system information
570 echo 'select version();' | su - postgres -c 'psql -At'
572 echo '/proc/meminfo:'
575 echo '/proc/cpuinfo:'
582 cpan -l 2> /dev/null | sort
583 echo End of system information =~-._