]> git.evergreen-ils.org Git - working/random.git/blob - installer/wheezy/eg_wheezy_installer.sh
Change into the correct pgtap directory
[working/random.git] / installer / wheezy / eg_wheezy_installer.sh
1 #!/bin/bash
2 # -----------------------------------------------------------------------
3 # Copyright (C) 2009-2012  Equinox Software Inc.
4 # Bill Erickson <berick@esilibrary.com>
5
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.
10
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 # -----------------------------------------------------------------------
16
17 while getopts ayst option
18 do
19         case "${option}"
20         in
21                 a) AUTOSTART=1;;
22                 y) YES=1;;
23                 s) SAMPLEDATA=--load-all-sample;;
24                 t) LIVETEST=1;;
25         esac
26 done
27
28 function my_init {
29     date
30     init_variables
31     configure_timezone
32     configure_cpan
33     build_essentials
34     setting_up_opensrf_env
35     cloning_git_repos
36     opensrf_prereqs
37     evergreen_prereqs
38     evergreen_db_prereqs
39     setting_ldconfig_and_rsyslog_and_hosts_and_ejabberd
40     build_opensrf
41     test_opensrf_build
42     install_opensrf
43     build_evergreen
44     test_evergreen_build
45     test_and_build_eg_browser_client
46     install_evergreen
47     configure_database
48     configure_apache
49     if [ $AUTOSTART ]; then
50         start_evergreen
51         if [ $LIVETEST ]; then
52             test_evergreen_live
53         fi
54     fi
55 }
56
57 function init_variables {
58     echo _.-~= initializing installer
59     date
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
66     export BASE_DIR=$PWD
67     echo AUTOSTART=${AUTOSTART}
68     echo YES=${YES}
69     echo SAMPLEDATA=${SAMPLEDATA}
70     echo LIVETEST=${LIVETEST}
71     echo DOJO_VERSION=${DOJO_VERSION}
72     echo PATH=${PATH}
73     echo LD_LIBRARY_PATH=${LD_LIBRARY_PATH}
74     echo BASE_DIR=${BASE_DIR}
75     # -----------------------------------------------------------------------
76     # Change to suit...
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}
101
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"
106
107     echo End of intializing installer =~-._
108 }
109
110 function configure_timezone {
111     echo _.-~= configure timezone
112     date
113     # should be America/New_York
114     perl -e 'print "2\n\n104\n";' | dpkg-reconfigure -fteletype tzdata
115     echo End of configure timezone =~-._
116 }
117
118 function configure_cpan {
119     echo _.-~= configure CPAN
120     date
121     # -----------------------------------------------------------------------
122     # force CPAN to load by installing something that should already be installed
123     if [ $YES ]; then
124         yes | cpan Fcntl
125     else
126         cpan Fcntl
127     fi
128     echo Return Value = $?
129     # CPAN follow pre-reqs?
130     if [ ! "$(echo 'o conf prerequisites_policy' | cpan | grep follow)" ]; then
131     if [ $YES ]; then
132
133         echo "setting cpan prerequisites_policy to follow"
134         echo -e "o conf prerequisites_policy follow\\n o conf commit" | cpan
135
136     else
137
138         echo '
139
140 -----------------------------------------------------------------------
141 The install will go faster if CPAN is configured to automatically install 
142 prerequisites.  You can revert the action later with:
143
144 echo -e "o conf prerequisites_policy ask\n o conf commit" | cpan 
145 '
146         while true; do
147             echo -n 'Automatically install prereqs? [Y/n] ';
148             read X;
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
152                 break;
153             fi;
154         done;
155     fi;
156     fi;
157     echo End of configure CPAN =~-._
158 }
159
160 function build_essentials {
161     echo _.-~= Installing some build essentials
162     date
163     # Install some essential tools
164     apt-get update \
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 = $?
168
169     if [ $LIVETEST ]; then
170         cpan TAP::Parser::SourceHandler::pgTAP
171         echo Return Value = $?
172     fi;
173     echo End of Installing some build essentials  =~-._
174 }
175
176 function setting_up_opensrf_env {
177     echo _.-~= creating opensrf user and environment
178     date
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
185     fi;
186     echo end of creating opensrf user and environment =~-._
187 }
188
189 function cloning_git_repos {
190     echo _.-~= cloning git repositories
191     date
192     OSRF_COMMAND="
193     cd /home/opensrf;
194     git clone --depth 0 --branch $OPENSRF_BRANCH $OPENSRF_REPO OpenSRF;
195     git clone --depth 0 --branch $EVERGREEN_BRANCH $EVERGREEN_REPO Evergreen;
196     "
197     rm -rf /home/opensrf/Evergreen /home/opensrf/OpenSRF
198     su - opensrf sh -c "$OSRF_COMMAND";
199     echo Return Value = $?
200
201     # Show tips
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`
206
207     echo End of cloning git repositories =~-._
208 }
209
210 function opensrf_prereqs {
211     echo _.-~= Installing OpenSRF pre-requisites
212     date
213     # Install pre-reqs
214     mkdir -p /usr/src/evergreen; 
215     cd /usr/src/evergreen;
216     if [ $YES ]; then
217         yes | make -f /home/opensrf/OpenSRF/src/extras/Makefile.install ${OPENSRF_PREREQ_TARGET}
218     else
219         make -f /home/opensrf/OpenSRF/src/extras/Makefile.install ${OPENSRF_PREREQ_TARGET}
220     fi;
221     echo Return Value = $?
222     echo End of Installing OpenSRF pre-requisites =~-._
223 }
224
225 function evergreen_prereqs {
226     echo _.-~= Installing Evergreen pre-requisites
227     date
228     if [ $YES ]; then
229         yes | make -f /home/opensrf/Evergreen/Open-ILS/src/extras/Makefile.install ${EVERGREEN_PREREQ_TARGET}
230     else
231         make -f /home/opensrf/Evergreen/Open-ILS/src/extras/Makefile.install ${EVERGREEN_PREREQ_TARGET}
232     fi;
233     echo Return Value = $?
234     echo End of Installing Evergreen pre-requisites =~-._
235 }
236
237 function evergreen_db_prereqs {
238     echo _.-~= Installing Evergreen database pre-requisites
239     date
240     if [ $YES ]; then
241         yes | make -f /home/opensrf/Evergreen/Open-ILS/src/extras/Makefile.install ${EVERGREEN_DB_PREREQ_TARGET}
242     else
243         make -f /home/opensrf/Evergreen/Open-ILS/src/extras/Makefile.install ${EVERGREEN_DB_PREREQ_TARGET}
244     fi;
245     echo Return Value = $?
246     echo End of Installing Evergreen database pre-requisites =~-._
247 }
248
249 function setting_ldconfig_and_rsyslog_and_hosts_and_ejabberd {
250     echo _.-~= setting ld.so.conf and rsyslog and /etc/hosts and ejabberd
251     date
252     cp $BASE_DIR/evergreen.ld.conf /etc/ld.so.conf.d/
253     ldconfig;
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
260
261         if [ $YES ]; 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
265         else
266
267         cat <<EOF
268
269     * Add these lines to /etc/hosts.
270
271     127.0.1.2   public.localhost    public
272     127.0.1.3   private.localhost   private
273
274 EOF
275         fi;
276
277     else
278         echo "INFO: /etc/hosts already has public.localhost line";
279     fi
280     echo Return Value = $?
281     # Patch Ejabberd and register users
282     if [ ! "$(grep 'public.localhost' /etc/ejabberd/ejabberd.cfg)" ]; then
283         cd /etc/ejabberd/
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
290         date
291         /etc/init.d/ejabberd start
292         echo Return Value = $?
293         sleep 10;
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 = $?
302     fi;
303     echo End of setting ld.so.conf and rsyslog and /etc/hosts and ejabberd =~-._
304 }
305
306 function build_opensrf {
307     # Build and install OpenSRF
308     echo _.-~= Building OpenSRF
309     date
310     OSRF_COMMAND='
311     cd /home/opensrf/OpenSRF;
312     autoreconf -i;
313     ./configure --prefix=/openils --sysconfdir=/openils/conf;
314     make;'
315     su - opensrf sh -c "$OSRF_COMMAND"
316     echo Return Value = $?
317     echo End of Building OpenSRF =~-._
318 }
319
320 function test_opensrf_build {
321     echo _.-~= Running OpenSRF build tests
322     date
323     cd /home/opensrf/OpenSRF;
324     make check
325     echo Return Value = $?
326     echo End of OpenSRF build tests =~-._
327 }
328
329 function install_opensrf {
330     echo _.-~= Installing OpenSRF
331     date
332     make install
333     echo Return Value = $?
334     echo End of Installing OpenSRF =~-._
335 }
336
337 function build_evergreen {
338     echo _.-~= Building Evergreen
339     date
340     OSRF_COMMAND='
341     export PATH=/openils/bin:$PATH
342     cd /home/opensrf/Evergreen;
343     autoreconf -i;
344     ./configure --prefix=/openils --sysconfdir=/openils/conf;
345     make;
346     '
347     su - opensrf sh -c "$OSRF_COMMAND"
348     echo Return Value = $?
349     echo End of Building Evergreen =~-._
350 }
351
352 function test_evergreen_build {
353     echo _.-~= Running Evergreen build tests
354     date
355     cd /home/opensrf/Evergreen
356     make check
357     echo Return Value = $?
358     echo End of Evergreen build tests =~-._
359 }
360
361
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
367     cd /tmp
368     git clone $NODEJS_REPO
369     cd node
370     git checkout -b $NODEJS_VERSION $NODEJS_VERSION
371     ./configure && make -j2 && make install
372     echo Return Value = $?
373     npm update
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 = $?
382
383     # fetch JS/CSS/etc prereqs
384     if [ $YES ]; then
385         # yes == allow sending package stats
386         yes | bower --allow-root install  
387     else
388         bower --allow-root install
389     fi
390     echo Return Value = $?
391
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 =~-._
397 }
398
399 function install_evergreen {
400     echo _.-~= Installing Evergreen
401     date
402     cd /home/opensrf/Evergreen
403     make install
404     echo Return Value = $?
405
406     cp /openils/conf/opensrf.xml.example      /openils/conf/opensrf.xml
407     cp /openils/conf/opensrf_core.xml.example /openils/conf/opensrf_core.xml
408
409     # fetch and install Dojo
410     cd /tmp;
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/;
415
416     # give it all to opensrf
417     chown -R opensrf:opensrf /openils
418
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 =~-._
423 }
424
425 function configure_database {
426     echo _.-~= configure database
427     date
428     if [ $YES ]; then
429         echo "Using password evergreen for the evergreen database user."
430         echo -e "evergreen\nevergreen\n" | su - postgres sh -c 'createuser -P -s evergreen;'
431     else
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;'
434     fi;
435
436     # Apply the DB schema
437     cd /home/opensrf/Evergreen
438     perl Open-ILS/src/support-scripts/eg_db_config \
439         --create-database       \
440         --create-schema         \
441         --create-offline        \
442         --update-config $SAMPLEDATA \
443         --service all           \
444         --user evergreen        \
445         --password evergreen    \
446         --hostname localhost    \
447         --database evergreen    \
448         --admin-user $ADMIN_USER \
449         --admin-pass $ADMIN_PASS;
450     echo Return Value = $?
451
452     if [ $LIVETEST ]; then
453         PG_TAP_VER="0.97.0"
454         PG_CMD="
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 \
458         && make \
459         && make installcheck
460         "
461         su - postgres -c "$PG_CMD"
462         cd /var/lib/postgresql/pgtap \
463         && make install;
464         echo 'CREATE EXTENSION pgtap;' | su - postgres -c "psql evergreen"
465     fi;
466     echo configure database =~-._
467 }
468
469 function configure_apache {
470     echo _.-~= configure apache
471     date
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/
478
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";
482         if [ $YES ]; then
483            yes "" | openssl req -new -x509 -days 365 -nodes -out /etc/apache2/ssl/server.crt -keyout /etc/apache2/ssl/server.key
484         else
485            openssl req -new -x509 -days 365 -nodes -out /etc/apache2/ssl/server.crt -keyout /etc/apache2/ssl/server.key
486         fi;
487     else
488         echo -e "\nkeeping existing ssl/server.key file\n";
489     fi
490
491     a2enmod ssl  
492     echo Return Value = $?
493     a2enmod rewrite
494     echo Return Value = $?
495     a2enmod expires 
496     echo Return Value = $?
497     a2dissite 000-default
498     echo Return Value = $?
499     a2ensite eg.conf
500     echo Return Value = $?
501
502     echo Modifying APACHE_RUN_USER/APACHE_RUN_GROUP in /etc/apache2/envvars
503     sed -i 's/www-data/opensrf/g' /etc/apache2/envvars
504
505     echo Making sure /var/lock/apache2 is owned by opensrf
506     chown opensrf:opensrf /var/lock/apache2
507
508     echo Modifying KeepAliveTimeout in /etc/apache2/apache2.conf
509     sed -i 's/KeepAliveTimeout .*/KeepAliveTimeout 1/' /etc/apache2/apache2.conf
510
511     echo End of configure apache =~-._
512 }
513
514 function start_evergreen {
515     echo _.-~= Starting Evergreen
516     date
517     if [ $LIVETEST ]; then
518         rm /openils/var/log/*.log
519     fi
520
521     OSRF_COMMAND='
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 \
526     && echo Finis;
527     '
528     echo Starting services...
529     su - opensrf sh -c "$OSRF_COMMAND";
530     echo Return Value = $?
531
532     echo Restarting Apache
533     /etc/init.d/apache2 restart
534     echo Return Value = $?
535
536     echo End of Starting Evergreen =~-._
537 }
538
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
543     date
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
547     date
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
551     date
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
555     date
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
559     date
560     echo ''
561     echo 'wc -l *.log:'
562     su - opensrf sh -c 'cd /openils/var/log/ ; wc -l *.log'
563     echo ''
564     echo 'du -sh *.log:'
565     su - opensrf sh -c 'cd /openils/var/log/ ; du -sh *.log'
566     echo ''
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)
569     echo ''
570     echo End of log summary =~-._
571     cd /openils/var/log/
572     for x in *.log; do
573         echo _.-~= Log Output: $x
574         date
575         cat $x
576         echo End of $x =~-._
577     done
578     echo _.-~= Gathering system information
579     echo ''
580     date
581     echo ''
582     uname -a
583     echo 'select version();' | su - postgres -c 'psql -At'
584     echo ''
585     echo '/proc/meminfo:'
586     cat /proc/meminfo
587     echo ''
588     echo '/proc/cpuinfo:'
589     cat /proc/cpuinfo
590     echo ''
591     echo 'dpkg --list:'
592     dpkg --list
593     echo ''
594     echo 'cpan -l:'
595     cpan -l 2> /dev/null | sort
596     echo End of system information =~-._
597     date
598 }
599
600 my_init
601
602