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 # -----------------------------------------------------------------------
83 # You can override these like so:
84 # EVERGREEN_BRANCH='master' ./eg_jessie_installer.sh
85 # -----------------------------------------------------------------------
86 OPENSRF_REPO='git://git.evergreen-ils.org/OpenSRF.git'
87 OPENSRF_BRANCH='master'
88 EVERGREEN_REPO='git://git.evergreen-ils.org/Evergreen.git'
89 EVERGREEN_BRANCH='master'
90 echo OPENSRF_REPO=${OPENSRF_REPO}
91 echo OPENSRF_BRANCH=${OPENSRF_BRANCH}
92 echo EVERGREEN_REPO=${EVERGREEN_REPO}
93 echo EVERGREEN_BRANCH=${EVERGREEN_BRANCH}
94 OPENSRF_PREREQ_TARGET=debian-jessie
95 EVERGREEN_PREREQ_TARGET=debian-jessie
96 EVERGREEN_DB_PREREQ_TARGET=postgres-server-debian-jessie
97 echo OPENSRF_PREREQ_TARGET=${OPENSRF_PREREQ_TARGET}
98 echo EVERGREEN_PREREQ_TARGET=${EVERGREEN_PREREQ_TARGET}
99 echo EVERGREEN_DB_PREREQ_TARGET=${EVERGREEN_DB_PREREQ_TARGET}
101 export NODEJS_REPO='https://github.com/joyent/node.git'
102 export NODEJS_VERSION='v0.10.35'
103 echo "NODEJS_REPO=$NODEJS_REPO"
104 echo "NODEJS_VERSION=$NODEJS_VERSION"
106 echo End of intializing installer =~-._
110 function configure_cpan {
111 echo _.-~= configure CPAN
113 # -----------------------------------------------------------------------
114 # force CPAN to load by installing something that should already be installed
120 echo Return Value = $?
121 # CPAN follow pre-reqs?
122 if [ ! "$(echo 'o conf prerequisites_policy' | cpan | grep follow)" ]; then
125 echo "setting cpan prerequisites_policy to follow"
126 echo -e "o conf prerequisites_policy follow\\n o conf commit" | cpan
132 -----------------------------------------------------------------------
133 The install will go faster if CPAN is configured to automatically install
134 prerequisites. You can revert the action later with:
136 echo -e "o conf prerequisites_policy ask\n o conf commit" | cpan
139 echo -n 'Automatically install prereqs? [Y/n] ';
141 [ "$X" == 'n' -o "$X" == "N" ] && break;
142 if [ "$X" == 'y' -o "$X" == 'Y' ]; then
143 echo -e "o conf prerequisites_policy follow\\n o conf commit" | cpan
149 echo End of configure CPAN =~-._
152 function build_essentials {
153 echo _.-~= Installing some build essentials
155 # Install some essential tools
157 && apt-get -yq dist-upgrade \
158 && apt-get -yq install build-essential automake git psmisc ntp rsyslog lsb-release unzip;
159 echo Return Value = $?
161 if [ $LIVETEST ]; then
162 cpan TAP::Parser::SourceHandler::pgTAP
163 echo Return Value = $?
165 echo End of Installing some build essentials =~-._
168 function setting_up_opensrf_env {
169 echo _.-~= creating opensrf user and environment
171 # Create opensrf user and set up environment
172 if [ ! "$(grep ^opensrf: /etc/passwd)" ]; then
173 useradd -m -s /bin/bash opensrf
174 echo Return Value = $?
175 echo 'export PATH=/openils/bin:$PATH' >> /home/opensrf/.bashrc
176 echo 'export LD_LIBRARY_PATH=/openils/lib:/usr/local/lib:/usr/local/lib/dbd:$LD_LIBRARY_PATH' >> /home/opensrf/.bashrc
178 echo end of creating opensrf user and environment =~-._
181 function cloning_git_repos {
182 echo _.-~= cloning git repositories
186 git clone --depth 1 --branch $OPENSRF_BRANCH $OPENSRF_REPO OpenSRF;
187 git clone --depth 1 --branch $EVERGREEN_BRANCH $EVERGREEN_REPO Evergreen;
189 rm -rf /home/opensrf/Evergreen /home/opensrf/OpenSRF
190 su - opensrf sh -c "$OSRF_COMMAND";
191 echo Return Value = $?
194 cd /home/opensrf/OpenSRF/
195 echo 'Tip of OpenSRF:' `git log --format=oneline | head -1`
196 cd /home/opensrf/Evergreen/
197 echo 'Tip of Evergreen:' `git log --format=oneline | head -1`
199 echo End of cloning git repositories =~-._
202 function opensrf_prereqs {
203 echo _.-~= Installing OpenSRF pre-requisites
206 mkdir -p /usr/src/evergreen;
207 cd /usr/src/evergreen;
209 yes | make -f /home/opensrf/OpenSRF/src/extras/Makefile.install ${OPENSRF_PREREQ_TARGET}
211 make -f /home/opensrf/OpenSRF/src/extras/Makefile.install ${OPENSRF_PREREQ_TARGET}
213 echo Return Value = $?
214 echo End of Installing OpenSRF pre-requisites =~-._
217 function evergreen_prereqs {
218 echo _.-~= Installing Evergreen pre-requisites
221 yes | make -f /home/opensrf/Evergreen/Open-ILS/src/extras/Makefile.install ${EVERGREEN_PREREQ_TARGET}
223 make -f /home/opensrf/Evergreen/Open-ILS/src/extras/Makefile.install ${EVERGREEN_PREREQ_TARGET}
225 echo Return Value = $?
226 echo End of Installing Evergreen pre-requisites =~-._
229 function evergreen_db_prereqs {
230 echo _.-~= Installing Evergreen database pre-requisites
233 yes | make -f /home/opensrf/Evergreen/Open-ILS/src/extras/Makefile.install ${EVERGREEN_DB_PREREQ_TARGET}
235 make -f /home/opensrf/Evergreen/Open-ILS/src/extras/Makefile.install ${EVERGREEN_DB_PREREQ_TARGET}
237 echo Return Value = $?
238 echo End of Installing Evergreen database pre-requisites =~-._
241 function setting_ldconfig_and_rsyslog_and_hosts_and_ejabberd {
242 echo _.-~= setting ld.so.conf and rsyslog and /etc/hosts and ejabberd
244 cp $BASE_DIR/evergreen.ld.conf /etc/ld.so.conf.d/
246 echo Return Value = $?
247 # Configure rsyslog and restart
248 cp /home/opensrf/Evergreen/Open-ILS/examples/evergreen-rsyslog.conf /etc/rsyslog.d/evergreen.conf
249 /etc/init.d/rsyslog restart
250 echo Return Value = $?
251 if [ ! "$(grep 'public.localhost' /etc/hosts)" ]; then
254 echo 'Adding public.localhost and private.localhost to /etc/hosts'
255 echo '127.0.1.2 public.localhost public' >> /etc/hosts
256 echo '127.0.1.3 private.localhost private' >> /etc/hosts
261 * Add these lines to /etc/hosts.
263 127.0.1.2 public.localhost public
264 127.0.1.3 private.localhost private
270 echo "INFO: /etc/hosts already has public.localhost line";
272 echo Return Value = $?
273 # Patch Ejabberd and register users
274 if [ ! "$(grep 'public.localhost' /etc/ejabberd/ejabberd.yml)" ]; then
276 /etc/init.d/ejabberd stop;
277 killall beam epmd; # just in case
278 cp ejabberd.yml /root/ejabberd.yml.orig
279 patch -p0 < $BASE_DIR/ejabberd.EG.patch
280 chown ejabberd:ejabberd ejabberd.yml
281 echo starting ejabberd after patching
283 /etc/init.d/ejabberd start
284 echo Return Value = $?
286 ejabberdctl register router private.localhost $JABBER_PASSWORD
287 echo Return Value = $?
288 ejabberdctl register opensrf private.localhost $JABBER_PASSWORD
289 echo Return Value = $?
290 ejabberdctl register router public.localhost $JABBER_PASSWORD
291 echo Return Value = $?
292 ejabberdctl register opensrf public.localhost $JABBER_PASSWORD
293 echo Return Value = $?
295 echo End of setting ld.so.conf and rsyslog and /etc/hosts and ejabberd =~-._
298 function build_opensrf {
299 # Build and install OpenSRF
300 echo _.-~= Building OpenSRF
303 cd /home/opensrf/OpenSRF;
305 ./configure --prefix=/openils --sysconfdir=/openils/conf;
307 su - opensrf sh -c "$OSRF_COMMAND"
308 echo Return Value = $?
309 echo End of Building OpenSRF =~-._
312 function test_opensrf_build {
313 echo _.-~= Running OpenSRF build tests
315 cd /home/opensrf/OpenSRF;
317 echo Return Value = $?
318 echo End of OpenSRF build tests =~-._
321 function install_opensrf {
322 echo _.-~= Installing OpenSRF
325 echo Return Value = $?
326 echo End of Installing OpenSRF =~-._
329 function build_evergreen {
330 echo _.-~= Building Evergreen
333 export PATH=/openils/bin:$PATH
334 cd /home/opensrf/Evergreen;
336 ./configure --prefix=/openils --sysconfdir=/openils/conf;
339 su - opensrf sh -c "$OSRF_COMMAND"
340 echo Return Value = $?
341 echo End of Building Evergreen =~-._
344 function test_evergreen_build {
345 echo _.-~= Running Evergreen build tests
347 cd /home/opensrf/Evergreen
349 echo Return Value = $?
350 echo End of Evergreen build tests =~-._
354 # The evergreen browser client prereq installation and
355 # build process is not baked into Evergreen proper (yet).
356 # Run it as a standalone operation for now.
357 function test_and_build_eg_browser_client {
358 echo _.-~= Running Evergreen browser client build/test
360 git clone $NODEJS_REPO
362 git checkout -b $NODEJS_VERSION $NODEJS_VERSION
363 ./configure && make -j2 && make install
364 echo Return Value = $?
366 echo Return Value = $?
367 npm install -g grunt-cli # install grunt
368 echo Return Value = $?
369 npm install -g bower # install bower
370 echo Return Value = $?
371 cd /home/opensrf/Evergreen/Open-ILS/web/js/ui/default/staff
372 npm install # fetch build depencies
373 echo Return Value = $?
375 # fetch JS/CSS/etc prereqs
377 # yes == allow sending package stats
378 yes | bower --allow-root install
380 bower --allow-root install
382 echo Return Value = $?
384 grunt build # concatentate, minify, copy into place
385 echo Return Value = $?
386 grunt test # run JS unit tests
387 echo Return Value = $?
388 echo End of Evergreen browser client build/test =~-._
391 function install_evergreen {
392 echo _.-~= Installing Evergreen
394 cd /home/opensrf/Evergreen
396 echo Return Value = $?
398 cp /openils/conf/opensrf.xml.example /openils/conf/opensrf.xml
399 cp /openils/conf/opensrf_core.xml.example /openils/conf/opensrf_core.xml
401 # fetch and install Dojo
403 wget -N "http://download.dojotoolkit.org/release-$DOJO_VERSION/dojo-release-$DOJO_VERSION.tar.gz" \
404 || wget -N "http://evergreen-ils.org/~phasefx/download.dojotoolkit.org/dojo-release-$DOJO_VERSION.tar.gz"
405 tar -zxf dojo-release-$DOJO_VERSION.tar.gz;
406 cp -r dojo-release-$DOJO_VERSION/* /openils/var/web/js/dojo/;
408 # give it all to opensrf
409 chown -R opensrf:opensrf /openils
411 # copy srfsh config into place
412 cp /openils/conf/srfsh.xml.example /home/opensrf/.srfsh.xml;
413 chown opensrf:opensrf /home/opensrf/.srfsh.xml;
414 echo End of Installing Evergreen =~-._
417 function configure_database {
418 echo _.-~= configure database
421 echo "Using password evergreen for the evergreen database user."
422 echo -e "evergreen\nevergreen\n" | su - postgres sh -c 'createuser -P -s evergreen;'
424 echo -e "\n\nPlease enter a password for the evergreen database user.\n If you do not want to edit configs, use \"evergreen\"\n"
425 su - postgres sh -c 'createuser -P -s evergreen;'
428 # Apply the DB schema
429 cd /home/opensrf/Evergreen
430 perl Open-ILS/src/support-scripts/eg_db_config \
434 --update-config $SAMPLEDATA \
437 --password evergreen \
438 --hostname localhost \
439 --database evergreen \
440 --admin-user $ADMIN_USER \
441 --admin-pass $ADMIN_PASS;
442 echo Return Value = $?
444 if [ $LIVETEST ]; then
447 wget http://api.pgxn.org/dist/pgtap/$PG_TAP_VER/pgtap-$PG_TAP_VER.zip \
448 && unzip pgtap-$PG_TAP_VER.zip \
449 && cd pgtap-$PG_TAP_VER \
453 su - postgres -c "$PG_CMD"
454 cd /var/lib/postgresql/pgtap \
456 echo 'CREATE EXTENSION pgtap;' | su - postgres -c "psql evergreen"
458 echo configure database =~-._
461 function configure_apache {
462 echo _.-~= configure apache
464 /etc/init.d/apache2 stop
465 # Copy apache configs into place and create SSL cert
466 cd /home/opensrf/Evergreen/
467 cp Open-ILS/examples/apache_24/eg_24.conf /etc/apache2/sites-available/eg.conf
468 cp Open-ILS/examples/apache_24/eg_vhost_24.conf /etc/apache2/eg_vhost.conf
469 cp Open-ILS/examples/apache/eg_startup /etc/apache2/
471 mkdir -p /etc/apache2/ssl;
472 if [ ! -f /etc/apache2/ssl/server.key ] ; then
473 echo -e "\n\nConfiguring a new temporary SSL certificate....\n";
475 yes "" | openssl req -new -x509 -days 365 -nodes -out /etc/apache2/ssl/server.crt -keyout /etc/apache2/ssl/server.key
477 openssl req -new -x509 -days 365 -nodes -out /etc/apache2/ssl/server.crt -keyout /etc/apache2/ssl/server.key
480 echo -e "\nkeeping existing ssl/server.key file\n";
484 echo Return Value = $?
486 echo Return Value = $?
488 echo Return Value = $?
489 a2dissite 000-default
490 echo Return Value = $?
492 echo Return Value = $?
494 echo Modifying APACHE_RUN_USER/APACHE_RUN_GROUP in /etc/apache2/envvars
495 sed -i 's/www-data/opensrf/g' /etc/apache2/envvars
497 echo Making sure /var/lock/apache2 is owned by opensrf
498 chown opensrf:opensrf /var/lock/apache2
500 echo Modifying KeepAliveTimeout in /etc/apache2/apache2.conf
501 sed -i 's/KeepAliveTimeout .*/KeepAliveTimeout 1/' /etc/apache2/apache2.conf
503 echo End of configure apache =~-._
506 function start_evergreen {
507 echo _.-~= Starting Evergreen
509 if [ $LIVETEST ]; then
510 rm /openils/var/log/*.log
514 export LD_LIBRARY_PATH=/openils/lib:/usr/local/lib:/usr/local/lib/dbd:$LD_LIBRARY_PATH \
515 && export PATH=/openils/bin:$PATH \
516 && OSRF_HOSTNAME="dns_hack" /openils/bin/osrf_control --localhost --restart-all && sleep 3 \
517 && /openils/bin/autogen.sh /openils/conf/opensrf_core.xml \
520 echo Starting services...
521 su - opensrf sh -c "$OSRF_COMMAND";
522 echo Return Value = $?
524 echo Restarting Apache
525 /etc/init.d/apache2 restart
526 echo Return Value = $?
528 echo End of Starting Evergreen =~-._
531 function test_evergreen_live {
532 # TODO: Eventually move these tests into a Make target within Evergreen
533 cd /home/opensrf/Evergreen
534 echo _.-~= Running pgTAP tests
536 su - postgres -c 'cd /home/opensrf/Evergreen ; pg_prove -vr -d evergreen Open-ILS/src/sql/Pg/t/ ; echo Return Value = $?'
537 echo End of pgTAP tests =~-._
538 echo _.-~= Running pgTAP live tests
540 su - postgres -c 'cd /home/opensrf/Evergreen ; pg_prove -vr -d evergreen Open-ILS/src/sql/Pg/live_t/ ; echo Return Value = $?'
541 echo End of pgTAP live tests =~-._
542 echo _.-~= Running settings-tester.pl
544 su - opensrf sh -c 'export PATH=/openils/bin:$PATH ; cd /home/opensrf/Evergreen/Open-ILS/src/support-scripts/ ; ./settings-tester.pl ; echo Return Value = $?'
545 echo End of settings-tester.pl output =~-._
546 echo _.-~= Running perl live tests
548 su - opensrf sh -c 'export PATH=/openils/bin:$PATH ; cd /home/opensrf/Evergreen/Open-ILS/src/perlmods/ ; make livecheck; echo Return Value = $?'
549 echo End of perl live tests =~-._
550 echo _.-~= Gathering log summary
554 su - opensrf sh -c 'cd /openils/var/log/ ; wc -l *.log'
557 su - opensrf sh -c 'cd /openils/var/log/ ; du -sh *.log'
559 echo 'perl -ne ''if (/^\[.*?\] (.*?) \[/) { print "$1\n"; }'' osrfsys.log | sort | uniq -c | sort -k2:'
560 (cd /openils/var/log/ ; perl -ne 'if (/^\[.*?\] (.*?) \[/) { print "$1\n"; }' osrfsys.log | sort | uniq -c | sort -k2)
562 echo End of log summary =~-._
565 echo _.-~= Log Output: $x
570 echo _.-~= Gathering system information
575 echo 'select version();' | su - postgres -c 'psql -At'
577 echo '/proc/meminfo:'
580 echo '/proc/cpuinfo:'
587 cpan -l 2> /dev/null | sort
588 echo End of system information =~-._