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;;
34 setting_up_opensrf_env
39 setting_ldconfig_and_rsyslog_and_hosts_and_ejabberd
48 if [ $AUTOSTART ]; then
54 function init_variables {
55 echo _.-~= initializing installer
57 # -----------------------------------------------------------------------
58 # Handling passed arguments to the script
59 # -----------------------------------------------------------------------
60 export DOJO_VERSION='1.3.3';
61 export PATH=/openils/bin:$PATH
62 export LD_LIBRARY_PATH=/openils/lib:/usr/local/lib:/usr/local/lib/dbd:$LD_LIBRARY_PATH
64 echo AUTOSTART=${AUTOSTART}
66 echo SAMPLEDATA=${SAMPLEDATA}
67 echo LIVETEST=${LIVETEST}
68 echo DOJO_VERSION=${DOJO_VERSION}
70 echo LD_LIBRARY_PATH=${LD_LIBRARY_PATH}
71 echo BASE_DIR=${BASE_DIR}
72 # -----------------------------------------------------------------------
74 # -----------------------------------------------------------------------
75 # If you change the jabber password, you will need to
76 # edit opensrf_core.xml and srfsh.xml accordingly
77 export JABBER_PASSWORD='password'
78 export ADMIN_USER='admin';
79 export ADMIN_PASS='demo123';
80 # -----------------------------------------------------------------------
81 # You can override these like so:
82 # EVERGREEN_BRANCH='master' ./eg_wheezy_installer.sh
83 # -----------------------------------------------------------------------
84 OPENSRF_REPO='git://git.evergreen-ils.org/OpenSRF.git'
85 OPENSRF_BRANCH='master'
86 EVERGREEN_REPO='git://git.evergreen-ils.org/Evergreen.git'
87 EVERGREEN_BRANCH='master'
88 echo OPENSRF_REPO=${OPENSRF_REPO}
89 echo OPENSRF_BRANCH=${OPENSRF_BRANCH}
90 echo EVERGREEN_REPO=${EVERGREEN_REPO}
91 echo EVERGREEN_BRANCH=${EVERGREEN_BRANCH}
92 OPENSRF_PREREQ_TARGET=debian-wheezy
93 EVERGREEN_PREREQ_TARGET=debian-wheezy
94 EVERGREEN_DB_PREREQ_TARGET=postgres-server-debian-wheezy
95 echo OPENSRF_PREREQ_TARGET=${OPENSRF_PREREQ_TARGET}
96 echo EVERGREEN_PREREQ_TARGET=${EVERGREEN_PREREQ_TARGET}
97 echo EVERGREEN_DB_PREREQ_TARGET=${EVERGREEN_DB_PREREQ_TARGET}
98 echo End of intializing installer =~-._
101 function configure_timezone {
102 echo _.-~= configure timezone
104 # should be America/New_York
105 perl -e 'print "2\n\n104\n";' | dpkg-reconfigure -fteletype tzdata
106 echo End of configure timezone =~-._
109 function configure_cpan {
110 echo _.-~= configure CPAN
112 # -----------------------------------------------------------------------
113 # force CPAN to load by installing something that should already be installed
119 echo Return Value = $?
120 # CPAN follow pre-reqs?
121 if [ ! "$(echo 'o conf prerequisites_policy' | cpan | grep follow)" ]; then
124 echo "setting cpan prerequisites_policy to follow"
125 echo -e "o conf prerequisites_policy follow\\n o conf commit" | cpan
131 -----------------------------------------------------------------------
132 The install will go faster if CPAN is configured to automatically install
133 prerequisites. You can revert the action later with:
135 echo -e "o conf prerequisites_policy ask\n o conf commit" | cpan
138 echo -n 'Automatically install prereqs? [Y/n] ';
140 [ "$X" == 'n' -o "$X" == "N" ] && break;
141 if [ "$X" == 'y' -o "$X" == 'Y' ]; then
142 echo -e "o conf prerequisites_policy follow\\n o conf commit" | cpan
148 echo End of configure CPAN =~-._
151 function build_essentials {
152 echo _.-~= Installing some build essentials
154 # Install some essential tools
156 && apt-get -yq dist-upgrade \
157 && apt-get -yq install build-essential automake git psmisc ntp rsyslog;
158 echo Return Value = $?
160 if [ $LIVETEST ]; then
161 cpan TAP::Parser::SourceHandler::pgTAP
162 echo Return Value = $?
164 echo End of Installing some build essentials =~-._
167 function setting_up_opensrf_env {
168 echo _.-~= creating opensrf user and environment
170 # Create opensrf user and set up environment
171 if [ ! "$(grep ^opensrf: /etc/passwd)" ]; then
172 useradd -m -s /bin/bash opensrf
173 echo Return Value = $?
174 echo 'export PATH=/openils/bin:$PATH' >> /home/opensrf/.bashrc
175 echo 'export LD_LIBRARY_PATH=/openils/lib:/usr/local/lib:/usr/local/lib/dbd:$LD_LIBRARY_PATH' >> /home/opensrf/.bashrc
177 echo end of creating opensrf user and environment =~-._
180 function cloning_git_repos {
181 echo _.-~= cloning git repositories
185 git clone --depth 0 --branch $OPENSRF_BRANCH $OPENSRF_REPO OpenSRF;
186 git clone --depth 0 --branch $EVERGREEN_BRANCH $EVERGREEN_REPO Evergreen;
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`
195 cd /home/opensrf/Evergreen/
196 echo 'Tip of Evergreen:' `git log --format=oneline | head -1`
198 echo End of cloning git repositories =~-._
201 function opensrf_prereqs {
202 echo _.-~= Installing OpenSRF pre-requisites
205 mkdir -p /usr/src/evergreen;
206 cd /usr/src/evergreen;
208 yes | make -f /home/opensrf/OpenSRF/src/extras/Makefile.install ${OPENSRF_PREREQ_TARGET}
210 make -f /home/opensrf/OpenSRF/src/extras/Makefile.install ${OPENSRF_PREREQ_TARGET}
212 echo Return Value = $?
213 echo End of Installing OpenSRF pre-requisites =~-._
216 function evergreen_prereqs {
217 echo _.-~= Installing Evergreen pre-requisites
220 yes | make -f /home/opensrf/Evergreen/Open-ILS/src/extras/Makefile.install ${EVERGREEN_PREREQ_TARGET}
222 make -f /home/opensrf/Evergreen/Open-ILS/src/extras/Makefile.install ${EVERGREEN_PREREQ_TARGET}
224 echo Return Value = $?
225 echo End of Installing Evergreen pre-requisites =~-._
228 function evergreen_db_prereqs {
229 echo _.-~= Installing Evergreen database pre-requisites
232 yes | make -f /home/opensrf/Evergreen/Open-ILS/src/extras/Makefile.install ${EVERGREEN_DB_PREREQ_TARGET}
234 make -f /home/opensrf/Evergreen/Open-ILS/src/extras/Makefile.install ${EVERGREEN_DB_PREREQ_TARGET}
236 echo Return Value = $?
237 echo End of Installing Evergreen database pre-requisites =~-._
240 function setting_ldconfig_and_rsyslog_and_hosts_and_ejabberd {
241 echo _.-~= setting ld.so.conf and rsyslog and /etc/hosts and ejabberd
243 cp $BASE_DIR/evergreen.ld.conf /etc/ld.so.conf.d/
245 echo Return Value = $?
246 # Configure rsyslog and restart
247 cp /home/opensrf/Evergreen/Open-ILS/examples/evergreen-rsyslog.conf /etc/rsyslog.d/evergreen.conf
248 /etc/init.d/rsyslog restart
249 echo Return Value = $?
250 if [ ! "$(grep 'public.localhost' /etc/hosts)" ]; then
253 echo 'Adding public.localhost and private.localhost to /etc/hosts'
254 echo '127.0.1.2 public.localhost public' >> /etc/hosts
255 echo '127.0.1.3 private.localhost private' >> /etc/hosts
260 * Add these lines to /etc/hosts.
262 127.0.1.2 public.localhost public
263 127.0.1.3 private.localhost private
269 echo "INFO: /etc/hosts already has public.localhost line";
271 echo Return Value = $?
272 # Patch Ejabberd and register users
273 if [ ! "$(grep 'public.localhost' /etc/ejabberd/ejabberd.cfg)" ]; then
275 /etc/init.d/ejabberd stop;
276 killall beam epmd; # just in case
277 cp ejabberd.cfg /root/ejabberd.cfg.orig
278 patch -p0 < $BASE_DIR/ejabberd.EG.patch
279 chown ejabberd:ejabberd ejabberd.cfg
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 =~-._
350 function install_evergreen {
351 echo _.-~= Installing Evergreen
354 echo Return Value = $?
356 cp /openils/conf/opensrf.xml.example /openils/conf/opensrf.xml
357 cp /openils/conf/opensrf_core.xml.example /openils/conf/opensrf_core.xml
359 # fetch and install Dojo
361 wget -N "http://download.dojotoolkit.org/release-$DOJO_VERSION/dojo-release-$DOJO_VERSION.tar.gz" \
362 || wget -N "http://evergreen-ils.org/~phasefx/download.dojotoolkit.org/dojo-release-$DOJO_VERSION.tar.gz"
363 tar -zxf dojo-release-$DOJO_VERSION.tar.gz;
364 cp -r dojo-release-$DOJO_VERSION/* /openils/var/web/js/dojo/;
366 # give it all to opensrf
367 chown -R opensrf:opensrf /openils
369 # copy srfsh config into place
370 cp /openils/conf/srfsh.xml.example /home/opensrf/.srfsh.xml;
371 chown opensrf:opensrf /home/opensrf/.srfsh.xml;
372 echo End of Installing Evergreen =~-._
375 function configure_database {
376 echo _.-~= configure database
379 echo "Using password evergreen for the evergreen database user."
380 echo -e "evergreen\nevergreen\n" | su - postgres sh -c 'createuser -P -s evergreen;'
382 echo -e "\n\nPlease enter a password for the evergreen database user.\n If you do not want to edit configs, use \"evergreen\"\n"
383 su - postgres sh -c 'createuser -P -s evergreen;'
386 # Apply the DB schema
387 cd /home/opensrf/Evergreen
388 perl Open-ILS/src/support-scripts/eg_db_config \
392 --update-config $SAMPLEDATA \
395 --password evergreen \
396 --hostname localhost \
397 --database evergreen \
398 --admin-user $ADMIN_USER \
399 --admin-pass $ADMIN_PASS;
400 echo Return Value = $?
402 if [ $LIVETEST ]; then
404 git clone --depth 0 https://github.com/theory/pgtap.git \
409 su - postgres -c "$PG_CMD"
410 cd /var/lib/postgresql/pgtap \
412 echo 'CREATE EXTENSION pgtap;' | su - postgres -c "psql evergreen"
414 echo configure database =~-._
417 function configure_apache {
418 echo _.-~= configure apache
420 /etc/init.d/apache2 stop
421 # Copy apache configs into place and create SSL cert
422 cd /home/opensrf/Evergreen/
423 cp Open-ILS/examples/apache/eg.conf /etc/apache2/sites-available/
424 cp Open-ILS/examples/apache/eg_vhost.conf /etc/apache2/
425 cp Open-ILS/examples/apache/eg_startup /etc/apache2/
427 mkdir -p /etc/apache2/ssl;
428 if [ ! -f /etc/apache2/ssl/server.key ] ; then
429 echo -e "\n\nConfiguring a new temporary SSL certificate....\n";
431 yes "" | openssl req -new -x509 -days 365 -nodes -out /etc/apache2/ssl/server.crt -keyout /etc/apache2/ssl/server.key
433 openssl req -new -x509 -days 365 -nodes -out /etc/apache2/ssl/server.crt -keyout /etc/apache2/ssl/server.key
436 echo -e "\nkeeping existing ssl/server.key file\n";
440 echo Return Value = $?
442 echo Return Value = $?
444 echo Return Value = $?
445 a2dissite 000-default
446 echo Return Value = $?
448 echo Return Value = $?
450 echo Modifying APACHE_RUN_USER/APACHE_RUN_GROUP in /etc/apache2/envvars
451 sed -i 's/www-data/opensrf/g' /etc/apache2/envvars
453 echo Making sure /var/lock/apache2 is owned by opensrf
454 chown opensrf:opensrf /var/lock/apache2
456 echo Modifying KeepAliveTimeout in /etc/apache2/apache2.conf
457 sed -i 's/KeepAliveTimeout .*/KeepAliveTimeout 1/' /etc/apache2/apache2.conf
459 echo End of configure apache =~-._
462 function start_evergreen {
463 echo _.-~= Starting Evergreen
465 if [ $LIVETEST ]; then
466 rm /openils/var/log/*.log
470 export LD_LIBRARY_PATH=/openils/lib:/usr/local/lib:/usr/local/lib/dbd:$LD_LIBRARY_PATH \
471 && export PATH=/openils/bin:$PATH \
472 && OSRF_HOSTNAME="dns_hack" /openils/bin/osrf_control --localhost --restart-all && sleep 3 \
473 && /openils/bin/autogen.sh /openils/conf/opensrf_core.xml \
476 echo Starting services...
477 su - opensrf sh -c "$OSRF_COMMAND";
478 echo Return Value = $?
480 echo Restarting Apache
481 /etc/init.d/apache2 restart
482 echo Return Value = $?
484 echo End of Starting Evergreen =~-._
487 function test_evergreen_live {
488 # TODO: Eventually move these tests into a Make target within Evergreen
489 cd /home/opensrf/Evergreen
490 echo _.-~= Running pgTAP tests
492 su - postgres -c 'cd /home/opensrf/Evergreen ; pg_prove -vr -d evergreen Open-ILS/src/sql/Pg/t/ ; echo Return Value = $?'
493 echo End of pgTAP tests =~-._
494 echo _.-~= Running pgTAP live tests
496 su - postgres -c 'cd /home/opensrf/Evergreen ; pg_prove -vr -d evergreen Open-ILS/src/sql/Pg/live_t/ ; echo Return Value = $?'
497 echo End of pgTAP live tests =~-._
498 echo _.-~= Running settings-tester.pl
500 su - opensrf sh -c 'export PATH=/openils/bin:$PATH ; cd /home/opensrf/Evergreen/Open-ILS/src/support-scripts/ ; ./settings-tester.pl ; echo Return Value = $?'
501 echo End of settings-tester.pl output =~-._
502 echo _.-~= Running perl live tests
504 su - opensrf sh -c 'export PATH=/openils/bin:$PATH ; cd /home/opensrf/Evergreen/Open-ILS/src/perlmods/ ; make livecheck; echo Return Value = $?'
505 echo End of perl live tests =~-._
506 echo _.-~= Gathering log summary
510 su - opensrf sh -c 'cd /openils/var/log/ ; wc -l *.log'
513 su - opensrf sh -c 'cd /openils/var/log/ ; du -sh *.log'
515 echo 'perl -ne ''if (/^\[.*?\] (.*?) \[/) { print "$1\n"; }'' osrfsys.log | sort | uniq -c | sort -k2:'
516 (cd /openils/var/log/ ; perl -ne 'if (/^\[.*?\] (.*?) \[/) { print "$1\n"; }' osrfsys.log | sort | uniq -c | sort -k2)
518 echo End of log summary =~-._
521 echo _.-~= Log Output: $x
526 echo _.-~= Gathering system information
531 echo 'select version();' | su - postgres -c 'psql -At'
533 echo '/proc/meminfo:'
536 echo '/proc/cpuinfo:'
543 cpan -l 2> /dev/null | sort
544 echo End of system information =~-._