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
51 if [ $LIVETEST ]; then
59 function init_variables {
60 echo _.-~= initializing installer
62 # -----------------------------------------------------------------------
63 # Handling passed arguments to the script
64 # -----------------------------------------------------------------------
65 export DOJO_VERSION='1.3.3';
66 export PATH=/openils/bin:$PATH
67 export LD_LIBRARY_PATH=/openils/lib:/usr/local/lib:/usr/local/lib/dbd:$LD_LIBRARY_PATH
69 echo AUTOSTART=${AUTOSTART}
71 echo SAMPLEDATA=${SAMPLEDATA}
72 echo LIVETEST=${LIVETEST}
73 echo DOJO_VERSION=${DOJO_VERSION}
75 echo LD_LIBRARY_PATH=${LD_LIBRARY_PATH}
76 echo BASE_DIR=${BASE_DIR}
77 # -----------------------------------------------------------------------
79 # -----------------------------------------------------------------------
80 # If you change the jabber password, you will need to
81 # edit opensrf_core.xml and srfsh.xml accordingly
82 export JABBER_PASSWORD='password'
83 export ADMIN_USER='admin';
84 export ADMIN_PASS='demo123';
85 # -----------------------------------------------------------------------
87 # -----------------------------------------------------------------------
88 export PGDATABASE=evergreen
89 export PGUSER=evergreen
90 export PGPASSWORD=evergreen
91 export PGHOST=localhost
92 # -----------------------------------------------------------------------
93 # You can override these like so:
94 # EVERGREEN_BRANCH='master' ./eg_wheezy_installer.sh
95 # -----------------------------------------------------------------------
96 OPENSRF_REPO='git://git.evergreen-ils.org/OpenSRF.git'
97 OPENSRF_BRANCH='master'
98 EVERGREEN_REPO='git://git.evergreen-ils.org/Evergreen.git'
99 EVERGREEN_BRANCH='master'
100 echo OPENSRF_REPO=${OPENSRF_REPO}
101 echo OPENSRF_BRANCH=${OPENSRF_BRANCH}
102 echo EVERGREEN_REPO=${EVERGREEN_REPO}
103 echo EVERGREEN_BRANCH=${EVERGREEN_BRANCH}
104 OPENSRF_PREREQ_TARGET=debian-wheezy
105 EVERGREEN_PREREQ_TARGET=debian-wheezy
106 EVERGREEN_DB_PREREQ_TARGET=postgres-server-debian-wheezy
107 echo OPENSRF_PREREQ_TARGET=${OPENSRF_PREREQ_TARGET}
108 echo EVERGREEN_PREREQ_TARGET=${EVERGREEN_PREREQ_TARGET}
109 echo EVERGREEN_DB_PREREQ_TARGET=${EVERGREEN_DB_PREREQ_TARGET}
111 export NODEJS_VERSION='v8.11.4'
112 export NODEJS_BINDIR="node-$NODEJS_VERSION-linux-x64"
113 export NODEJS_TARBIN="$NODEJS_BINDIR.tar.xz"
114 export NODEJS_BINARY="https://nodejs.org/dist/$NODEJS_VERSION/$NODEJS_TARBIN"
115 echo "NODEJS_BINARY=$NODEJS_BINARY"
116 echo "NODEJS_VERSION=$NODEJS_VERSION"
118 echo End of intializing installer =~-._
121 function configure_timezone {
122 echo _.-~= configure timezone
124 # should be America/New_York
125 perl -e 'print "2\n\n104\n";' | dpkg-reconfigure -fteletype tzdata
126 echo End of configure timezone =~-._
129 function configure_cpan {
130 echo _.-~= configure CPAN
132 # -----------------------------------------------------------------------
133 # force CPAN to load by installing something that should already be installed
139 echo Return Value = $?
140 # CPAN follow pre-reqs?
141 if [ ! "$(echo 'o conf prerequisites_policy' | cpan | grep follow)" ]; then
144 echo "setting cpan prerequisites_policy to follow"
145 echo -e "o conf prerequisites_policy follow\\n o conf commit" | cpan
151 -----------------------------------------------------------------------
152 The install will go faster if CPAN is configured to automatically install
153 prerequisites. You can revert the action later with:
155 echo -e "o conf prerequisites_policy ask\n o conf commit" | cpan
158 echo -n 'Automatically install prereqs? [Y/n] ';
160 [ "$X" == 'n' -o "$X" == "N" ] && break;
161 if [ "$X" == 'y' -o "$X" == 'Y' ]; then
162 echo -e "o conf prerequisites_policy follow\\n o conf commit" | cpan
168 echo End of configure CPAN =~-._
171 function build_essentials {
172 echo _.-~= Installing some build essentials
174 # Install some essential tools
176 && apt-get -yq dist-upgrade \
177 && apt-get -yq install build-essential automake git psmisc ntp rsyslog lsb-release unzip;
178 echo Return Value = $?
180 if [ $LIVETEST ]; then
181 cpan TAP::Parser::SourceHandler::pgTAP
182 echo Return Value = $?
184 echo End of Installing some build essentials =~-._
187 function docs_builder_prereqs {
188 echo _.-~= Installing prereqs for building the documentation formats
190 # Install tools used for building the docs
191 apt-get -yq install asciidoc source-highlight fop;
192 echo Return Value = $?
194 echo End of Installing prereqs for building the documentation formats =~-._
197 function build_the_docs {
198 echo _.-~= Building the AsciiDoc output formats
201 su - opensrf sh -c 'cd /home/opensrf/Evergreen/docs/ ; asciidoc root.adoc ; echo Return Value = $?'
203 su - opensrf sh -c 'cd /home/opensrf/Evergreen/docs/ ; a2x --fop --fop-opts="-q" root.adoc ; echo Return Value = $?'
205 su - opensrf sh -c 'cd /home/opensrf/Evergreen/docs/ ; a2x --no-xmllint --format epub root.adoc ; echo Return Value = $?'
207 echo End of Building the AsciiDoc output formats =~-._
210 function setting_up_opensrf_env {
211 echo _.-~= creating opensrf user and environment
213 # Create opensrf user and set up environment
214 if [ ! "$(grep ^opensrf: /etc/passwd)" ]; then
215 useradd -m -s /bin/bash opensrf
216 echo Return Value = $?
217 echo 'export PATH=/openils/bin:$PATH' >> /home/opensrf/.bashrc
218 echo 'export LD_LIBRARY_PATH=/openils/lib:/usr/local/lib:/usr/local/lib/dbd:$LD_LIBRARY_PATH' >> /home/opensrf/.bashrc
220 echo end of creating opensrf user and environment =~-._
223 function cloning_git_repos {
224 echo _.-~= cloning git repositories
228 git clone --depth 0 --branch $OPENSRF_BRANCH $OPENSRF_REPO OpenSRF;
229 git clone --depth 0 --branch $EVERGREEN_BRANCH $EVERGREEN_REPO Evergreen;
231 rm -rf /home/opensrf/Evergreen /home/opensrf/OpenSRF
232 su - opensrf sh -c "$OSRF_COMMAND";
233 echo Return Value = $?
236 cd /home/opensrf/OpenSRF/
237 echo 'Tip of OpenSRF:' `git log --format=oneline | head -1`
238 cd /home/opensrf/Evergreen/
239 echo 'Tip of Evergreen:' `git log --format=oneline | head -1`
241 echo End of cloning git repositories =~-._
244 function opensrf_prereqs {
245 echo _.-~= Installing OpenSRF pre-requisites
248 mkdir -p /usr/src/evergreen;
249 cd /usr/src/evergreen;
251 yes | make -f /home/opensrf/OpenSRF/src/extras/Makefile.install ${OPENSRF_PREREQ_TARGET}
253 make -f /home/opensrf/OpenSRF/src/extras/Makefile.install ${OPENSRF_PREREQ_TARGET}
255 echo Return Value = $?
256 echo End of Installing OpenSRF pre-requisites =~-._
259 function evergreen_prereqs {
260 echo _.-~= Installing Evergreen pre-requisites
263 yes | make -f /home/opensrf/Evergreen/Open-ILS/src/extras/Makefile.install ${EVERGREEN_PREREQ_TARGET}
265 make -f /home/opensrf/Evergreen/Open-ILS/src/extras/Makefile.install ${EVERGREEN_PREREQ_TARGET}
267 echo Return Value = $?
268 echo End of Installing Evergreen pre-requisites =~-._
271 function evergreen_db_prereqs {
272 echo _.-~= Installing Evergreen database pre-requisites
275 yes | make -f /home/opensrf/Evergreen/Open-ILS/src/extras/Makefile.install ${EVERGREEN_DB_PREREQ_TARGET}
277 make -f /home/opensrf/Evergreen/Open-ILS/src/extras/Makefile.install ${EVERGREEN_DB_PREREQ_TARGET}
279 echo Return Value = $?
280 echo End of Installing Evergreen database pre-requisites =~-._
283 function setting_ldconfig_and_rsyslog_and_hosts_and_ejabberd {
284 echo _.-~= setting ld.so.conf and rsyslog and /etc/hosts and ejabberd
286 cp $BASE_DIR/evergreen.ld.conf /etc/ld.so.conf.d/
288 echo Return Value = $?
289 # Configure rsyslog and restart
290 cp /home/opensrf/Evergreen/Open-ILS/examples/evergreen-rsyslog.conf /etc/rsyslog.d/evergreen.conf
291 /etc/init.d/rsyslog restart
292 echo Return Value = $?
293 if [ ! "$(grep 'public.localhost' /etc/hosts)" ]; then
296 echo 'Adding public.localhost and private.localhost to /etc/hosts'
297 echo '127.0.1.2 public.localhost public' >> /etc/hosts
298 echo '127.0.1.3 private.localhost private' >> /etc/hosts
303 * Add these lines to /etc/hosts.
305 127.0.1.2 public.localhost public
306 127.0.1.3 private.localhost private
312 echo "INFO: /etc/hosts already has public.localhost line";
314 echo Return Value = $?
315 # Patch Ejabberd and register users
316 if [ ! "$(grep 'public.localhost' /etc/ejabberd/ejabberd.cfg)" ]; then
318 /etc/init.d/ejabberd stop;
319 killall beam epmd; # just in case
320 cp ejabberd.cfg /root/ejabberd.cfg.orig
321 patch -p0 < $BASE_DIR/ejabberd.EG.patch
322 chown ejabberd:ejabberd ejabberd.cfg
323 echo starting ejabberd after patching
325 /etc/init.d/ejabberd start
326 echo Return Value = $?
328 ejabberdctl register router private.localhost $JABBER_PASSWORD
329 echo Return Value = $?
330 ejabberdctl register opensrf private.localhost $JABBER_PASSWORD
331 echo Return Value = $?
332 ejabberdctl register router public.localhost $JABBER_PASSWORD
333 echo Return Value = $?
334 ejabberdctl register opensrf public.localhost $JABBER_PASSWORD
335 echo Return Value = $?
337 echo End of setting ld.so.conf and rsyslog and /etc/hosts and ejabberd =~-._
340 function build_opensrf {
341 # Build and install OpenSRF
342 echo _.-~= Building OpenSRF
345 cd /home/opensrf/OpenSRF;
347 ./configure --prefix=/openils --sysconfdir=/openils/conf;
349 su - opensrf sh -c "$OSRF_COMMAND"
350 echo Return Value = $?
351 echo End of Building OpenSRF =~-._
354 function test_opensrf_build {
355 echo _.-~= Running OpenSRF build tests
357 cd /home/opensrf/OpenSRF;
359 echo Return Value = $?
360 echo End of OpenSRF build tests =~-._
363 function install_opensrf {
364 echo _.-~= Installing OpenSRF
367 echo Return Value = $?
368 echo End of Installing OpenSRF =~-._
371 function build_evergreen {
372 echo _.-~= Building Evergreen
375 export PATH=/openils/bin:$PATH
376 cd /home/opensrf/Evergreen;
378 ./configure --prefix=/openils --sysconfdir=/openils/conf;
381 su - opensrf sh -c "$OSRF_COMMAND"
382 echo Return Value = $?
383 echo End of Building Evergreen =~-._
386 function test_evergreen_build {
387 echo _.-~= Running Evergreen build tests
389 cd /home/opensrf/Evergreen
391 echo Return Value = $?
392 echo End of Evergreen build tests =~-._
396 # The evergreen browser client prereq installation and
397 # build process is not baked into Evergreen proper (yet).
398 # Run it as a standalone operation for now.
399 function test_and_build_eg_browser_client {
400 echo _.-~= Running Evergreen browser client build/test
401 cd /home/opensrf && pwd
402 wget -N $NODEJS_BINARY
403 tar xf $NODEJS_TARBIN
404 echo Return Value = $?
405 export PATH=$PATH:/home/opensrf/$NODEJS_BINDIR/bin
406 echo Return Value = $?
407 echo Running npm update
409 echo Return Value = $?
410 echo Running npm i npm@latest -g
412 echo Return Value = $?
413 echo Running npm audit
415 echo Return Value = $?
416 cd /home/opensrf/Evergreen/Open-ILS/web/js/ui/default/staff && pwd
417 echo Running npm install
418 npm install # fetch build depencies
419 echo Return Value = $?
420 echo Running npm run build
421 npm run build # copy into place; use build-prod for concatenation
422 echo Return Value = $?
423 echo Running npm test
424 npm run test # run JS unit tests
425 echo Return Value = $?
426 cd /home/opensrf/Evergreen/Open-ILS/src/eg2/ && pwd
427 echo Running npm install
428 npm install # fetch build depencies
429 echo Return Value = $?
430 echo Running ng build --prod
431 ng build --prod # for ang6
432 echo Return Value = $?
433 echo Running npm test
434 npm run test # run JS unit tests
435 echo Return Value = $?
436 echo End of Evergreen browser client build/test =~-._
439 function install_evergreen {
440 echo _.-~= Installing Evergreen
442 cd /home/opensrf/Evergreen
444 echo Return Value = $?
446 cp /openils/conf/opensrf.xml.example /openils/conf/opensrf.xml
447 cp /openils/conf/opensrf_core.xml.example /openils/conf/opensrf_core.xml
449 # fetch and install Dojo
451 wget -N "http://download.dojotoolkit.org/release-$DOJO_VERSION/dojo-release-$DOJO_VERSION.tar.gz" \
452 || wget -N "http://evergreen-ils.org/~phasefx/download.dojotoolkit.org/dojo-release-$DOJO_VERSION.tar.gz"
453 tar -zxf dojo-release-$DOJO_VERSION.tar.gz;
454 cp -r dojo-release-$DOJO_VERSION/* /openils/var/web/js/dojo/;
456 # give it all to opensrf
457 chown -R opensrf:opensrf /openils
459 # copy srfsh config into place
460 cp /openils/conf/srfsh.xml.example /home/opensrf/.srfsh.xml;
461 chown opensrf:opensrf /home/opensrf/.srfsh.xml;
462 echo End of Installing Evergreen =~-._
465 function configure_database {
466 echo _.-~= configure database
469 echo "Using password $PGPASSWORD for the $PGUSER database user."
470 echo -e "$PGPASSWORD\n$PGPASSWORD\n" | su - postgres sh -c "createuser -P -s $PGUSER;"
472 echo -e "\n\nPlease enter a password for the $PGUSER database user.\n If you do not want to edit configs, use \"$PGPASSWORD\"\n"
473 su - postgres sh -c "createuser -P -s $PGUSER;"
476 # Apply the DB schema
477 cd /home/opensrf/Evergreen
478 perl Open-ILS/src/support-scripts/eg_db_config \
482 --update-config $SAMPLEDATA \
485 --password $PGPASSWORD \
487 --database $PGDATABASE \
488 --admin-user $ADMIN_USER \
489 --admin-pass $ADMIN_PASS;
490 echo Return Value = $?
492 if [ $LIVETEST ]; then
494 wget -N http://api.pgxn.org/dist/pgtap/$PG_TAP_VER/pgtap-$PG_TAP_VER.zip \
495 && unzip pgtap-$PG_TAP_VER.zip \
496 && cd pgtap-$PG_TAP_VER \
498 && make installcheck \
500 echo 'CREATE EXTENSION pgtap;' | su - postgres -c "psql evergreen"
502 echo configure database =~-._
505 function configure_apache {
506 echo _.-~= configure apache
508 /etc/init.d/apache2 stop
509 # Copy apache configs into place and create SSL cert
510 cd /home/opensrf/Evergreen/
511 cp Open-ILS/examples/apache/eg.conf /etc/apache2/sites-available/
512 cp Open-ILS/examples/apache/eg_vhost.conf /etc/apache2/
513 cp Open-ILS/examples/apache/eg_startup /etc/apache2/
515 mkdir -p /etc/apache2/ssl;
516 if [ ! -f /etc/apache2/ssl/server.key ] ; then
517 echo -e "\n\nConfiguring a new temporary SSL certificate....\n";
519 yes "" | openssl req -new -x509 -days 365 -nodes -out /etc/apache2/ssl/server.crt -keyout /etc/apache2/ssl/server.key
521 openssl req -new -x509 -days 365 -nodes -out /etc/apache2/ssl/server.crt -keyout /etc/apache2/ssl/server.key
524 echo -e "\nkeeping existing ssl/server.key file\n";
528 echo Return Value = $?
530 echo Return Value = $?
532 echo Return Value = $?
533 a2dissite 000-default
534 echo Return Value = $?
536 echo Return Value = $?
538 echo Modifying APACHE_RUN_USER/APACHE_RUN_GROUP in /etc/apache2/envvars
539 sed -i 's/www-data/opensrf/g' /etc/apache2/envvars
541 echo Making sure /var/lock/apache2 is owned by opensrf
542 chown opensrf:opensrf /var/lock/apache2
544 echo Modifying KeepAliveTimeout in /etc/apache2/apache2.conf
545 sed -i 's/KeepAliveTimeout .*/KeepAliveTimeout 1/' /etc/apache2/apache2.conf
547 echo End of configure apache =~-._
550 function start_evergreen {
551 echo _.-~= Starting Evergreen
553 if [ $LIVETEST ]; then
554 rm /openils/var/log/*.log
558 export LD_LIBRARY_PATH=/openils/lib:/usr/local/lib:/usr/local/lib/dbd:$LD_LIBRARY_PATH \
559 && export PATH=/openils/bin:$PATH \
560 && OSRF_HOSTNAME="dns_hack" /openils/bin/osrf_control --localhost --restart-all && sleep 3 \
561 && /openils/bin/autogen.sh /openils/conf/opensrf_core.xml \
564 echo Starting services...
565 su - opensrf sh -c "$OSRF_COMMAND";
566 echo Return Value = $?
568 echo Restarting Apache
569 /etc/init.d/apache2 restart
570 echo Return Value = $?
572 echo End of Starting Evergreen =~-._
575 function test_evergreen_live {
576 # TODO: Eventually move these tests into a Make target within Evergreen
577 cd /home/opensrf/Evergreen
578 echo _.-~= Running pgTAP tests
580 su - postgres -c 'cd /home/opensrf/Evergreen ; pg_prove -vr -d evergreen Open-ILS/src/sql/Pg/t/ ; echo Return Value = $?'
581 echo End of pgTAP tests =~-._
582 echo _.-~= Running pgTAP live tests
584 su - postgres -c 'cd /home/opensrf/Evergreen ; pg_prove -vr -d evergreen Open-ILS/src/sql/Pg/live_t/ ; echo Return Value = $?'
585 echo End of pgTAP live tests =~-._
586 echo _.-~= Running settings-tester.pl
588 su - opensrf sh -c 'export PATH=/openils/bin:$PATH ; cd /home/opensrf/Evergreen/Open-ILS/src/support-scripts/ ; ./settings-tester.pl ; echo Return Value = $?'
589 echo End of settings-tester.pl output =~-._
590 echo _.-~= Running perl live tests
592 su - opensrf sh -c 'export PATH=/openils/bin:$PATH ; cd /home/opensrf/Evergreen/Open-ILS/src/perlmods/ ; make livecheck; echo Return Value = $?'
593 echo End of perl live tests =~-._
594 echo _.-~= Gathering log summary
598 su - opensrf sh -c 'cd /openils/var/log/ ; wc -l *.log'
601 su - opensrf sh -c 'cd /openils/var/log/ ; du -sh *.log'
603 echo 'perl -ne ''if (/^\[.*?\] (.*?) \[/) { print "$1\n"; }'' osrfsys.log | sort | uniq -c | sort -k2:'
604 (cd /openils/var/log/ ; perl -ne 'if (/^\[.*?\] (.*?) \[/) { print "$1\n"; }' osrfsys.log | sort | uniq -c | sort -k2)
606 echo End of log summary =~-._
609 echo _.-~= Log Output: $x
614 echo _.-~= Gathering system information
619 echo 'select version();' | su - postgres -c 'psql -At'
621 echo '/proc/meminfo:'
624 echo '/proc/cpuinfo:'
631 cpan -l 2> /dev/null | sort
632 echo End of system information =~-._