]> git.evergreen-ils.org Git - working/random.git/blob - installer/wheezy/eg_wheezy_installer.sh
point to collab/phasefx/lp1350042-grid-print-and-show-all-cols for this round
[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         test_evergreen_live
52     fi
53 }
54
55 function init_variables {
56     echo _.-~= initializing installer
57     date
58     # -----------------------------------------------------------------------
59     # Handling passed arguments to the script
60     # -----------------------------------------------------------------------
61     export DOJO_VERSION='1.3.3';
62     export PATH=/openils/bin:$PATH
63     export LD_LIBRARY_PATH=/openils/lib:/usr/local/lib:/usr/local/lib/dbd:$LD_LIBRARY_PATH
64     export BASE_DIR=$PWD
65     echo AUTOSTART=${AUTOSTART}
66     echo YES=${YES}
67     echo SAMPLEDATA=${SAMPLEDATA}
68     echo LIVETEST=${LIVETEST}
69     echo DOJO_VERSION=${DOJO_VERSION}
70     echo PATH=${PATH}
71     echo LD_LIBRARY_PATH=${LD_LIBRARY_PATH}
72     echo BASE_DIR=${BASE_DIR}
73     # -----------------------------------------------------------------------
74     # Change to suit...
75     # -----------------------------------------------------------------------
76     # If you change the jabber password, you will need to 
77     # edit opensrf_core.xml and srfsh.xml accordingly
78     export JABBER_PASSWORD='password'
79     export ADMIN_USER='admin';
80     export ADMIN_PASS='demo123';
81     # -----------------------------------------------------------------------
82     # You can override these like so:
83     #       EVERGREEN_BRANCH='master' ./eg_wheezy_installer.sh
84     # -----------------------------------------------------------------------
85     OPENSRF_REPO='git://git.evergreen-ils.org/OpenSRF.git'
86     OPENSRF_BRANCH='master'
87     EVERGREEN_REPO='git://git.evergreen-ils.org/working/Evergreen.git'
88     EVERGREEN_BRANCH='collab/phasefx/lp1350042-grid-print-and-show-all-cols'
89     echo OPENSRF_REPO=${OPENSRF_REPO}
90     echo OPENSRF_BRANCH=${OPENSRF_BRANCH}
91     echo EVERGREEN_REPO=${EVERGREEN_REPO}
92     echo EVERGREEN_BRANCH=${EVERGREEN_BRANCH}
93     OPENSRF_PREREQ_TARGET=debian-wheezy
94     EVERGREEN_PREREQ_TARGET=debian-wheezy
95     EVERGREEN_DB_PREREQ_TARGET=postgres-server-debian-wheezy
96     echo OPENSRF_PREREQ_TARGET=${OPENSRF_PREREQ_TARGET}
97     echo EVERGREEN_PREREQ_TARGET=${EVERGREEN_PREREQ_TARGET}
98     echo EVERGREEN_DB_PREREQ_TARGET=${EVERGREEN_DB_PREREQ_TARGET}
99
100     export NODEJS_REPO='https://github.com/joyent/node.git'
101     export NODEJS_VERSION='v0.10.31'
102     echo "NODEJS_REPO=$NODEJS_REPO"
103     echo "NODEJS_VERSION=$NODEJS_VERSION"
104
105     echo End of intializing installer =~-._
106 }
107
108 function configure_timezone {
109     echo _.-~= configure timezone
110     date
111     # should be America/New_York
112     perl -e 'print "2\n\n104\n";' | dpkg-reconfigure -fteletype tzdata
113     echo End of configure timezone =~-._
114 }
115
116 function configure_cpan {
117     echo _.-~= configure CPAN
118     date
119     # -----------------------------------------------------------------------
120     # force CPAN to load by installing something that should already be installed
121     if [ $YES ]; then
122         yes | cpan Fcntl
123     else
124         cpan Fcntl
125     fi
126     echo Return Value = $?
127     # CPAN follow pre-reqs?
128     if [ ! "$(echo 'o conf prerequisites_policy' | cpan | grep follow)" ]; then
129     if [ $YES ]; then
130
131         echo "setting cpan prerequisites_policy to follow"
132         echo -e "o conf prerequisites_policy follow\\n o conf commit" | cpan
133
134     else
135
136         echo '
137
138 -----------------------------------------------------------------------
139 The install will go faster if CPAN is configured to automatically install 
140 prerequisites.  You can revert the action later with:
141
142 echo -e "o conf prerequisites_policy ask\n o conf commit" | cpan 
143 '
144         while true; do
145             echo -n 'Automatically install prereqs? [Y/n] ';
146             read X;
147             [ "$X" == 'n' -o "$X" == "N" ] && break;
148             if [ "$X" == 'y' -o "$X" == 'Y' ]; then
149                 echo -e "o conf prerequisites_policy follow\\n o conf commit" | cpan
150                 break;
151             fi;
152         done;
153     fi;
154     fi;
155     echo End of configure CPAN =~-._
156 }
157
158 function build_essentials {
159     echo _.-~= Installing some build essentials
160     date
161     # Install some essential tools
162     apt-get update \
163     && apt-get -yq dist-upgrade \
164     && apt-get -yq install build-essential automake git psmisc ntp rsyslog;
165     echo Return Value = $?
166
167     if [ $LIVETEST ]; then
168         cpan TAP::Parser::SourceHandler::pgTAP
169         echo Return Value = $?
170     fi;
171     echo End of Installing some build essentials  =~-._
172 }
173
174 function setting_up_opensrf_env {
175     echo _.-~= creating opensrf user and environment
176     date
177     # Create opensrf user and set up environment
178     if [ ! "$(grep ^opensrf: /etc/passwd)" ]; then
179         useradd -m -s /bin/bash opensrf
180         echo Return Value = $?
181         echo 'export PATH=/openils/bin:$PATH' >> /home/opensrf/.bashrc
182         echo 'export LD_LIBRARY_PATH=/openils/lib:/usr/local/lib:/usr/local/lib/dbd:$LD_LIBRARY_PATH' >> /home/opensrf/.bashrc
183     fi;
184     echo end of creating opensrf user and environment =~-._
185 }
186
187 function cloning_git_repos {
188     echo _.-~= cloning git repositories
189     date
190     OSRF_COMMAND="
191     cd /home/opensrf;
192     git clone --depth 0 --branch $OPENSRF_BRANCH $OPENSRF_REPO OpenSRF;
193     git clone --depth 0 --branch $EVERGREEN_BRANCH $EVERGREEN_REPO Evergreen;
194     "
195     rm -rf /home/opensrf/Evergreen /home/opensrf/OpenSRF
196     su - opensrf sh -c "$OSRF_COMMAND";
197     echo Return Value = $?
198
199     # Show tips
200     cd /home/opensrf/OpenSRF/
201     echo 'Tip of OpenSRF:' `git log --format=oneline | head -1`
202     cd /home/opensrf/Evergreen/
203     echo 'Tip of Evergreen:' `git log --format=oneline | head -1`
204
205     echo End of cloning git repositories =~-._
206 }
207
208 function opensrf_prereqs {
209     echo _.-~= Installing OpenSRF pre-requisites
210     date
211     # Install pre-reqs
212     mkdir -p /usr/src/evergreen; 
213     cd /usr/src/evergreen;
214     if [ $YES ]; then
215         yes | make -f /home/opensrf/OpenSRF/src/extras/Makefile.install ${OPENSRF_PREREQ_TARGET}
216     else
217         make -f /home/opensrf/OpenSRF/src/extras/Makefile.install ${OPENSRF_PREREQ_TARGET}
218     fi;
219     echo Return Value = $?
220     echo End of Installing OpenSRF pre-requisites =~-._
221 }
222
223 function evergreen_prereqs {
224     echo _.-~= Installing Evergreen pre-requisites
225     date
226     if [ $YES ]; then
227         yes | make -f /home/opensrf/Evergreen/Open-ILS/src/extras/Makefile.install ${EVERGREEN_PREREQ_TARGET}
228     else
229         make -f /home/opensrf/Evergreen/Open-ILS/src/extras/Makefile.install ${EVERGREEN_PREREQ_TARGET}
230     fi;
231     echo Return Value = $?
232     echo End of Installing Evergreen pre-requisites =~-._
233 }
234
235 function evergreen_db_prereqs {
236     echo _.-~= Installing Evergreen database pre-requisites
237     date
238     if [ $YES ]; then
239         yes | make -f /home/opensrf/Evergreen/Open-ILS/src/extras/Makefile.install ${EVERGREEN_DB_PREREQ_TARGET}
240     else
241         make -f /home/opensrf/Evergreen/Open-ILS/src/extras/Makefile.install ${EVERGREEN_DB_PREREQ_TARGET}
242     fi;
243     echo Return Value = $?
244     echo End of Installing Evergreen database pre-requisites =~-._
245 }
246
247 function setting_ldconfig_and_rsyslog_and_hosts_and_ejabberd {
248     echo _.-~= setting ld.so.conf and rsyslog and /etc/hosts and ejabberd
249     date
250     cp $BASE_DIR/evergreen.ld.conf /etc/ld.so.conf.d/
251     ldconfig;
252     echo Return Value = $?
253     # Configure rsyslog and restart
254     cp /home/opensrf/Evergreen/Open-ILS/examples/evergreen-rsyslog.conf /etc/rsyslog.d/evergreen.conf
255     /etc/init.d/rsyslog restart
256     echo Return Value = $?
257     if [ ! "$(grep 'public.localhost' /etc/hosts)" ]; then
258
259         if [ $YES ]; then
260             echo 'Adding public.localhost and private.localhost to /etc/hosts'
261             echo '127.0.1.2    public.localhost     public' >> /etc/hosts
262             echo '127.0.1.3    private.localhost    private' >> /etc/hosts
263         else
264
265         cat <<EOF
266
267     * Add these lines to /etc/hosts.
268
269     127.0.1.2   public.localhost    public
270     127.0.1.3   private.localhost   private
271
272 EOF
273         fi;
274
275     else
276         echo "INFO: /etc/hosts already has public.localhost line";
277     fi
278     echo Return Value = $?
279     # Patch Ejabberd and register users
280     if [ ! "$(grep 'public.localhost' /etc/ejabberd/ejabberd.cfg)" ]; then
281         cd /etc/ejabberd/
282         /etc/init.d/ejabberd stop;
283         killall beam epmd; # just in case
284         cp ejabberd.cfg /root/ejabberd.cfg.orig
285         patch -p0 < $BASE_DIR/ejabberd.EG.patch
286         chown ejabberd:ejabberd ejabberd.cfg
287         echo starting ejabberd after patching
288         date
289         /etc/init.d/ejabberd start
290         echo Return Value = $?
291         sleep 10;
292         ejabberdctl register router  private.localhost $JABBER_PASSWORD
293         echo Return Value = $?
294         ejabberdctl register opensrf private.localhost $JABBER_PASSWORD
295         echo Return Value = $?
296         ejabberdctl register router  public.localhost  $JABBER_PASSWORD
297         echo Return Value = $?
298         ejabberdctl register opensrf public.localhost  $JABBER_PASSWORD
299         echo Return Value = $?
300     fi;
301     echo End of setting ld.so.conf and rsyslog and /etc/hosts and ejabberd =~-._
302 }
303
304 function build_opensrf {
305     # Build and install OpenSRF
306     echo _.-~= Building OpenSRF
307     date
308     OSRF_COMMAND='
309     cd /home/opensrf/OpenSRF;
310     autoreconf -i;
311     ./configure --prefix=/openils --sysconfdir=/openils/conf;
312     make;'
313     su - opensrf sh -c "$OSRF_COMMAND"
314     echo Return Value = $?
315     echo End of Building OpenSRF =~-._
316 }
317
318 function test_opensrf_build {
319     echo _.-~= Running OpenSRF build tests
320     date
321     cd /home/opensrf/OpenSRF;
322     make check
323     echo Return Value = $?
324     echo End of OpenSRF build tests =~-._
325 }
326
327 function install_opensrf {
328     echo _.-~= Installing OpenSRF
329     date
330     make install
331     echo Return Value = $?
332     echo End of Installing OpenSRF =~-._
333 }
334
335 function build_evergreen {
336     echo _.-~= Building Evergreen
337     date
338     OSRF_COMMAND='
339     export PATH=/openils/bin:$PATH
340     cd /home/opensrf/Evergreen;
341     autoreconf -i;
342     ./configure --prefix=/openils --sysconfdir=/openils/conf;
343     make;
344     '
345     su - opensrf sh -c "$OSRF_COMMAND"
346     echo Return Value = $?
347     echo End of Building Evergreen =~-._
348 }
349
350 function test_evergreen_build {
351     echo _.-~= Running Evergreen build tests
352     date
353     cd /home/opensrf/Evergreen
354     make check
355     echo Return Value = $?
356     echo End of Evergreen build tests =~-._
357 }
358
359
360 # The evergreen browser client prereq installation and 
361 # build process is not baked into Evergreen proper (yet).  
362 # Run it as a standalone operation for now.
363 function test_and_build_eg_browser_client {
364     echo _.-~= Running Evergreen browser client build/test
365     cd /tmp
366     git clone $NODEJS_REPO
367     cd node
368     git checkout -b $NODEJS_VERSION $NODEJS_VERSION
369     ./configure && make -j2 && make install
370     echo Return Value = $?
371     npm update
372     echo Return Value = $?
373     npm install -g grunt-cli    # install grunt
374     echo Return Value = $?
375     npm install -g bower        # install bower
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
381     # fetch JS/CSS/etc prereqs
382     if [ $YES ]; then
383         # yes == allow sending package stats
384         yes | bower --allow-root install  
385     else
386         bower --allow-root install
387     fi
388     echo Return Value = $?
389
390     grunt build                 # concatentate, minify, copy into place
391     echo Return Value = $?
392     grunt test                  # run JS unit tests
393     echo Return Value = $?
394     echo End of Evergreen browser client build/test =~-._
395 }
396
397 function install_evergreen {
398     echo _.-~= Installing Evergreen
399     date
400     cd /home/opensrf/Evergreen
401     make install
402     echo Return Value = $?
403
404     cp /openils/conf/opensrf.xml.example      /openils/conf/opensrf.xml
405     cp /openils/conf/opensrf_core.xml.example /openils/conf/opensrf_core.xml
406
407     # fetch and install Dojo
408     cd /tmp;
409     wget -N "http://download.dojotoolkit.org/release-$DOJO_VERSION/dojo-release-$DOJO_VERSION.tar.gz" \
410     || wget -N "http://evergreen-ils.org/~phasefx/download.dojotoolkit.org/dojo-release-$DOJO_VERSION.tar.gz"
411     tar -zxf dojo-release-$DOJO_VERSION.tar.gz;
412     cp -r dojo-release-$DOJO_VERSION/* /openils/var/web/js/dojo/;
413
414     # give it all to opensrf
415     chown -R opensrf:opensrf /openils
416
417     # copy srfsh config into place
418     cp /openils/conf/srfsh.xml.example /home/opensrf/.srfsh.xml;
419     chown opensrf:opensrf /home/opensrf/.srfsh.xml;
420     echo End of Installing Evergreen =~-._
421 }
422
423 function configure_database {
424     echo _.-~= configure database
425     date
426     if [ $YES ]; then
427         echo "Using password evergreen for the evergreen database user."
428         echo -e "evergreen\nevergreen\n" | su - postgres sh -c 'createuser -P -s evergreen;'
429     else
430         echo -e "\n\nPlease enter a password for the evergreen database user.\n  If you do not want to edit configs, use \"evergreen\"\n"
431         su - postgres sh -c 'createuser -P -s evergreen;'
432     fi;
433
434     # Apply the DB schema
435     cd /home/opensrf/Evergreen
436     perl Open-ILS/src/support-scripts/eg_db_config \
437         --create-database       \
438         --create-schema         \
439         --create-offline        \
440         --update-config $SAMPLEDATA \
441         --service all           \
442         --user evergreen        \
443         --password evergreen    \
444         --hostname localhost    \
445         --database evergreen    \
446         --admin-user $ADMIN_USER \
447         --admin-pass $ADMIN_PASS;
448     echo Return Value = $?
449
450     if [ $LIVETEST ]; then
451         PG_CMD="
452         git clone --depth 0 https://github.com/theory/pgtap.git \
453         && cd pgtap \
454         && make \
455         && make installcheck
456         "
457         su - postgres -c "$PG_CMD"
458         cd /var/lib/postgresql/pgtap \
459         && make install;
460         echo 'CREATE EXTENSION pgtap;' | su - postgres -c "psql evergreen"
461     fi;
462     echo configure database =~-._
463 }
464
465 function configure_apache {
466     echo _.-~= configure apache
467     date
468     /etc/init.d/apache2 stop
469     # Copy apache configs into place and create SSL cert
470     cd /home/opensrf/Evergreen/
471     cp Open-ILS/examples/apache/eg.conf       /etc/apache2/sites-available/
472     cp Open-ILS/examples/apache/eg_vhost.conf /etc/apache2/
473     cp Open-ILS/examples/apache/eg_startup    /etc/apache2/
474
475     mkdir -p /etc/apache2/ssl;
476     if [ ! -f /etc/apache2/ssl/server.key ] ; then
477         echo -e "\n\nConfiguring a new temporary SSL certificate....\n";
478         if [ $YES ]; then
479            yes "" | openssl req -new -x509 -days 365 -nodes -out /etc/apache2/ssl/server.crt -keyout /etc/apache2/ssl/server.key
480         else
481            openssl req -new -x509 -days 365 -nodes -out /etc/apache2/ssl/server.crt -keyout /etc/apache2/ssl/server.key
482         fi;
483     else
484         echo -e "\nkeeping existing ssl/server.key file\n";
485     fi
486
487     a2enmod ssl  
488     echo Return Value = $?
489     a2enmod rewrite
490     echo Return Value = $?
491     a2enmod expires 
492     echo Return Value = $?
493     a2dissite 000-default
494     echo Return Value = $?
495     a2ensite eg.conf
496     echo Return Value = $?
497
498     echo Modifying APACHE_RUN_USER/APACHE_RUN_GROUP in /etc/apache2/envvars
499     sed -i 's/www-data/opensrf/g' /etc/apache2/envvars
500
501     echo Making sure /var/lock/apache2 is owned by opensrf
502     chown opensrf:opensrf /var/lock/apache2
503
504     echo Modifying KeepAliveTimeout in /etc/apache2/apache2.conf
505     sed -i 's/KeepAliveTimeout .*/KeepAliveTimeout 1/' /etc/apache2/apache2.conf
506
507     echo End of configure apache =~-._
508 }
509
510 function start_evergreen {
511     echo _.-~= Starting Evergreen
512     date
513     if [ $LIVETEST ]; then
514         rm /openils/var/log/*.log
515     fi
516
517     OSRF_COMMAND='
518     export LD_LIBRARY_PATH=/openils/lib:/usr/local/lib:/usr/local/lib/dbd:$LD_LIBRARY_PATH \
519     && export PATH=/openils/bin:$PATH \
520     && OSRF_HOSTNAME="dns_hack" /openils/bin/osrf_control --localhost --restart-all  && sleep 3 \
521     && /openils/bin/autogen.sh /openils/conf/opensrf_core.xml \
522     && echo Finis;
523     '
524     echo Starting services...
525     su - opensrf sh -c "$OSRF_COMMAND";
526     echo Return Value = $?
527
528     echo Restarting Apache
529     /etc/init.d/apache2 restart
530     echo Return Value = $?
531
532     echo End of Starting Evergreen =~-._
533 }
534
535 function test_evergreen_live {
536     # TODO: Eventually move these tests into a Make target within Evergreen
537     cd /home/opensrf/Evergreen
538     echo _.-~= Running pgTAP tests
539     date
540     su - postgres -c 'cd /home/opensrf/Evergreen ; pg_prove -vr -d evergreen Open-ILS/src/sql/Pg/t/ ; echo Return Value = $?'
541     echo End of pgTAP tests =~-._
542     echo _.-~= Running pgTAP live tests
543     date
544     su - postgres -c 'cd /home/opensrf/Evergreen ; pg_prove -vr -d evergreen Open-ILS/src/sql/Pg/live_t/ ; echo Return Value = $?'
545     echo End of pgTAP live tests =~-._
546     echo _.-~= Running settings-tester.pl
547     date
548     su - opensrf sh -c 'export PATH=/openils/bin:$PATH ; cd /home/opensrf/Evergreen/Open-ILS/src/support-scripts/ ; ./settings-tester.pl ; echo Return Value = $?'
549     echo End of settings-tester.pl output =~-._
550     echo _.-~= Running perl live tests
551     date
552     su - opensrf sh -c 'export PATH=/openils/bin:$PATH ; cd /home/opensrf/Evergreen/Open-ILS/src/perlmods/ ; make livecheck; echo Return Value = $?'
553     echo End of perl live tests =~-._
554     echo _.-~= Gathering log summary
555     date
556     echo ''
557     echo 'wc -l *.log:'
558     su - opensrf sh -c 'cd /openils/var/log/ ; wc -l *.log'
559     echo ''
560     echo 'du -sh *.log:'
561     su - opensrf sh -c 'cd /openils/var/log/ ; du -sh *.log'
562     echo ''
563     echo 'perl -ne ''if (/^\[.*?\] (.*?) \[/) { print "$1\n"; }'' osrfsys.log | sort | uniq -c | sort -k2:'
564     (cd /openils/var/log/ ; perl -ne 'if (/^\[.*?\] (.*?) \[/) { print "$1\n"; }' osrfsys.log | sort | uniq -c | sort -k2)
565     echo ''
566     echo End of log summary =~-._
567     cd /openils/var/log/
568     for x in *.log; do
569         echo _.-~= Log Output: $x
570         date
571         cat $x
572         echo End of $x =~-._
573     done
574     echo _.-~= Gathering system information
575     echo ''
576     date
577     echo ''
578     uname -a
579     echo 'select version();' | su - postgres -c 'psql -At'
580     echo ''
581     echo '/proc/meminfo:'
582     cat /proc/meminfo
583     echo ''
584     echo '/proc/cpuinfo:'
585     cat /proc/cpuinfo
586     echo ''
587     echo 'dpkg --list:'
588     dpkg --list
589     echo ''
590     echo 'cpan -l:'
591     cpan -l 2> /dev/null | sort
592     echo End of system information =~-._
593     date
594 }
595
596 my_init
597
598