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
45 test_and_build_eg_browser_client
49 if [ $AUTOSTART ]; then
55 function init_variables {
56 echo _.-~= initializing installer
58 # -----------------------------------------------------------------------
59 # Handling passed arguments to the script
60 # -----------------------------------------------------------------------
61 export DOJO_VERSION='1.3.3';
62 export PATH=/openils/bin:$PATH
63 export LD_LIBRARY_PATH=/openils/lib:/usr/local/lib:/usr/local/lib/dbd:$LD_LIBRARY_PATH
65 echo AUTOSTART=${AUTOSTART}
67 echo SAMPLEDATA=${SAMPLEDATA}
68 echo LIVETEST=${LIVETEST}
69 echo DOJO_VERSION=${DOJO_VERSION}
71 echo LD_LIBRARY_PATH=${LD_LIBRARY_PATH}
72 echo BASE_DIR=${BASE_DIR}
73 # -----------------------------------------------------------------------
75 # -----------------------------------------------------------------------
76 # If you change the jabber password, you will need to
77 # edit opensrf_core.xml and srfsh.xml accordingly
78 export JABBER_PASSWORD='password'
79 export ADMIN_USER='admin';
80 export ADMIN_PASS='demo123';
81 # -----------------------------------------------------------------------
82 # You can override these like so:
83 # EVERGREEN_BRANCH='master' ./eg_wheezy_installer.sh
84 # -----------------------------------------------------------------------
85 OPENSRF_REPO='git://git.evergreen-ils.org/OpenSRF.git'
86 OPENSRF_BRANCH='master'
87 EVERGREEN_REPO='git://git.evergreen-ils.org/working/Evergreen.git'
88 EVERGREEN_BRANCH='collab/phasefx/lp1350042-grid-print-and-show-all-cols'
89 echo OPENSRF_REPO=${OPENSRF_REPO}
90 echo OPENSRF_BRANCH=${OPENSRF_BRANCH}
91 echo EVERGREEN_REPO=${EVERGREEN_REPO}
92 echo EVERGREEN_BRANCH=${EVERGREEN_BRANCH}
93 OPENSRF_PREREQ_TARGET=debian-wheezy
94 EVERGREEN_PREREQ_TARGET=debian-wheezy
95 EVERGREEN_DB_PREREQ_TARGET=postgres-server-debian-wheezy
96 echo OPENSRF_PREREQ_TARGET=${OPENSRF_PREREQ_TARGET}
97 echo EVERGREEN_PREREQ_TARGET=${EVERGREEN_PREREQ_TARGET}
98 echo EVERGREEN_DB_PREREQ_TARGET=${EVERGREEN_DB_PREREQ_TARGET}
100 export NODEJS_REPO='https://github.com/joyent/node.git'
101 export NODEJS_VERSION='v0.10.31'
102 echo "NODEJS_REPO=$NODEJS_REPO"
103 echo "NODEJS_VERSION=$NODEJS_VERSION"
105 echo End of intializing installer =~-._
108 function configure_timezone {
109 echo _.-~= configure timezone
111 # should be America/New_York
112 perl -e 'print "2\n\n104\n";' | dpkg-reconfigure -fteletype tzdata
113 echo End of configure timezone =~-._
116 function configure_cpan {
117 echo _.-~= configure CPAN
119 # -----------------------------------------------------------------------
120 # force CPAN to load by installing something that should already be installed
126 echo Return Value = $?
127 # CPAN follow pre-reqs?
128 if [ ! "$(echo 'o conf prerequisites_policy' | cpan | grep follow)" ]; then
131 echo "setting cpan prerequisites_policy to follow"
132 echo -e "o conf prerequisites_policy follow\\n o conf commit" | cpan
138 -----------------------------------------------------------------------
139 The install will go faster if CPAN is configured to automatically install
140 prerequisites. You can revert the action later with:
142 echo -e "o conf prerequisites_policy ask\n o conf commit" | cpan
145 echo -n 'Automatically install prereqs? [Y/n] ';
147 [ "$X" == 'n' -o "$X" == "N" ] && break;
148 if [ "$X" == 'y' -o "$X" == 'Y' ]; then
149 echo -e "o conf prerequisites_policy follow\\n o conf commit" | cpan
155 echo End of configure CPAN =~-._
158 function build_essentials {
159 echo _.-~= Installing some build essentials
161 # Install some essential tools
163 && apt-get -yq dist-upgrade \
164 && apt-get -yq install build-essential automake git psmisc ntp rsyslog;
165 echo Return Value = $?
167 if [ $LIVETEST ]; then
168 cpan TAP::Parser::SourceHandler::pgTAP
169 echo Return Value = $?
171 echo End of Installing some build essentials =~-._
174 function setting_up_opensrf_env {
175 echo _.-~= creating opensrf user and environment
177 # Create opensrf user and set up environment
178 if [ ! "$(grep ^opensrf: /etc/passwd)" ]; then
179 useradd -m -s /bin/bash opensrf
180 echo Return Value = $?
181 echo 'export PATH=/openils/bin:$PATH' >> /home/opensrf/.bashrc
182 echo 'export LD_LIBRARY_PATH=/openils/lib:/usr/local/lib:/usr/local/lib/dbd:$LD_LIBRARY_PATH' >> /home/opensrf/.bashrc
184 echo end of creating opensrf user and environment =~-._
187 function cloning_git_repos {
188 echo _.-~= cloning git repositories
192 git clone --depth 0 --branch $OPENSRF_BRANCH $OPENSRF_REPO OpenSRF;
193 git clone --depth 0 --branch $EVERGREEN_BRANCH $EVERGREEN_REPO Evergreen;
195 rm -rf /home/opensrf/Evergreen /home/opensrf/OpenSRF
196 su - opensrf sh -c "$OSRF_COMMAND";
197 echo Return Value = $?
200 cd /home/opensrf/OpenSRF/
201 echo 'Tip of OpenSRF:' `git log --format=oneline | head -1`
202 cd /home/opensrf/Evergreen/
203 echo 'Tip of Evergreen:' `git log --format=oneline | head -1`
205 echo End of cloning git repositories =~-._
208 function opensrf_prereqs {
209 echo _.-~= Installing OpenSRF pre-requisites
212 mkdir -p /usr/src/evergreen;
213 cd /usr/src/evergreen;
215 yes | make -f /home/opensrf/OpenSRF/src/extras/Makefile.install ${OPENSRF_PREREQ_TARGET}
217 make -f /home/opensrf/OpenSRF/src/extras/Makefile.install ${OPENSRF_PREREQ_TARGET}
219 echo Return Value = $?
220 echo End of Installing OpenSRF pre-requisites =~-._
223 function evergreen_prereqs {
224 echo _.-~= Installing Evergreen pre-requisites
227 yes | make -f /home/opensrf/Evergreen/Open-ILS/src/extras/Makefile.install ${EVERGREEN_PREREQ_TARGET}
229 make -f /home/opensrf/Evergreen/Open-ILS/src/extras/Makefile.install ${EVERGREEN_PREREQ_TARGET}
231 echo Return Value = $?
232 echo End of Installing Evergreen pre-requisites =~-._
235 function evergreen_db_prereqs {
236 echo _.-~= Installing Evergreen database pre-requisites
239 yes | make -f /home/opensrf/Evergreen/Open-ILS/src/extras/Makefile.install ${EVERGREEN_DB_PREREQ_TARGET}
241 make -f /home/opensrf/Evergreen/Open-ILS/src/extras/Makefile.install ${EVERGREEN_DB_PREREQ_TARGET}
243 echo Return Value = $?
244 echo End of Installing Evergreen database pre-requisites =~-._
247 function setting_ldconfig_and_rsyslog_and_hosts_and_ejabberd {
248 echo _.-~= setting ld.so.conf and rsyslog and /etc/hosts and ejabberd
250 cp $BASE_DIR/evergreen.ld.conf /etc/ld.so.conf.d/
252 echo Return Value = $?
253 # Configure rsyslog and restart
254 cp /home/opensrf/Evergreen/Open-ILS/examples/evergreen-rsyslog.conf /etc/rsyslog.d/evergreen.conf
255 /etc/init.d/rsyslog restart
256 echo Return Value = $?
257 if [ ! "$(grep 'public.localhost' /etc/hosts)" ]; then
260 echo 'Adding public.localhost and private.localhost to /etc/hosts'
261 echo '127.0.1.2 public.localhost public' >> /etc/hosts
262 echo '127.0.1.3 private.localhost private' >> /etc/hosts
267 * Add these lines to /etc/hosts.
269 127.0.1.2 public.localhost public
270 127.0.1.3 private.localhost private
276 echo "INFO: /etc/hosts already has public.localhost line";
278 echo Return Value = $?
279 # Patch Ejabberd and register users
280 if [ ! "$(grep 'public.localhost' /etc/ejabberd/ejabberd.cfg)" ]; then
282 /etc/init.d/ejabberd stop;
283 killall beam epmd; # just in case
284 cp ejabberd.cfg /root/ejabberd.cfg.orig
285 patch -p0 < $BASE_DIR/ejabberd.EG.patch
286 chown ejabberd:ejabberd ejabberd.cfg
287 echo starting ejabberd after patching
289 /etc/init.d/ejabberd start
290 echo Return Value = $?
292 ejabberdctl register router private.localhost $JABBER_PASSWORD
293 echo Return Value = $?
294 ejabberdctl register opensrf private.localhost $JABBER_PASSWORD
295 echo Return Value = $?
296 ejabberdctl register router public.localhost $JABBER_PASSWORD
297 echo Return Value = $?
298 ejabberdctl register opensrf public.localhost $JABBER_PASSWORD
299 echo Return Value = $?
301 echo End of setting ld.so.conf and rsyslog and /etc/hosts and ejabberd =~-._
304 function build_opensrf {
305 # Build and install OpenSRF
306 echo _.-~= Building OpenSRF
309 cd /home/opensrf/OpenSRF;
311 ./configure --prefix=/openils --sysconfdir=/openils/conf;
313 su - opensrf sh -c "$OSRF_COMMAND"
314 echo Return Value = $?
315 echo End of Building OpenSRF =~-._
318 function test_opensrf_build {
319 echo _.-~= Running OpenSRF build tests
321 cd /home/opensrf/OpenSRF;
323 echo Return Value = $?
324 echo End of OpenSRF build tests =~-._
327 function install_opensrf {
328 echo _.-~= Installing OpenSRF
331 echo Return Value = $?
332 echo End of Installing OpenSRF =~-._
335 function build_evergreen {
336 echo _.-~= Building Evergreen
339 export PATH=/openils/bin:$PATH
340 cd /home/opensrf/Evergreen;
342 ./configure --prefix=/openils --sysconfdir=/openils/conf;
345 su - opensrf sh -c "$OSRF_COMMAND"
346 echo Return Value = $?
347 echo End of Building Evergreen =~-._
350 function test_evergreen_build {
351 echo _.-~= Running Evergreen build tests
353 cd /home/opensrf/Evergreen
355 echo Return Value = $?
356 echo End of Evergreen build tests =~-._
360 # The evergreen browser client prereq installation and
361 # build process is not baked into Evergreen proper (yet).
362 # Run it as a standalone operation for now.
363 function test_and_build_eg_browser_client {
364 echo _.-~= Running Evergreen browser client build/test
366 git clone $NODEJS_REPO
368 git checkout -b $NODEJS_VERSION $NODEJS_VERSION
369 ./configure && make -j2 && make install
370 echo Return Value = $?
372 echo Return Value = $?
373 npm install -g grunt-cli # install grunt
374 echo Return Value = $?
375 npm install -g bower # install bower
376 echo Return Value = $?
377 cd /home/opensrf/Evergreen/Open-ILS/web/js/ui/default/staff
378 npm install # fetch build depencies
379 echo Return Value = $?
381 # fetch JS/CSS/etc prereqs
383 # yes == allow sending package stats
384 yes | bower --allow-root install
386 bower --allow-root install
388 echo Return Value = $?
390 grunt build # concatentate, minify, copy into place
391 echo Return Value = $?
392 grunt test # run JS unit tests
393 echo Return Value = $?
394 echo End of Evergreen browser client build/test =~-._
397 function install_evergreen {
398 echo _.-~= Installing Evergreen
400 cd /home/opensrf/Evergreen
402 echo Return Value = $?
404 cp /openils/conf/opensrf.xml.example /openils/conf/opensrf.xml
405 cp /openils/conf/opensrf_core.xml.example /openils/conf/opensrf_core.xml
407 # fetch and install Dojo
409 wget -N "http://download.dojotoolkit.org/release-$DOJO_VERSION/dojo-release-$DOJO_VERSION.tar.gz" \
410 || wget -N "http://evergreen-ils.org/~phasefx/download.dojotoolkit.org/dojo-release-$DOJO_VERSION.tar.gz"
411 tar -zxf dojo-release-$DOJO_VERSION.tar.gz;
412 cp -r dojo-release-$DOJO_VERSION/* /openils/var/web/js/dojo/;
414 # give it all to opensrf
415 chown -R opensrf:opensrf /openils
417 # copy srfsh config into place
418 cp /openils/conf/srfsh.xml.example /home/opensrf/.srfsh.xml;
419 chown opensrf:opensrf /home/opensrf/.srfsh.xml;
420 echo End of Installing Evergreen =~-._
423 function configure_database {
424 echo _.-~= configure database
427 echo "Using password evergreen for the evergreen database user."
428 echo -e "evergreen\nevergreen\n" | su - postgres sh -c 'createuser -P -s evergreen;'
430 echo -e "\n\nPlease enter a password for the evergreen database user.\n If you do not want to edit configs, use \"evergreen\"\n"
431 su - postgres sh -c 'createuser -P -s evergreen;'
434 # Apply the DB schema
435 cd /home/opensrf/Evergreen
436 perl Open-ILS/src/support-scripts/eg_db_config \
440 --update-config $SAMPLEDATA \
443 --password evergreen \
444 --hostname localhost \
445 --database evergreen \
446 --admin-user $ADMIN_USER \
447 --admin-pass $ADMIN_PASS;
448 echo Return Value = $?
450 if [ $LIVETEST ]; then
452 git clone --depth 0 https://github.com/theory/pgtap.git \
457 su - postgres -c "$PG_CMD"
458 cd /var/lib/postgresql/pgtap \
460 echo 'CREATE EXTENSION pgtap;' | su - postgres -c "psql evergreen"
462 echo configure database =~-._
465 function configure_apache {
466 echo _.-~= configure apache
468 /etc/init.d/apache2 stop
469 # Copy apache configs into place and create SSL cert
470 cd /home/opensrf/Evergreen/
471 cp Open-ILS/examples/apache/eg.conf /etc/apache2/sites-available/
472 cp Open-ILS/examples/apache/eg_vhost.conf /etc/apache2/
473 cp Open-ILS/examples/apache/eg_startup /etc/apache2/
475 mkdir -p /etc/apache2/ssl;
476 if [ ! -f /etc/apache2/ssl/server.key ] ; then
477 echo -e "\n\nConfiguring a new temporary SSL certificate....\n";
479 yes "" | openssl req -new -x509 -days 365 -nodes -out /etc/apache2/ssl/server.crt -keyout /etc/apache2/ssl/server.key
481 openssl req -new -x509 -days 365 -nodes -out /etc/apache2/ssl/server.crt -keyout /etc/apache2/ssl/server.key
484 echo -e "\nkeeping existing ssl/server.key file\n";
488 echo Return Value = $?
490 echo Return Value = $?
492 echo Return Value = $?
493 a2dissite 000-default
494 echo Return Value = $?
496 echo Return Value = $?
498 echo Modifying APACHE_RUN_USER/APACHE_RUN_GROUP in /etc/apache2/envvars
499 sed -i 's/www-data/opensrf/g' /etc/apache2/envvars
501 echo Making sure /var/lock/apache2 is owned by opensrf
502 chown opensrf:opensrf /var/lock/apache2
504 echo Modifying KeepAliveTimeout in /etc/apache2/apache2.conf
505 sed -i 's/KeepAliveTimeout .*/KeepAliveTimeout 1/' /etc/apache2/apache2.conf
507 echo End of configure apache =~-._
510 function start_evergreen {
511 echo _.-~= Starting Evergreen
513 if [ $LIVETEST ]; then
514 rm /openils/var/log/*.log
518 export LD_LIBRARY_PATH=/openils/lib:/usr/local/lib:/usr/local/lib/dbd:$LD_LIBRARY_PATH \
519 && export PATH=/openils/bin:$PATH \
520 && OSRF_HOSTNAME="dns_hack" /openils/bin/osrf_control --localhost --restart-all && sleep 3 \
521 && /openils/bin/autogen.sh /openils/conf/opensrf_core.xml \
524 echo Starting services...
525 su - opensrf sh -c "$OSRF_COMMAND";
526 echo Return Value = $?
528 echo Restarting Apache
529 /etc/init.d/apache2 restart
530 echo Return Value = $?
532 echo End of Starting Evergreen =~-._
535 function test_evergreen_live {
536 # TODO: Eventually move these tests into a Make target within Evergreen
537 cd /home/opensrf/Evergreen
538 echo _.-~= Running pgTAP tests
540 su - postgres -c 'cd /home/opensrf/Evergreen ; pg_prove -vr -d evergreen Open-ILS/src/sql/Pg/t/ ; echo Return Value = $?'
541 echo End of pgTAP tests =~-._
542 echo _.-~= Running pgTAP live tests
544 su - postgres -c 'cd /home/opensrf/Evergreen ; pg_prove -vr -d evergreen Open-ILS/src/sql/Pg/live_t/ ; echo Return Value = $?'
545 echo End of pgTAP live tests =~-._
546 echo _.-~= Running settings-tester.pl
548 su - opensrf sh -c 'export PATH=/openils/bin:$PATH ; cd /home/opensrf/Evergreen/Open-ILS/src/support-scripts/ ; ./settings-tester.pl ; echo Return Value = $?'
549 echo End of settings-tester.pl output =~-._
550 echo _.-~= Running perl live tests
552 su - opensrf sh -c 'export PATH=/openils/bin:$PATH ; cd /home/opensrf/Evergreen/Open-ILS/src/perlmods/ ; make livecheck; echo Return Value = $?'
553 echo End of perl live tests =~-._
554 echo _.-~= Gathering log summary
558 su - opensrf sh -c 'cd /openils/var/log/ ; wc -l *.log'
561 su - opensrf sh -c 'cd /openils/var/log/ ; du -sh *.log'
563 echo 'perl -ne ''if (/^\[.*?\] (.*?) \[/) { print "$1\n"; }'' osrfsys.log | sort | uniq -c | sort -k2:'
564 (cd /openils/var/log/ ; perl -ne 'if (/^\[.*?\] (.*?) \[/) { print "$1\n"; }' osrfsys.log | sort | uniq -c | sort -k2)
566 echo End of log summary =~-._
569 echo _.-~= Log Output: $x
574 echo _.-~= Gathering system information
579 echo 'select version();' | su - postgres -c 'psql -At'
581 echo '/proc/meminfo:'
584 echo '/proc/cpuinfo:'
591 cpan -l 2> /dev/null | sort
592 echo End of system information =~-._