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
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 # -----------------------------------------------------------------------
84 # -----------------------------------------------------------------------
85 export PGDATABASE=evergreen
86 export PGUSER=evergreen
87 export PGPASSWORD=evergreen
88 export PGHOST=localhost
89 # -----------------------------------------------------------------------
90 # You can override these like so:
91 # EVERGREEN_BRANCH='master' ./eg_jessie_installer.sh
92 # -----------------------------------------------------------------------
93 OPENSRF_REPO='git://git.evergreen-ils.org/OpenSRF.git'
94 OPENSRF_BRANCH='master'
95 EVERGREEN_REPO='git://git.evergreen-ils.org/Evergreen.git'
96 EVERGREEN_BRANCH='master'
97 echo OPENSRF_REPO=${OPENSRF_REPO}
98 echo OPENSRF_BRANCH=${OPENSRF_BRANCH}
99 echo EVERGREEN_REPO=${EVERGREEN_REPO}
100 echo EVERGREEN_BRANCH=${EVERGREEN_BRANCH}
101 OPENSRF_PREREQ_TARGET=debian-jessie
102 EVERGREEN_PREREQ_TARGET=debian-jessie
103 EVERGREEN_DB_PREREQ_TARGET=postgres-server-debian-jessie
104 echo OPENSRF_PREREQ_TARGET=${OPENSRF_PREREQ_TARGET}
105 echo EVERGREEN_PREREQ_TARGET=${EVERGREEN_PREREQ_TARGET}
106 echo EVERGREEN_DB_PREREQ_TARGET=${EVERGREEN_DB_PREREQ_TARGET}
108 export NODEJS_VERSION='v6.10.1'
109 export NODEJS_BINDIR="node-$NODEJS_VERSION-linux-x64"
110 export NODEJS_TARBIN="$NODEJS_BINDIR.tar.xz"
111 export NODEJS_BINARY="https://nodejs.org/dist/$NODEJS_VERSION/$NODEJS_TARBIN"
112 echo "NODEJS_BINARY=$NODEJS_BINARY"
113 echo "NODEJS_VERSION=$NODEJS_VERSION"
115 echo End of intializing installer =~-._
119 function configure_cpan {
120 echo _.-~= configure CPAN
122 # -----------------------------------------------------------------------
123 # force CPAN to load by installing something that should already be installed
129 echo Return Value = $?
130 # CPAN follow pre-reqs?
131 if [ ! "$(echo 'o conf prerequisites_policy' | cpan | grep follow)" ]; then
134 echo "setting cpan prerequisites_policy to follow"
135 echo -e "o conf prerequisites_policy follow\\n o conf commit" | cpan
141 -----------------------------------------------------------------------
142 The install will go faster if CPAN is configured to automatically install
143 prerequisites. You can revert the action later with:
145 echo -e "o conf prerequisites_policy ask\n o conf commit" | cpan
148 echo -n 'Automatically install prereqs? [Y/n] ';
150 [ "$X" == 'n' -o "$X" == "N" ] && break;
151 if [ "$X" == 'y' -o "$X" == 'Y' ]; then
152 echo -e "o conf prerequisites_policy follow\\n o conf commit" | cpan
158 echo End of configure CPAN =~-._
161 function build_essentials {
162 echo _.-~= Installing some build essentials
164 # Install some essential tools
166 && apt-get -yq dist-upgrade \
167 && apt-get -yq install build-essential automake git psmisc ntp rsyslog lsb-release unzip;
168 echo Return Value = $?
170 if [ $LIVETEST ]; then
171 cpan TAP::Parser::SourceHandler::pgTAP
172 echo Return Value = $?
174 echo End of Installing some build essentials =~-._
177 function setting_up_opensrf_env {
178 echo _.-~= creating opensrf user and environment
180 # Create opensrf user and set up environment
181 if [ ! "$(grep ^opensrf: /etc/passwd)" ]; then
182 useradd -m -s /bin/bash opensrf
183 echo Return Value = $?
184 echo 'export PATH=/openils/bin:$PATH' >> /home/opensrf/.bashrc
185 echo 'export LD_LIBRARY_PATH=/openils/lib:/usr/local/lib:/usr/local/lib/dbd:$LD_LIBRARY_PATH' >> /home/opensrf/.bashrc
187 echo end of creating opensrf user and environment =~-._
190 function cloning_git_repos {
191 echo _.-~= cloning git repositories
195 git clone --depth 1 --branch $OPENSRF_BRANCH $OPENSRF_REPO OpenSRF;
196 git clone --depth 1 --branch $EVERGREEN_BRANCH $EVERGREEN_REPO Evergreen;
198 rm -rf /home/opensrf/Evergreen /home/opensrf/OpenSRF
199 su - opensrf sh -c "$OSRF_COMMAND";
200 echo Return Value = $?
203 cd /home/opensrf/OpenSRF/
204 echo 'Tip of OpenSRF:' `git log --format=oneline | head -1`
205 cd /home/opensrf/Evergreen/
206 echo 'Tip of Evergreen:' `git log --format=oneline | head -1`
208 echo End of cloning git repositories =~-._
211 function opensrf_prereqs {
212 echo _.-~= Installing OpenSRF pre-requisites
215 mkdir -p /usr/src/evergreen;
216 cd /usr/src/evergreen;
218 yes | make -f /home/opensrf/OpenSRF/src/extras/Makefile.install ${OPENSRF_PREREQ_TARGET}
220 make -f /home/opensrf/OpenSRF/src/extras/Makefile.install ${OPENSRF_PREREQ_TARGET}
222 echo Return Value = $?
223 echo End of Installing OpenSRF pre-requisites =~-._
226 function evergreen_prereqs {
227 echo _.-~= Installing Evergreen pre-requisites
230 yes | make -f /home/opensrf/Evergreen/Open-ILS/src/extras/Makefile.install ${EVERGREEN_PREREQ_TARGET}
232 make -f /home/opensrf/Evergreen/Open-ILS/src/extras/Makefile.install ${EVERGREEN_PREREQ_TARGET}
234 echo Return Value = $?
235 echo End of Installing Evergreen pre-requisites =~-._
238 function evergreen_db_prereqs {
239 echo _.-~= Installing Evergreen database pre-requisites
242 yes | make -f /home/opensrf/Evergreen/Open-ILS/src/extras/Makefile.install ${EVERGREEN_DB_PREREQ_TARGET}
244 make -f /home/opensrf/Evergreen/Open-ILS/src/extras/Makefile.install ${EVERGREEN_DB_PREREQ_TARGET}
246 echo Return Value = $?
247 echo End of Installing Evergreen database pre-requisites =~-._
250 function setting_ldconfig_and_rsyslog_and_hosts_and_ejabberd {
251 echo _.-~= setting ld.so.conf and rsyslog and /etc/hosts and ejabberd
253 cp $BASE_DIR/evergreen.ld.conf /etc/ld.so.conf.d/
255 echo Return Value = $?
256 # Configure rsyslog and restart
257 cp /home/opensrf/Evergreen/Open-ILS/examples/evergreen-rsyslog.conf /etc/rsyslog.d/evergreen.conf
258 /etc/init.d/rsyslog restart
259 echo Return Value = $?
260 if [ ! "$(grep 'public.localhost' /etc/hosts)" ]; then
263 echo 'Adding public.localhost and private.localhost to /etc/hosts'
264 echo '127.0.1.2 public.localhost public' >> /etc/hosts
265 echo '127.0.1.3 private.localhost private' >> /etc/hosts
270 * Add these lines to /etc/hosts.
272 127.0.1.2 public.localhost public
273 127.0.1.3 private.localhost private
279 echo "INFO: /etc/hosts already has public.localhost line";
281 echo Return Value = $?
282 # Patch Ejabberd and register users
283 if [ ! "$(grep 'public.localhost' /etc/ejabberd/ejabberd.yml)" ]; then
285 /etc/init.d/ejabberd stop;
286 killall beam epmd; # just in case
287 cp ejabberd.yml /root/ejabberd.yml.orig
288 patch -p0 < $BASE_DIR/ejabberd.EG.patch
289 chown ejabberd:ejabberd ejabberd.yml
290 echo starting ejabberd after patching
292 /etc/init.d/ejabberd start
293 echo Return Value = $?
295 ejabberdctl register router private.localhost $JABBER_PASSWORD
296 echo Return Value = $?
297 ejabberdctl register opensrf private.localhost $JABBER_PASSWORD
298 echo Return Value = $?
299 ejabberdctl register router public.localhost $JABBER_PASSWORD
300 echo Return Value = $?
301 ejabberdctl register opensrf public.localhost $JABBER_PASSWORD
302 echo Return Value = $?
304 echo End of setting ld.so.conf and rsyslog and /etc/hosts and ejabberd =~-._
307 function build_opensrf {
308 # Build and install OpenSRF
309 echo _.-~= Building OpenSRF
312 cd /home/opensrf/OpenSRF;
314 ./configure --prefix=/openils --sysconfdir=/openils/conf;
316 su - opensrf sh -c "$OSRF_COMMAND"
317 echo Return Value = $?
318 echo End of Building OpenSRF =~-._
321 function test_opensrf_build {
322 echo _.-~= Running OpenSRF build tests
324 cd /home/opensrf/OpenSRF;
326 echo Return Value = $?
327 echo End of OpenSRF build tests =~-._
330 function install_opensrf {
331 echo _.-~= Installing OpenSRF
334 echo Return Value = $?
335 echo End of Installing OpenSRF =~-._
338 function build_evergreen {
339 echo _.-~= Building Evergreen
342 export PATH=/openils/bin:$PATH
343 cd /home/opensrf/Evergreen;
345 ./configure --prefix=/openils --sysconfdir=/openils/conf;
348 su - opensrf sh -c "$OSRF_COMMAND"
349 echo Return Value = $?
350 echo End of Building Evergreen =~-._
353 function test_evergreen_build {
354 echo _.-~= Running Evergreen build tests
356 cd /home/opensrf/Evergreen
358 echo Return Value = $?
359 echo End of Evergreen build tests =~-._
363 # The evergreen browser client prereq installation and
364 # build process is not baked into Evergreen proper (yet).
365 # Run it as a standalone operation for now.
366 function test_and_build_eg_browser_client {
367 echo _.-~= Running Evergreen browser client build/test
369 wget -N $NODEJS_BINARY
370 tar xf $NODEJS_TARBIN
371 echo Return Value = $?
372 export PATH=$PATH:/home/opensrf/$NODEJS_BINDIR/bin
374 echo Return Value = $?
375 npm install -g grunt-cli # install grunt
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 = $?
380 grunt build # concatentate, minify, copy into place
381 echo Return Value = $?
382 grunt test # run JS unit tests
383 echo Return Value = $?
384 echo End of Evergreen browser client build/test =~-._
387 function install_evergreen {
388 echo _.-~= Installing Evergreen
390 cd /home/opensrf/Evergreen
392 echo Return Value = $?
394 cp /openils/conf/opensrf.xml.example /openils/conf/opensrf.xml
395 cp /openils/conf/opensrf_core.xml.example /openils/conf/opensrf_core.xml
397 # fetch and install Dojo
399 wget -N "http://download.dojotoolkit.org/release-$DOJO_VERSION/dojo-release-$DOJO_VERSION.tar.gz" \
400 || wget -N "http://evergreen-ils.org/~phasefx/download.dojotoolkit.org/dojo-release-$DOJO_VERSION.tar.gz"
401 tar -zxf dojo-release-$DOJO_VERSION.tar.gz;
402 cp -r dojo-release-$DOJO_VERSION/* /openils/var/web/js/dojo/;
404 # give it all to opensrf
405 chown -R opensrf:opensrf /openils
407 # copy srfsh config into place
408 cp /openils/conf/srfsh.xml.example /home/opensrf/.srfsh.xml;
409 chown opensrf:opensrf /home/opensrf/.srfsh.xml;
410 echo End of Installing Evergreen =~-._
413 function configure_database {
414 echo _.-~= configure database
417 echo "Using password $PGPASSWORD for the $PGUSER database user."
418 echo -e "$PGPASSWORD\n$PGPASSWORD\n" | su - postgres sh -c "createuser -P -s $PGUSER;"
420 echo -e "\n\nPlease enter a password for the $PGUSER database user.\n If you do not want to edit configs, use \"$PGPASSWORD\"\n"
421 su - postgres sh -c "createuser -P -s $PGUSER;"
424 # Apply the DB schema
425 cd /home/opensrf/Evergreen
426 perl Open-ILS/src/support-scripts/eg_db_config \
430 --update-config $SAMPLEDATA \
433 --password $PGPASSWORD \
435 --database $PGDATABASE \
436 --admin-user $ADMIN_USER \
437 --admin-pass $ADMIN_PASS;
438 echo Return Value = $?
440 if [ $LIVETEST ]; then
442 wget -N http://api.pgxn.org/dist/pgtap/$PG_TAP_VER/pgtap-$PG_TAP_VER.zip \
443 && unzip pgtap-$PG_TAP_VER.zip \
444 && cd pgtap-$PG_TAP_VER \
446 && make installcheck \
448 echo 'CREATE EXTENSION pgtap;' | su - postgres -c "psql evergreen"
450 echo configure database =~-._
453 function configure_apache {
454 echo _.-~= configure apache
456 /etc/init.d/apache2 stop
457 # Copy apache configs into place and create SSL cert
458 cd /home/opensrf/Evergreen/
459 cp Open-ILS/examples/apache_24/eg_24.conf /etc/apache2/sites-available/eg.conf
460 cp Open-ILS/examples/apache_24/eg_vhost_24.conf /etc/apache2/eg_vhost.conf
461 cp Open-ILS/examples/apache/eg_startup /etc/apache2/
463 mkdir -p /etc/apache2/ssl;
464 if [ ! -f /etc/apache2/ssl/server.key ] ; then
465 echo -e "\n\nConfiguring a new temporary SSL certificate....\n";
467 yes "" | openssl req -new -x509 -days 365 -nodes -out /etc/apache2/ssl/server.crt -keyout /etc/apache2/ssl/server.key
469 openssl req -new -x509 -days 365 -nodes -out /etc/apache2/ssl/server.crt -keyout /etc/apache2/ssl/server.key
472 echo -e "\nkeeping existing ssl/server.key file\n";
476 echo Return Value = $?
478 echo Return Value = $?
480 echo Return Value = $?
481 a2dissite 000-default
482 echo Return Value = $?
484 echo Return Value = $?
486 echo Modifying APACHE_RUN_USER/APACHE_RUN_GROUP in /etc/apache2/envvars
487 sed -i 's/www-data/opensrf/g' /etc/apache2/envvars
489 echo Making sure /var/lock/apache2 is owned by opensrf
490 chown opensrf:opensrf /var/lock/apache2
492 echo Modifying KeepAliveTimeout in /etc/apache2/apache2.conf
493 sed -i 's/KeepAliveTimeout .*/KeepAliveTimeout 1/' /etc/apache2/apache2.conf
495 echo End of configure apache =~-._
498 function start_evergreen {
499 echo _.-~= Starting Evergreen
501 if [ $LIVETEST ]; then
502 rm /openils/var/log/*.log
506 export LD_LIBRARY_PATH=/openils/lib:/usr/local/lib:/usr/local/lib/dbd:$LD_LIBRARY_PATH \
507 && export PATH=/openils/bin:$PATH \
508 && OSRF_HOSTNAME="dns_hack" /openils/bin/osrf_control --localhost --restart-all && sleep 3 \
509 && /openils/bin/autogen.sh /openils/conf/opensrf_core.xml \
512 echo Starting services...
513 su - opensrf sh -c "$OSRF_COMMAND";
514 echo Return Value = $?
516 echo Restarting Apache
517 /etc/init.d/apache2 restart
518 echo Return Value = $?
520 echo End of Starting Evergreen =~-._
523 function test_evergreen_live {
524 # TODO: Eventually move these tests into a Make target within Evergreen
525 cd /home/opensrf/Evergreen
526 echo _.-~= Running pgTAP tests
528 su - postgres -c 'cd /home/opensrf/Evergreen ; pg_prove -vr -d evergreen Open-ILS/src/sql/Pg/t/ ; echo Return Value = $?'
529 echo End of pgTAP tests =~-._
530 echo _.-~= Running pgTAP live tests
532 su - postgres -c 'cd /home/opensrf/Evergreen ; pg_prove -vr -d evergreen Open-ILS/src/sql/Pg/live_t/ ; echo Return Value = $?'
533 echo End of pgTAP live tests =~-._
534 echo _.-~= Running settings-tester.pl
536 su - opensrf sh -c 'export PATH=/openils/bin:$PATH ; cd /home/opensrf/Evergreen/Open-ILS/src/support-scripts/ ; ./settings-tester.pl ; echo Return Value = $?'
537 echo End of settings-tester.pl output =~-._
538 echo _.-~= Running perl live tests
540 su - opensrf sh -c 'export PATH=/openils/bin:$PATH ; cd /home/opensrf/Evergreen/Open-ILS/src/perlmods/ ; make livecheck; echo Return Value = $?'
541 echo End of perl live tests =~-._
542 echo _.-~= Gathering log summary
546 su - opensrf sh -c 'cd /openils/var/log/ ; wc -l *.log'
549 su - opensrf sh -c 'cd /openils/var/log/ ; du -sh *.log'
551 echo 'perl -ne ''if (/^\[.*?\] (.*?) \[/) { print "$1\n"; }'' osrfsys.log | sort | uniq -c | sort -k2:'
552 (cd /openils/var/log/ ; perl -ne 'if (/^\[.*?\] (.*?) \[/) { print "$1\n"; }' osrfsys.log | sort | uniq -c | sort -k2)
554 echo End of log summary =~-._
557 echo _.-~= Log Output: $x
562 echo _.-~= Gathering system information
567 echo 'select version();' | su - postgres -c 'psql -At'
569 echo '/proc/meminfo:'
572 echo '/proc/cpuinfo:'
579 cpan -l 2> /dev/null | sort
580 echo End of system information =~-._