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
52 function init_variables {
53 echo _.-~= initializing installer
54 # -----------------------------------------------------------------------
55 # Handling passed arguments to the script
56 # -----------------------------------------------------------------------
57 export DOJO_VERSION='1.3.3';
58 export PATH=/openils/bin:$PATH
59 export LD_LIBRARY_PATH=/openils/lib:/usr/local/lib:/usr/local/lib/dbd:$LD_LIBRARY_PATH
61 echo AUTOSTART=${AUTOSTART}
63 echo SAMPLEDATA=${SAMPLEDATA}
64 echo LIVETEST=${LIVETEST}
65 echo DOJO_VERSION=${DOJO_VERSION}
67 echo LD_LIBRARY_PATH=${LD_LIBRARY_PATH}
68 echo BASE_DIR=${BASE_DIR}
69 # -----------------------------------------------------------------------
71 # -----------------------------------------------------------------------
72 # If you change the jabber password, you will need to
73 # edit opensrf_core.xml and srfsh.xml accordingly
74 export JABBER_PASSWORD='password'
75 export ADMIN_USER='admin';
76 export ADMIN_PASS='demo123';
77 # -----------------------------------------------------------------------
78 # You can override these like so:
79 # EVERGREEN_BRANCH='master' ./eg_wheezy_installer.sh
80 # -----------------------------------------------------------------------
81 OPENSRF_REPO='git://git.evergreen-ils.org/OpenSRF.git'
82 OPENSRF_BRANCH='master'
83 EVERGREEN_REPO='git://git.evergreen-ils.org/Evergreen.git'
84 EVERGREEN_BRANCH='master'
85 echo OPENSRF_REPO=${OPENSRF_REPO}
86 echo OPENSRF_BRANCH=${OPENSRF_BRANCH}
87 echo EVERGREEN_REPO=${EVERGREEN_REPO}
88 echo EVERGREEN_BRANCH=${EVERGREEN_BRANCH}
89 OPENSRF_PREREQ_TARGET=debian-wheezy
90 EVERGREEN_PREREQ_TARGET=debian-wheezy
91 EVERGREEN_DB_PREREQ_TARGET=postgres-server-debian-wheezy
92 echo OPENSRF_PREREQ_TARGET=${OPENSRF_PREREQ_TARGET}
93 echo EVERGREEN_PREREQ_TARGET=${EVERGREEN_PREREQ_TARGET}
94 echo EVERGREEN_DB_PREREQ_TARGET=${EVERGREEN_DB_PREREQ_TARGET}
95 echo End of intializing installer =~-._
98 function configure_cpan {
99 echo _.-~= configure CPAN
100 # -----------------------------------------------------------------------
101 # force CPAN to load by installing something that should already be installed
107 echo Return Value = $?
108 # CPAN follow pre-reqs?
109 if [ ! "$(echo 'o conf prerequisites_policy' | cpan | grep follow)" ]; then
112 echo "setting cpan prerequisites_policy to follow"
113 echo -e "o conf prerequisites_policy follow\\n o conf commit" | cpan
119 -----------------------------------------------------------------------
120 The install will go faster if CPAN is configured to automatically install
121 prerequisites. You can revert the action later with:
123 echo -e "o conf prerequisites_policy ask\n o conf commit" | cpan
126 echo -n 'Automatically install prereqs? [Y/n] ';
128 [ "$X" == 'n' -o "$X" == "N" ] && break;
129 if [ "$X" == 'y' -o "$X" == 'Y' ]; then
130 echo -e "o conf prerequisites_policy follow\\n o conf commit" | cpan
136 echo End of configure CPAN =~-._
139 function build_essentials {
140 echo _.-~= Installing some build essentials
141 # Install some essential tools
143 && apt-get -yq dist-upgrade \
144 && apt-get -yq install build-essential automake git psmisc ntp rsyslog;
145 echo Return Value = $?
147 if [ $LIVETEST ]; then
148 cpan TAP::Parser::SourceHandler::pgTAP
149 echo Return Value = $?
151 echo End of Installing some build essentials =~-._
154 function setting_up_opensrf_env {
155 echo _.-~= creating opensrf user and environment
156 # Create opensrf user and set up environment
157 if [ ! "$(grep ^opensrf: /etc/passwd)" ]; then
158 useradd -m -s /bin/bash opensrf
159 echo Return Value = $?
160 echo 'export PATH=/openils/bin:$PATH' >> /home/opensrf/.bashrc
161 echo 'export LD_LIBRARY_PATH=/openils/lib:/usr/local/lib:/usr/local/lib/dbd:$LD_LIBRARY_PATH' >> /home/opensrf/.bashrc
163 echo end of creating opensrf user and environment =~-._
166 function cloning_git_repos {
167 echo _.-~= cloning git repositories
170 git clone --depth 0 --branch $OPENSRF_BRANCH $OPENSRF_REPO OpenSRF;
171 git clone --depth 0 --branch $EVERGREEN_BRANCH $EVERGREEN_REPO Evergreen;
173 rm -rf /home/opensrf/Evergreen /home/opensrf/OpenSRF
174 su - opensrf sh -c "$OSRF_COMMAND";
175 echo Return Value = $?
178 cd /home/opensrf/OpenSRF/
179 echo 'Tip of OpenSRF:' `git log --format=oneline | head -1`
180 cd /home/opensrf/Evergreen/
181 echo 'Tip of Evergreen:' `git log --format=oneline | head -1`
183 echo End of cloning git repositories =~-._
186 function opensrf_prereqs {
187 echo _.-~= Installing OpenSRF pre-requisites
189 mkdir -p /usr/src/evergreen;
190 cd /usr/src/evergreen;
192 yes | make -f /home/opensrf/OpenSRF/src/extras/Makefile.install ${OPENSRF_PREREQ_TARGET}
194 make -f /home/opensrf/OpenSRF/src/extras/Makefile.install ${OPENSRF_PREREQ_TARGET}
196 echo Return Value = $?
197 echo End of Installing OpenSRF pre-requisites =~-._
200 function evergreen_prereqs {
201 echo _.-~= Installing Evergreen pre-requisites
203 yes | make -f /home/opensrf/Evergreen/Open-ILS/src/extras/Makefile.install ${EVERGREEN_PREREQ_TARGET}
205 make -f /home/opensrf/Evergreen/Open-ILS/src/extras/Makefile.install ${EVERGREEN_PREREQ_TARGET}
207 echo Return Value = $?
208 echo End of Installing Evergreen pre-requisites =~-._
211 function evergreen_db_prereqs {
212 echo _.-~= Installing Evergreen database pre-requisites
214 yes | make -f /home/opensrf/Evergreen/Open-ILS/src/extras/Makefile.install ${EVERGREEN_DB_PREREQ_TARGET}
216 make -f /home/opensrf/Evergreen/Open-ILS/src/extras/Makefile.install ${EVERGREEN_DB_PREREQ_TARGET}
218 echo Return Value = $?
219 echo End of Installing Evergreen database pre-requisites =~-._
222 function setting_ldconfig_and_rsyslog_and_hosts_ejabberd {
223 echo _.-~= setting ld.so.conf and rsyslog and /etc/hosts and ejabberd
224 cp $BASE_DIR/evergreen.ld.conf /etc/ld.so.conf.d/
226 echo Return Value = $?
227 # Configure rsyslog and restart
228 cp /home/opensrf/Evergreen/Open-ILS/examples/evergreen-rsyslog.conf /etc/rsyslog.d/evergreen.conf
229 /etc/init.d/rsyslog restart
230 echo Return Value = $?
231 if [ ! "$(grep 'public.localhost' /etc/hosts)" ]; then
234 echo 'Adding public.localhost and private.localhost to /etc/hosts'
235 echo '127.0.1.2 public.localhost public' >> /etc/hosts
236 echo '127.0.1.3 private.localhost private' >> /etc/hosts
241 * Add these lines to /etc/hosts.
243 127.0.1.2 public.localhost public
244 127.0.1.3 private.localhost private
250 echo "INFO: /etc/hosts already has public.localhost line";
252 echo Return Value = $?
253 # Patch Ejabberd and register users
254 if [ ! "$(grep 'public.localhost' /etc/ejabberd/ejabberd.cfg)" ]; then
256 /etc/init.d/ejabberd stop;
257 killall beam epmd; # just in case
258 cp ejabberd.cfg /root/ejabberd.cfg.orig
259 patch -p0 < $BASE_DIR/ejabberd.EG.patch
260 chown ejabberd:ejabberd ejabberd.cfg
261 /etc/init.d/ejabberd start
262 echo Return Value = $?
264 ejabberdctl register router private.localhost $JABBER_PASSWORD
265 echo Return Value = $?
266 ejabberdctl register opensrf private.localhost $JABBER_PASSWORD
267 echo Return Value = $?
268 ejabberdctl register router public.localhost $JABBER_PASSWORD
269 echo Return Value = $?
270 ejabberdctl register opensrf public.localhost $JABBER_PASSWORD
271 echo Return Value = $?
273 echo End of setting ld.so.conf and rsyslog and /etc/hosts and ejabberd =~-._
276 function build_opensrf {
277 # Build and install OpenSRF
278 echo _.-~= Building OpenSRF
280 cd /home/opensrf/OpenSRF;
282 ./configure --prefix=/openils --sysconfdir=/openils/conf;
284 su - opensrf sh -c "$OSRF_COMMAND"
285 echo Return Value = $?
286 echo End of Building OpenSRF =~-._
289 function test_opensrf_build {
290 echo _.-~= Running OpenSRF build tests
291 cd /home/opensrf/OpenSRF;
293 echo Return Value = $?
294 echo End of OpenSRF build tests =~-._
297 function install_opensrf {
298 echo _.-~= Installing OpenSRF
300 echo Return Value = $?
301 echo End of Installing OpenSRF =~-._
304 function build_evergreen {
305 echo _.-~= Building Evergreen
307 export PATH=/openils/bin:$PATH
308 cd /home/opensrf/Evergreen;
310 ./configure --prefix=/openils --sysconfdir=/openils/conf;
313 su - opensrf sh -c "$OSRF_COMMAND"
314 echo Return Value = $?
315 echo End of Building Evergreen =~-._
318 function test_evergreen_build {
319 echo _.-~= Running Evergreen build tests
320 cd /home/opensrf/Evergreen
322 echo Return Value = $?
323 echo End of Evergreen build tests =~-._
326 function install_evergreen {
327 echo _.-~= Installing Evergreen
329 echo Return Value = $?
331 cp /openils/conf/opensrf.xml.example /openils/conf/opensrf.xml
332 cp /openils/conf/opensrf_core.xml.example /openils/conf/opensrf_core.xml
334 # fetch and install Dojo
336 wget -N "http://download.dojotoolkit.org/release-$DOJO_VERSION/dojo-release-$DOJO_VERSION.tar.gz" \
337 || wget -N "http://evergreen-ils.org/~phasefx/download.dojotoolkit.org/dojo-release-$DOJO_VERSION.tar.gz"
338 tar -zxf dojo-release-$DOJO_VERSION.tar.gz;
339 cp -r dojo-release-$DOJO_VERSION/* /openils/var/web/js/dojo/;
341 # give it all to opensrf
342 chown -R opensrf:opensrf /openils
344 # copy srfsh config into place
345 cp /openils/conf/srfsh.xml.example /home/opensrf/.srfsh.xml;
346 chown opensrf:opensrf /home/opensrf/.srfsh.xml;
347 echo End of Installing Evergreen =~-._
350 function configure_database {
351 echo _.-~= configure database
353 echo "Using password evergreen for the evergreen database user."
354 echo -e "evergreen\nevergreen\n" | su - postgres sh -c 'createuser -P -s evergreen;'
356 echo -e "\n\nPlease enter a password for the evergreen database user.\n If you do not want to edit configs, use \"evergreen\"\n"
357 su - postgres sh -c 'createuser -P -s evergreen;'
360 # Apply the DB schema
361 cd /home/opensrf/Evergreen
362 perl Open-ILS/src/support-scripts/eg_db_config \
366 --update-config $SAMPLEDATA \
369 --password evergreen \
370 --hostname localhost \
371 --database evergreen \
372 --admin-user $ADMIN_USER \
373 --admin-pass $ADMIN_PASS;
374 echo Return Value = $?
376 if [ $LIVETEST ]; then
378 git clone --depth 0 https://github.com/theory/pgtap.git \
383 su - postgres -c "$PG_CMD"
384 cd /var/lib/postgresql/pgtap \
386 echo 'CREATE EXTENSION pgtap;' | su - postgres -c "psql evergreen"
388 echo configure database =~-._
391 function configure_apache {
392 echo _.-~= configure apache
393 /etc/init.d/apache2 stop
394 # Copy apache configs into place and create SSL cert
395 cd /home/opensrf/Evergreen/
396 cp Open-ILS/examples/apache/eg.conf /etc/apache2/sites-available/
397 cp Open-ILS/examples/apache/eg_vhost.conf /etc/apache2/
398 cp Open-ILS/examples/apache/eg_startup /etc/apache2/
400 mkdir -p /etc/apache2/ssl;
401 if [ ! -f /etc/apache2/ssl/server.key ] ; then
402 echo -e "\n\nConfiguring a new temporary SSL certificate....\n";
404 yes "" | openssl req -new -x509 -days 365 -nodes -out /etc/apache2/ssl/server.crt -keyout /etc/apache2/ssl/server.key
406 openssl req -new -x509 -days 365 -nodes -out /etc/apache2/ssl/server.crt -keyout /etc/apache2/ssl/server.key
409 echo -e "\nkeeping existing ssl/server.key file\n";
413 echo Return Value = $?
415 echo Return Value = $?
417 echo Return Value = $?
418 a2dissite 000-default
419 echo Return Value = $?
421 echo Return Value = $?
423 echo Modifying APACHE_RUN_USER/APACHE_RUN_GROUP in /etc/apache2/envvars
424 sed -i 's/www-data/opensrf/g' /etc/apache2/envvars
426 echo Making sure /var/lock/apache2 is owned by opensrf
427 chown opensrf:opensrf /var/lock/apache2
429 echo Modifying KeepAliveTimeout in /etc/apache2/apache2.conf
430 sed -i 's/KeepAliveTimeout .*/KeepAliveTimeout 1/' /etc/apache2/apache2.conf
432 echo End of configure apache =~-._
435 function start_evergreen {
436 echo _.-~= Starting Evergreen
437 if [ $LIVETEST ]; then
438 rm /openils/var/log/*.log
442 export LD_LIBRARY_PATH=/openils/lib:/usr/local/lib:/usr/local/lib/dbd:$LD_LIBRARY_PATH \
443 && export PATH=/openils/bin:$PATH \
444 && OSRF_HOSTNAME="dns_hack" /openils/bin/osrf_control --localhost --stop_all && sleep 3 \
445 && OSRF_HOSTNAME="dns_hack" /openils/bin/osrf_control --localhost --start_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 settings-tester.pl
467 echo _.-~= Running pgTAP live tests
468 su - postgres -c 'cd /home/opensrf/Evergreen ; pg_prove -vr -d evergreen Open-ILS/src/sql/Pg/live_t/ ; echo Return Value = $?'
469 echo End of pgTAP live tests =~-._
470 echo _.-~= Running settings-tester.pl
471 su - opensrf sh -c 'export PATH=/openils/bin:$PATH ; cd /home/opensrf/Evergreen/Open-ILS/src/support-scripts/ ; ./settings-tester.pl ; echo Return Value = $?'
472 echo End of settings-tester.pl output =~-._
473 echo _.-~= Running perl live tests
474 su - opensrf sh -c 'export PATH=/openils/bin:$PATH ; cd /home/opensrf/Evergreen/Open-ILS/src/perlmods/ ; make livecheck; echo Return Value = $?'
475 echo End of perl live tests =~-._
476 echo _.-~= Gathering log summary
479 su - opensrf sh -c 'cd /openils/var/log/ ; wc -l *.log'
482 su - opensrf sh -c 'cd /openils/var/log/ ; du -sh *.log'
484 echo 'perl -ne ''if (/^\[.*?\] (.*?) \[/) { print "$1\n"; }'' osrfsys.log | sort | uniq -c | sort -k2:'
485 (cd /openils/var/log/ ; perl -ne 'if (/^\[.*?\] (.*?) \[/) { print "$1\n"; }' osrfsys.log | sort | uniq -c | sort -k2)
487 echo End of log summary =~-._
488 echo _.-~= Gathering system information
493 echo 'select version();' | su - postgres -c 'psql -At'
495 echo '/proc/meminfo:'
498 echo '/proc/cpuinfo:'
506 echo End of system information =~-._