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
57 function init_variables {
58 echo _.-~= initializing installer
60 # -----------------------------------------------------------------------
61 # Handling passed arguments to the script
62 # -----------------------------------------------------------------------
63 export DOJO_VERSION='1.3.3';
64 export PATH=/openils/bin:$PATH
65 export LD_LIBRARY_PATH=/openils/lib:/usr/local/lib:/usr/local/lib/dbd:$LD_LIBRARY_PATH
67 echo AUTOSTART=${AUTOSTART}
69 echo SAMPLEDATA=${SAMPLEDATA}
70 echo LIVETEST=${LIVETEST}
71 echo DOJO_VERSION=${DOJO_VERSION}
73 echo LD_LIBRARY_PATH=${LD_LIBRARY_PATH}
74 echo BASE_DIR=${BASE_DIR}
75 # -----------------------------------------------------------------------
77 # -----------------------------------------------------------------------
78 # If you change the jabber password, you will need to
79 # edit opensrf_core.xml and srfsh.xml accordingly
80 export JABBER_PASSWORD='password'
81 export ADMIN_USER='admin';
82 export ADMIN_PASS='demo123';
83 # -----------------------------------------------------------------------
84 # You can override these like so:
85 # EVERGREEN_BRANCH='master' ./eg_wheezy_installer.sh
86 # -----------------------------------------------------------------------
87 OPENSRF_REPO='git://git.evergreen-ils.org/OpenSRF.git'
88 OPENSRF_BRANCH='master'
89 EVERGREEN_REPO='git://git.evergreen-ils.org/Evergreen.git'
90 EVERGREEN_BRANCH='master'
91 echo OPENSRF_REPO=${OPENSRF_REPO}
92 echo OPENSRF_BRANCH=${OPENSRF_BRANCH}
93 echo EVERGREEN_REPO=${EVERGREEN_REPO}
94 echo EVERGREEN_BRANCH=${EVERGREEN_BRANCH}
95 OPENSRF_PREREQ_TARGET=debian-wheezy
96 EVERGREEN_PREREQ_TARGET=debian-wheezy
97 EVERGREEN_DB_PREREQ_TARGET=postgres-server-debian-wheezy
98 echo OPENSRF_PREREQ_TARGET=${OPENSRF_PREREQ_TARGET}
99 echo EVERGREEN_PREREQ_TARGET=${EVERGREEN_PREREQ_TARGET}
100 echo EVERGREEN_DB_PREREQ_TARGET=${EVERGREEN_DB_PREREQ_TARGET}
102 export NODEJS_REPO='https://github.com/joyent/node.git'
103 export NODEJS_VERSION='v0.10.35'
104 echo "NODEJS_REPO=$NODEJS_REPO"
105 echo "NODEJS_VERSION=$NODEJS_VERSION"
107 echo End of intializing installer =~-._
110 function configure_timezone {
111 echo _.-~= configure timezone
113 # should be America/New_York
114 perl -e 'print "2\n\n104\n";' | dpkg-reconfigure -fteletype tzdata
115 echo End of configure timezone =~-._
118 function configure_cpan {
119 echo _.-~= configure CPAN
121 # -----------------------------------------------------------------------
122 # force CPAN to load by installing something that should already be installed
128 echo Return Value = $?
129 # CPAN follow pre-reqs?
130 if [ ! "$(echo 'o conf prerequisites_policy' | cpan | grep follow)" ]; then
133 echo "setting cpan prerequisites_policy to follow"
134 echo -e "o conf prerequisites_policy follow\\n o conf commit" | cpan
140 -----------------------------------------------------------------------
141 The install will go faster if CPAN is configured to automatically install
142 prerequisites. You can revert the action later with:
144 echo -e "o conf prerequisites_policy ask\n o conf commit" | cpan
147 echo -n 'Automatically install prereqs? [Y/n] ';
149 [ "$X" == 'n' -o "$X" == "N" ] && break;
150 if [ "$X" == 'y' -o "$X" == 'Y' ]; then
151 echo -e "o conf prerequisites_policy follow\\n o conf commit" | cpan
157 echo End of configure CPAN =~-._
160 function build_essentials {
161 echo _.-~= Installing some build essentials
163 # Install some essential tools
165 && apt-get -yq dist-upgrade \
166 && apt-get -yq install build-essential automake git psmisc ntp rsyslog lsb-release unzip;
167 echo Return Value = $?
169 if [ $LIVETEST ]; then
170 cpan TAP::Parser::SourceHandler::pgTAP
171 echo Return Value = $?
173 echo End of Installing some build essentials =~-._
176 function setting_up_opensrf_env {
177 echo _.-~= creating opensrf user and environment
179 # Create opensrf user and set up environment
180 if [ ! "$(grep ^opensrf: /etc/passwd)" ]; then
181 useradd -m -s /bin/bash opensrf
182 echo Return Value = $?
183 echo 'export PATH=/openils/bin:$PATH' >> /home/opensrf/.bashrc
184 echo 'export LD_LIBRARY_PATH=/openils/lib:/usr/local/lib:/usr/local/lib/dbd:$LD_LIBRARY_PATH' >> /home/opensrf/.bashrc
186 echo end of creating opensrf user and environment =~-._
189 function cloning_git_repos {
190 echo _.-~= cloning git repositories
194 git clone --depth 0 --branch $OPENSRF_BRANCH $OPENSRF_REPO OpenSRF;
195 git clone --depth 0 --branch $EVERGREEN_BRANCH $EVERGREEN_REPO Evergreen;
197 rm -rf /home/opensrf/Evergreen /home/opensrf/OpenSRF
198 su - opensrf sh -c "$OSRF_COMMAND";
199 echo Return Value = $?
202 cd /home/opensrf/OpenSRF/
203 echo 'Tip of OpenSRF:' `git log --format=oneline | head -1`
204 cd /home/opensrf/Evergreen/
205 echo 'Tip of Evergreen:' `git log --format=oneline | head -1`
207 echo End of cloning git repositories =~-._
210 function opensrf_prereqs {
211 echo _.-~= Installing OpenSRF pre-requisites
214 mkdir -p /usr/src/evergreen;
215 cd /usr/src/evergreen;
217 yes | make -f /home/opensrf/OpenSRF/src/extras/Makefile.install ${OPENSRF_PREREQ_TARGET}
219 make -f /home/opensrf/OpenSRF/src/extras/Makefile.install ${OPENSRF_PREREQ_TARGET}
221 echo Return Value = $?
222 echo End of Installing OpenSRF pre-requisites =~-._
225 function evergreen_prereqs {
226 echo _.-~= Installing Evergreen pre-requisites
229 yes | make -f /home/opensrf/Evergreen/Open-ILS/src/extras/Makefile.install ${EVERGREEN_PREREQ_TARGET}
231 make -f /home/opensrf/Evergreen/Open-ILS/src/extras/Makefile.install ${EVERGREEN_PREREQ_TARGET}
233 echo Return Value = $?
234 echo End of Installing Evergreen pre-requisites =~-._
237 function evergreen_db_prereqs {
238 echo _.-~= Installing Evergreen database pre-requisites
241 yes | make -f /home/opensrf/Evergreen/Open-ILS/src/extras/Makefile.install ${EVERGREEN_DB_PREREQ_TARGET}
243 make -f /home/opensrf/Evergreen/Open-ILS/src/extras/Makefile.install ${EVERGREEN_DB_PREREQ_TARGET}
245 echo Return Value = $?
246 echo End of Installing Evergreen database pre-requisites =~-._
249 function setting_ldconfig_and_rsyslog_and_hosts_and_ejabberd {
250 echo _.-~= setting ld.so.conf and rsyslog and /etc/hosts and ejabberd
252 cp $BASE_DIR/evergreen.ld.conf /etc/ld.so.conf.d/
254 echo Return Value = $?
255 # Configure rsyslog and restart
256 cp /home/opensrf/Evergreen/Open-ILS/examples/evergreen-rsyslog.conf /etc/rsyslog.d/evergreen.conf
257 /etc/init.d/rsyslog restart
258 echo Return Value = $?
259 if [ ! "$(grep 'public.localhost' /etc/hosts)" ]; then
262 echo 'Adding public.localhost and private.localhost to /etc/hosts'
263 echo '127.0.1.2 public.localhost public' >> /etc/hosts
264 echo '127.0.1.3 private.localhost private' >> /etc/hosts
269 * Add these lines to /etc/hosts.
271 127.0.1.2 public.localhost public
272 127.0.1.3 private.localhost private
278 echo "INFO: /etc/hosts already has public.localhost line";
280 echo Return Value = $?
281 # Patch Ejabberd and register users
282 if [ ! "$(grep 'public.localhost' /etc/ejabberd/ejabberd.cfg)" ]; then
284 /etc/init.d/ejabberd stop;
285 killall beam epmd; # just in case
286 cp ejabberd.cfg /root/ejabberd.cfg.orig
287 patch -p0 < $BASE_DIR/ejabberd.EG.patch
288 chown ejabberd:ejabberd ejabberd.cfg
289 echo starting ejabberd after patching
291 /etc/init.d/ejabberd start
292 echo Return Value = $?
294 ejabberdctl register router private.localhost $JABBER_PASSWORD
295 echo Return Value = $?
296 ejabberdctl register opensrf private.localhost $JABBER_PASSWORD
297 echo Return Value = $?
298 ejabberdctl register router public.localhost $JABBER_PASSWORD
299 echo Return Value = $?
300 ejabberdctl register opensrf public.localhost $JABBER_PASSWORD
301 echo Return Value = $?
303 echo End of setting ld.so.conf and rsyslog and /etc/hosts and ejabberd =~-._
306 function build_opensrf {
307 # Build and install OpenSRF
308 echo _.-~= Building OpenSRF
311 cd /home/opensrf/OpenSRF;
313 ./configure --prefix=/openils --sysconfdir=/openils/conf;
315 su - opensrf sh -c "$OSRF_COMMAND"
316 echo Return Value = $?
317 echo End of Building OpenSRF =~-._
320 function test_opensrf_build {
321 echo _.-~= Running OpenSRF build tests
323 cd /home/opensrf/OpenSRF;
325 echo Return Value = $?
326 echo End of OpenSRF build tests =~-._
329 function install_opensrf {
330 echo _.-~= Installing OpenSRF
333 echo Return Value = $?
334 echo End of Installing OpenSRF =~-._
337 function build_evergreen {
338 echo _.-~= Building Evergreen
341 export PATH=/openils/bin:$PATH
342 cd /home/opensrf/Evergreen;
344 ./configure --prefix=/openils --sysconfdir=/openils/conf;
347 su - opensrf sh -c "$OSRF_COMMAND"
348 echo Return Value = $?
349 echo End of Building Evergreen =~-._
352 function test_evergreen_build {
353 echo _.-~= Running Evergreen build tests
355 cd /home/opensrf/Evergreen
357 echo Return Value = $?
358 echo End of Evergreen build tests =~-._
362 # The evergreen browser client prereq installation and
363 # build process is not baked into Evergreen proper (yet).
364 # Run it as a standalone operation for now.
365 function test_and_build_eg_browser_client {
366 echo _.-~= Running Evergreen browser client build/test
368 git clone $NODEJS_REPO
370 git checkout -b $NODEJS_VERSION $NODEJS_VERSION
371 ./configure && make -j2 && make install
372 echo Return Value = $?
374 echo Return Value = $?
375 npm install -g grunt-cli # install grunt
376 echo Return Value = $?
377 npm install -g bower # install bower
378 echo Return Value = $?
379 cd /home/opensrf/Evergreen/Open-ILS/web/js/ui/default/staff
380 npm install # fetch build depencies
381 echo Return Value = $?
383 # fetch JS/CSS/etc prereqs
385 # yes == allow sending package stats
386 yes | bower --allow-root install
388 bower --allow-root install
390 echo Return Value = $?
392 grunt build # concatentate, minify, copy into place
393 echo Return Value = $?
394 grunt test # run JS unit tests
395 echo Return Value = $?
396 echo End of Evergreen browser client build/test =~-._
399 function install_evergreen {
400 echo _.-~= Installing Evergreen
402 cd /home/opensrf/Evergreen
404 echo Return Value = $?
406 cp /openils/conf/opensrf.xml.example /openils/conf/opensrf.xml
407 cp /openils/conf/opensrf_core.xml.example /openils/conf/opensrf_core.xml
409 # fetch and install Dojo
411 wget -N "http://download.dojotoolkit.org/release-$DOJO_VERSION/dojo-release-$DOJO_VERSION.tar.gz" \
412 || wget -N "http://evergreen-ils.org/~phasefx/download.dojotoolkit.org/dojo-release-$DOJO_VERSION.tar.gz"
413 tar -zxf dojo-release-$DOJO_VERSION.tar.gz;
414 cp -r dojo-release-$DOJO_VERSION/* /openils/var/web/js/dojo/;
416 # give it all to opensrf
417 chown -R opensrf:opensrf /openils
419 # copy srfsh config into place
420 cp /openils/conf/srfsh.xml.example /home/opensrf/.srfsh.xml;
421 chown opensrf:opensrf /home/opensrf/.srfsh.xml;
422 echo End of Installing Evergreen =~-._
425 function configure_database {
426 echo _.-~= configure database
429 echo "Using password evergreen for the evergreen database user."
430 echo -e "evergreen\nevergreen\n" | su - postgres sh -c 'createuser -P -s evergreen;'
432 echo -e "\n\nPlease enter a password for the evergreen database user.\n If you do not want to edit configs, use \"evergreen\"\n"
433 su - postgres sh -c 'createuser -P -s evergreen;'
436 # Apply the DB schema
437 cd /home/opensrf/Evergreen
438 perl Open-ILS/src/support-scripts/eg_db_config \
442 --update-config $SAMPLEDATA \
445 --password evergreen \
446 --hostname localhost \
447 --database evergreen \
448 --admin-user $ADMIN_USER \
449 --admin-pass $ADMIN_PASS;
450 echo Return Value = $?
452 if [ $LIVETEST ]; then
455 wget http://api.pgxn.org/dist/pgtap/$PG_TAP_VER/pgtap-$PG_TAP_VER.zip \
456 && unzip pgtap-$PG_TAP_VER.zip \
457 && cd pgtap-$PG_TAP_VER \
461 su - postgres -c "$PG_CMD"
462 cd /var/lib/postgresql/pgtap \
464 echo 'CREATE EXTENSION pgtap;' | su - postgres -c "psql evergreen"
466 echo configure database =~-._
469 function configure_apache {
470 echo _.-~= configure apache
472 /etc/init.d/apache2 stop
473 # Copy apache configs into place and create SSL cert
474 cd /home/opensrf/Evergreen/
475 cp Open-ILS/examples/apache/eg.conf /etc/apache2/sites-available/
476 cp Open-ILS/examples/apache/eg_vhost.conf /etc/apache2/
477 cp Open-ILS/examples/apache/eg_startup /etc/apache2/
479 mkdir -p /etc/apache2/ssl;
480 if [ ! -f /etc/apache2/ssl/server.key ] ; then
481 echo -e "\n\nConfiguring a new temporary SSL certificate....\n";
483 yes "" | openssl req -new -x509 -days 365 -nodes -out /etc/apache2/ssl/server.crt -keyout /etc/apache2/ssl/server.key
485 openssl req -new -x509 -days 365 -nodes -out /etc/apache2/ssl/server.crt -keyout /etc/apache2/ssl/server.key
488 echo -e "\nkeeping existing ssl/server.key file\n";
492 echo Return Value = $?
494 echo Return Value = $?
496 echo Return Value = $?
497 a2dissite 000-default
498 echo Return Value = $?
500 echo Return Value = $?
502 echo Modifying APACHE_RUN_USER/APACHE_RUN_GROUP in /etc/apache2/envvars
503 sed -i 's/www-data/opensrf/g' /etc/apache2/envvars
505 echo Making sure /var/lock/apache2 is owned by opensrf
506 chown opensrf:opensrf /var/lock/apache2
508 echo Modifying KeepAliveTimeout in /etc/apache2/apache2.conf
509 sed -i 's/KeepAliveTimeout .*/KeepAliveTimeout 1/' /etc/apache2/apache2.conf
511 echo End of configure apache =~-._
514 function start_evergreen {
515 echo _.-~= Starting Evergreen
517 if [ $LIVETEST ]; then
518 rm /openils/var/log/*.log
522 export LD_LIBRARY_PATH=/openils/lib:/usr/local/lib:/usr/local/lib/dbd:$LD_LIBRARY_PATH \
523 && export PATH=/openils/bin:$PATH \
524 && OSRF_HOSTNAME="dns_hack" /openils/bin/osrf_control --localhost --restart-all && sleep 3 \
525 && /openils/bin/autogen.sh /openils/conf/opensrf_core.xml \
528 echo Starting services...
529 su - opensrf sh -c "$OSRF_COMMAND";
530 echo Return Value = $?
532 echo Restarting Apache
533 /etc/init.d/apache2 restart
534 echo Return Value = $?
536 echo End of Starting Evergreen =~-._
539 function test_evergreen_live {
540 # TODO: Eventually move these tests into a Make target within Evergreen
541 cd /home/opensrf/Evergreen
542 echo _.-~= Running pgTAP tests
544 su - postgres -c 'cd /home/opensrf/Evergreen ; pg_prove -vr -d evergreen Open-ILS/src/sql/Pg/t/ ; echo Return Value = $?'
545 echo End of pgTAP tests =~-._
546 echo _.-~= Running pgTAP live tests
548 su - postgres -c 'cd /home/opensrf/Evergreen ; pg_prove -vr -d evergreen Open-ILS/src/sql/Pg/live_t/ ; echo Return Value = $?'
549 echo End of pgTAP live tests =~-._
550 echo _.-~= Running settings-tester.pl
552 su - opensrf sh -c 'export PATH=/openils/bin:$PATH ; cd /home/opensrf/Evergreen/Open-ILS/src/support-scripts/ ; ./settings-tester.pl ; echo Return Value = $?'
553 echo End of settings-tester.pl output =~-._
554 echo _.-~= Running perl live tests
556 su - opensrf sh -c 'export PATH=/openils/bin:$PATH ; cd /home/opensrf/Evergreen/Open-ILS/src/perlmods/ ; make livecheck; echo Return Value = $?'
557 echo End of perl live tests =~-._
558 echo _.-~= Gathering log summary
562 su - opensrf sh -c 'cd /openils/var/log/ ; wc -l *.log'
565 su - opensrf sh -c 'cd /openils/var/log/ ; du -sh *.log'
567 echo 'perl -ne ''if (/^\[.*?\] (.*?) \[/) { print "$1\n"; }'' osrfsys.log | sort | uniq -c | sort -k2:'
568 (cd /openils/var/log/ ; perl -ne 'if (/^\[.*?\] (.*?) \[/) { print "$1\n"; }' osrfsys.log | sort | uniq -c | sort -k2)
570 echo End of log summary =~-._
573 echo _.-~= Log Output: $x
578 echo _.-~= Gathering system information
583 echo 'select version();' | su - postgres -c 'psql -At'
585 echo '/proc/meminfo:'
588 echo '/proc/cpuinfo:'
595 cpan -l 2> /dev/null | sort
596 echo End of system information =~-._